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
- func AddReviewerToTurns(ctx workflow.Context, prURL, email string) error
- func BitbucketIDToEmail(ctx workflow.Context, accountID string) string
- func CleanupPRData(ctx workflow.Context, channelID, prURL string)
- func DeleteBitbucketBuilds(ctx workflow.Context, prURL string)
- func DeleteBitbucketPR(ctx workflow.Context, url string)
- func DeleteDiffstat(ctx workflow.Context, url string)
- func DeleteReminder(ctx workflow.Context, userID string)
- func DeleteSlackBotIDs(ctx workflow.Context, botID string) error
- func DeleteTurns(ctx workflow.Context, prURL string)
- func DeleteURLAndIDMapping(ctx workflow.Context, key string)
- func FollowUser(ctx workflow.Context, followerSlackID, followedSlackID string) bool
- func FreezeTurns(ctx workflow.Context, prURL, email string) (bool, error)
- func Frozen(ctx workflow.Context, url string) (time.Time, string)
- func GetCurrentTurn(ctx workflow.Context, prURL string) ([]string, error)
- func GetSlackBotUserID(ctx workflow.Context, botID string) (string, error)
- func InitTurns(ctx workflow.Context, prURL, authorEmail string)
- func ListReminders(ctx workflow.Context) (map[string]string, error)
- func LoadBitbucketPR(ctx workflow.Context, url string) (map[string]any, error)
- func LogSlackChannelArchived(ctx workflow.Context, channelID, url string)
- func LogSlackChannelCreated(ctx workflow.Context, channelID, name, url string)
- func MapURLAndID(ctx workflow.Context, url, ids string) error
- func Nudge(ctx workflow.Context, prURL, email string) (ok, approved bool, err error)
- func ReadBitbucketDiffstatPaths(url string) []string
- func RemoveFollower(ctx workflow.Context, followerSlackID string)
- func RemoveReviewerFromTurns(ctx workflow.Context, prURL, email string, approved bool) error
- func SetReminder(ctx workflow.Context, userID, kitchenTime, tz string) error
- func SetSlackBotUserID(ctx workflow.Context, botID, userID string) error
- func StoreBitbucketPR(ctx workflow.Context, url string, pr any)
- func SwitchTurn(ctx workflow.Context, prURL, email string, force bool) error
- func SwitchURLAndID(ctx workflow.Context, key string) (string, error)
- func UnfollowUser(ctx workflow.Context, followerSlackID, followedSlackID string) bool
- func UnfreezeTurns(ctx workflow.Context, prURL string) (bool, error)
- func UpdateActivityTime(ctx workflow.Context, prURL, email string)
- func UpdateBitbucketBuilds(ctx workflow.Context, prURL, commitHash, key string, cs CommitStatus)
- func UpdateBitbucketDiffstat(url string, ds []bitbucket.Diffstat) error
- func UpsertUser(ctx workflow.Context, ...) error
- type CommitStatus
- type PRStatus
- type PRTurns
- type RWMutexMap
- type User
- func SelectUserByBitbucketID(ctx workflow.Context, accountID string) User
- func SelectUserByEmail(ctx workflow.Context, email string) User
- func SelectUserByGitHubID(ctx workflow.Context, login string) User
- func SelectUserByRealName(ctx workflow.Context, realName string) User
- func SelectUserBySlackID(ctx workflow.Context, userID string) (User, bool, error)
- type Users
Constants ¶
const (
BitbucketPRSnapshotFileSuffix = "_snapshot.json"
)
const (
TurnsFileSuffix = "_turns.json"
)
Variables ¶
This section is empty.
Functions ¶
func AddReviewerToTurns ¶ added in v1.1.0
AddReviewerToTurns adds a new reviewer to the attention state 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 BitbucketIDToEmail ¶ added in v1.1.0
BitbucketIDToEmail converts a Bitbucket account ID into an email address. This function returns an empty string if the account ID is not found. It uses persistent data storage, or API calls as a fallback. This function is also wrapped in the "users" package, and reused by other packages from there.
func CleanupPRData ¶ added in v1.0.0
CleanupPRData deletes all the data associated with a PR. If there are errors, they are logged but ignored, as they do not affect the overall need to clean up.
func DeleteBitbucketBuilds ¶ added in v0.8.0
func DeleteBitbucketPR ¶ added in v0.2.0
func DeleteDiffstat ¶ added in v1.1.0
func DeleteReminder ¶ added in v0.5.0
func DeleteSlackBotIDs ¶ added in v0.4.0
func DeleteTurns ¶ added in v0.8.0
func DeleteURLAndIDMapping ¶ added in v0.2.0
DeleteURLAndIDMapping deletes the 2-way mapping between PR and PR comment URLs and their corresponding Slack channel and thread IDs when they become obsolete. Errors here are notable but not critical, so they are logged but not returned.
func FollowUser ¶ added in v1.0.0
func FreezeTurns ¶ added in v1.3.1
FreezeTurns marks the attention state of a specific PR as frozen by a specific user. This prevents most changes by SwitchTurn, and only by it, until it is unfrozen. If the turn is already frozen, this function returns false and does nothing.
func GetCurrentTurn ¶ added in v0.6.0
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.
func GetSlackBotUserID ¶ added in v0.4.0
func InitTurns ¶ added in v0.8.0
InitTurns initializes the attention state of a new PR with its author's email address. The initial state has no reviewers; they are added when they are added to the Slack channel.
func ListReminders ¶ added in v0.5.0
func LoadBitbucketPR ¶ added in v0.2.0
LoadBitbucketPR reads a snapshot of a Bitbucket PR, which is used to detect metadata changes. If a snapshot doesn't exist, this function returns a nil map and no error.
func LogSlackChannelArchived ¶ added in v0.6.0
func LogSlackChannelCreated ¶ added in v0.6.0
func MapURLAndID ¶ added in v0.2.0
MapURLAndID saves a 2-way mapping between PR and PR comment URLs and their corresponding Slack channel and thread IDs. An error in mapping a new Slack channel is critical, but an error in mapping Slack messages isn't.
func Nudge ¶ added in v0.7.0
Nudge records that a specific user has been nudged about a specific PR, so it becomes their turn to pay attention to that PR if it wasn't already. The first boolean return value indicates whether the nudge is valid (the user is tracked as a reviewer). The second indicates if the user already approved the PR (in case the first value is false).
func ReadBitbucketDiffstatPaths ¶ added in v0.8.0
func RemoveFollower ¶ added in v1.1.0
func RemoveReviewerFromTurns ¶ added in v1.1.0
RemoveReviewerFromTurns completely removes a reviewer from the attention state of a specific PR. This is called when that reviewer approves the PR, or is unassigned from it. 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 SetSlackBotUserID ¶ added in v0.4.0
func StoreBitbucketPR ¶ added in v0.2.0
StoreBitbucketPR writes a snapshot of a Bitbucket PR, which is used to detect metadata changes.
func SwitchTurn ¶ added in v0.6.0
SwitchTurn switches the turn of a specific user in a specific PR to others. If the user is not found or is a bot, this function does nothing. If turns are frozen and the switch isn't forced, it only records the activity. If the user is the PR author, it adds all reviewers to the attention state. If the user is a reviewer, it adds the author to the attention state.
func SwitchURLAndID ¶ added in v0.2.0
SwitchURLAndID converts the URL of a PR or PR comment into the corresponding channel or thread IDs, and vice versa.
func UnfollowUser ¶ added in v1.0.0
func UnfreezeTurns ¶ added in v1.3.1
UnfreezeTurns is the inverse of FreezeTurns. If the turn is not frozen, this function returns false and does nothing.
func UpdateActivityTime ¶ added in v1.3.2
UpdateActivityTime updates the last activity timestamp of a specific user in a specific PR. If the user is empty or "bot", this function does nothing. This is called when the user interacts with the PR in any way that doesn't change their turn (such as PR edits, commit pushes, and review actions).
func UpdateBitbucketBuilds ¶ added in v0.7.0
func UpdateBitbucketBuilds(ctx workflow.Context, prURL, commitHash, key string, cs CommitStatus)
UpdateBitbucketBuilds appends the given build status to the given PR, unless the new status is based on a different (i.e. newer) commit, in which case this function discards all previous build statuses.
func UpdateBitbucketDiffstat ¶ added in v0.8.0
Types ¶
type CommitStatus ¶ added in v0.7.0
type PRStatus ¶ added in v0.7.0
type PRStatus struct {
CommitHash string `json:"commit_hash"`
Builds map[string]CommitStatus `json:"builds"`
}
PRStatus represents the current status of all reported builds for a specific Bitbucket PR at a specific commit.
type PRTurns ¶ added in v1.3.1
type PRTurns struct {
Author string `json:"author"` // Email address of the PR author.
Reviewers map[string]bool `json:"reviewers,omitempty"` // Email address -> is it their turn?
Activity map[string]time.Time `json:"activity,omitempty"` // When each user last interacted with the PR.
Approvers map[string]time.Time `json:"approvers,omitempty"` // When each user approved the PR.
FrozenAt time.Time `json:"frozen_at,omitzero"`
FrozenBy string `json:"frozen_by,omitempty"`
}
PRTurns represents the attention state for all the author-reviewer pairs in a specific pull request, and also records activity timestamps.
type RWMutexMap ¶ added in v0.7.0
type RWMutexMap struct {
// contains filtered or unexported fields
}
type User ¶ added in v0.6.0
type User struct {
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"`
RealName string `json:"real_name,omitempty"` // Not guaranteed to be unique, unlike the fields above.
// Slack user IDs, controlled by the un/follow slash commands, used when creating channels.
Followers []string `json:"followers,omitempty"`
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
Deleted string `json:"deleted,omitempty"`
}
User represents a mapping between a unique email address and at least 2 other unique identifiers for that person across different systems (Bitbucket, GitHub, Slack, Thrippy).