data

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package data provides functions to manage persistent data storage. For the time being, storage is file-based on the local filesystem. Future implementations may include remote key-value stores and databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReviewerToPR added in v0.6.0

func AddReviewerToPR(url, email string) error

AddReviewerToPR adds a new reviewer to the attention list of a specific PR. This function is idempotent: if a reviewer already exists, or is the PR author, it does nothing. It also ignores empty or "bot" email addresses.

func DeleteBitbucketPR added in v0.2.0

func DeleteBitbucketPR(url string) error

DeleteBitbucketPR deletes the snapshot of a Bitbucket pull request when it becomes obsolete (i.e. when the PR is merged, closed, or marked as a draft). This function is idempotent: it does not return an error if the snapshot does not exist.

func DeleteReminder added in v0.5.0

func DeleteReminder(userID string) error

func DeleteSlackBotIDs added in v0.4.0

func DeleteSlackBotIDs(botID string) error

func DeleteTurn added in v0.6.0

func DeleteTurn(url string) error

DeleteTurn removes the attention state file of a specific PR. This is used when the PR is closed or marked as a draft.

func DeleteURLAndIDMapping added in v0.2.0

func DeleteURLAndIDMapping(key string) error

DeleteURLAndIDMapping deletes the 2-way mapping between PR URLs and chat channel and thread IDs when they become obsolete (i.e. when the PR is merged, closed, or marked as a draft).

func GetCurrentTurn added in v0.6.0

func GetCurrentTurn(url string) ([]string, error)

GetCurrentTurn returns the email addresses of all the users whose turn it is to pay attention to a specific PR. If the PR has no assigned reviewers, this function returns the PR author (as a reminder for them to assign reviewers). If any assigned reviewer has their turn flag set to false, we add the author to the list as well, unless the attention list was set explicitly using SetTurn.

func GetSlackBotUserID added in v0.4.0

func GetSlackBotUserID(botID string) (string, error)

func InitTurn added in v0.6.0

func InitTurn(url, author string, reviewers []string) error

InitTurn initializes the attention state of a new PR. Users are specified using their email addresses.

func IsOptedIn

func IsOptedIn(email string) (bool, error)

func ListReminders added in v0.5.0

func ListReminders() (map[string]string, error)

func LoadBitbucketPR added in v0.2.0

func LoadBitbucketPR(url string) (map[string]any, error)

LoadBitbucketPR loads a snapshot of a Bitbucket pull request. This is used to detect changes in the pull request over time. This function returns nil if no snapshot is found.

func LogSlackChannelArchived added in v0.6.0

func LogSlackChannelArchived(channelID, url string) error

func LogSlackChannelCreated added in v0.6.0

func LogSlackChannelCreated(channelID, name, url string) error

func LogSlackChannelDeleted added in v0.6.0

func LogSlackChannelDeleted(channelID string) error

func LogSlackChannelRenamed added in v0.6.0

func LogSlackChannelRenamed(channelID, name string) error

func MapURLAndID added in v0.2.0

func MapURLAndID(url, id string) error

MapURLAndID saves a 2-way mapping between a PR URL and its dedicated chat channel or thread IDs.

func OptInBitbucketUser

func OptInBitbucketUser(slackUserID, accountID, email, linkID string) error

func OptInGitHubUser

func OptInGitHubUser(slackUserID, username, email, linkID string) error

func OptOut

func OptOut(email string) error

func RemoveFromTurn added in v0.6.0

func RemoveFromTurn(url, email string) error

RemoveFromTurn completely removes a reviewer from the attention list of a specific PR. This is used when that reviewer approves the PR, or is unassigned from the PR. This function is idempotent: if the reviewer does not exist, it does nothing. It also ignores empty or "bot" email addresses.

func SetReminder added in v0.5.0

func SetReminder(userID, kitchenTime, tz string) error

func SetSlackBotUserID added in v0.4.0

func SetSlackBotUserID(botID, userID string) error

func SetTurn added in v0.6.0

func SetTurn(url string, emails []string) error

SetTurn overwrites the attention state of a specific PR to an explicit set of users. Missing users are added, which means the caller needs to ensure they *are* valid reviewers. Existing unmentioned users are not removed, but are marked as not their turn. If the input contains the PR author, they *are* added (temporarily, until SwitchTurn is called for them). It also ignores empty or "bot" email addresses.

func StoreBitbucketPR added in v0.2.0

func StoreBitbucketPR(url string, pr any) error

StoreBitbucketPR saves a snapshot of a Bitbucket pull request. This is used to detect changes in the pull request over time.

func SwitchTurn added in v0.6.0

func SwitchTurn(url, email string) error

SwitchTurn switches the turn of a specific user in a specific PR. If the user is the PR author, it adds all reviewers to the attention list. If the user is a reviewer, it adds the author to the attention list. If the user is not found, this function does nothing.

func SwitchURLAndID added in v0.2.0

func SwitchURLAndID(key string) (string, error)

SwitchURLAndID converts a PR URL to its mapped chat channel or thread IDs, and vice versa.

func UpsertUser added in v0.6.0

func UpsertUser(email, bitbucketID, githubID, slackID, thrippyLink string) error

func UserLinkID added in v0.5.0

func UserLinkID(email string) (string, error)

Types

type PRTurn added in v0.6.0

type PRTurn struct {
	Author    string          `json:"author"`    // Email address of the PR author.
	Reviewers map[string]bool `json:"reviewers"` // Email address -> is it their turn?
	Set       bool            `json:"set"`       // Whether the attention state has been set explicitly.
}

PRTurn represents the attention state for a specific pull request.

The [Reviewers] map tracks which reviewers are assigned to the PR and whether it's currently their turn to pay attention to it.

Initial state:

  • If the map is empty, the PR author is considered responsible for the PR's progress: they need to assign reviewers or merge the PR.
  • When any number of reviewers are assigned, at the same time or separately, the initial state of their turn flag is set to true. Each one of them needs to pay attention to the PR.

State transitions for reviewers:

  • When a reviewer approves the PR, or is unassigned from it, they are removed from the map. They will no longer need to pay attention to this PR, unless they are added again later.
  • When a reviewer creates a new comment, reply, or code suggestion, their turn flag is set to false. It is no longer their turn to pay attention to the PR. This does not affect other reviewers.
  • If a reviewer creates multiple-but-separate comments or code suggestions, their turn flag remains false.

State transitions for the author:

  • The author's state is USUALLY not tracked explicitly. They need to pay attention to the PR whenever at least one reviewer has their turn flag set to false.

  • When the author addresses review comments (i.e. creates a new comment or reply), the turn flags of all the reviewers are reset to true. It is their turn still/again to pay attention to the PR.

  • Pushing commits does not have the same effect for now, as it may be work in progress. Only discussions trigger state changes.

Manual state changes:

  • Any participant (author or reviewers) may indicate that it is or isn't their turn to pay attention to the PR, by using a Slack slash command instead of interacting within the PR discussion.
  • Any participant may also set the entire attention state explicitly, specifying exactly which reviewers need to pay attention to the PR. Unmentioned reviewers are not removed from the map, but their turn flags are set to false. If the author is mentioned, they are added temporarily until a regular state transition affects them.

type User added in v0.6.0

type User struct {
	Created string `json:"created,omitempty"`
	Updated string `json:"updated,omitempty"`
	Deleted string `json:"deleted,omitempty"`

	Email       string `json:"email,omitempty"`
	BitbucketID string `json:"bitbucket_id,omitempty"`
	GitHubID    string `json:"github_id,omitempty"`
	SlackID     string `json:"slack_id,omitempty"`
	ThrippyLink string `json:"thrippy_link,omitempty"`
}

User represents a mapping between various user IDs and email addresses across different platforms (Bitbucket, GitHub, Slack).

func SelectUserByBitbucketID added in v0.6.0

func SelectUserByBitbucketID(bitbucketID string) (User, error)

func SelectUserByEmail added in v0.6.0

func SelectUserByEmail(email string) (User, error)

func SelectUserByGitHubID added in v0.6.0

func SelectUserByGitHubID(githubID string) (User, error)

func SelectUserBySlackID added in v0.6.0

func SelectUserBySlackID(slackID string) (User, error)

type Users added in v0.6.0

type Users struct {
	// contains filtered or unexported fields
}

Users is an indexed copy of a collection of User entries. This should really be stored in a relational database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL