Documentation
¶
Index ¶
- Constants
- func AppendToCSVFile(_ context.Context, record []string) error
- func DelURLAndIDMapping(_ context.Context, key string) error
- func DeleteGenericPRFile(_ context.Context, prURLWithSuffix string) error
- func DeleteReminder(_ context.Context, userID string) error
- func FindPRsByCommit(ctx context.Context, hash string) (prs []map[string]any, err error)
- func FreezeTurns(ctx context.Context, prURL, email string) (bool, error)
- func GetActivityTime(ctx context.Context, prURL, email string) (time.Time, error)
- func GetSlackBotUserID(_ context.Context, botID string) (string, error)
- func GetURLAndIDMapping(_ context.Context, key string) (string, error)
- func InitTurns(prURL, authorEmail string) error
- func ListReminders(_ context.Context) (map[string]string, error)
- func ReadCurrentTurnEmails(ctx context.Context, prURL string) ([]string, error)
- func ReadDiffstatPaths(_ context.Context, prURL string) ([]string, error)
- func ReadPRSnapshot(_ context.Context, prURL string) (map[string]any, error)
- func ReadPRsPerSlackUser(ctx context.Context, onlyCurrentTurn, authors, reviewers bool, ...) (map[string][]string, error)
- func RemoveFollower(_ context.Context, followerSlackID string) error
- func RemoveReviewerFromTurns(ctx context.Context, prURL, email string, approved bool) error
- func SetReminder(_ context.Context, userID, kitchenTime, tz string) error
- func SetReviewerTurn(ctx context.Context, prURL, email string, nudge bool) ([2]bool, error)
- func SetSlackBotUserID(_ context.Context, botID, userID string) error
- func SetURLAndIDMapping(_ context.Context, url, ids string) error
- func SwitchTurn(ctx context.Context, prURL, email string, force bool) error
- func UnfreezeTurns(ctx context.Context, prURL string) (bool, error)
- func UpdateActivityTime(ctx context.Context, prURL, email string) error
- func UpdateBitbucketBuilds(_ context.Context, prURL, commitHash, key string, cs CommitStatus) error
- func WriteDiffstat(_ context.Context, prURL string, files any) error
- func WritePRSnapshot(_ context.Context, prURL string, pr any) error
- type CommitStatus
- type Frozen
- type PRStatus
- type PRTurns
- type User
- func FollowUser(_ context.Context, followerSlackID, followedSlackID string) (User, error)
- func SelectUser(_ context.Context, indexType int, id string) (User, error)
- func UnfollowUser(_ context.Context, followerSlackID, followedSlackID string) (User, error)
- func UpsertUser(_ context.Context, ...) (User, error)
- type Users
Constants ¶
const ( TurnsFileSuffix = "_turns.json" SlackIDNotFound = " email not found" )
const ( IndexByEmail = 1 IndexByBitbucketID = 2 IndexByGitHubID = 3 IndexBySlackID = 4 IndexByRealName = 5 )
const (
BuildsFileSuffix = "_builds.json"
)
const (
DiffstatFileSuffix = "_diffstat.json"
)
const (
PRSnapshotFileSuffix = "_snapshot.json"
)
Variables ¶
This section is empty.
Functions ¶
func DeleteGenericPRFile ¶
DeleteGenericPRFile deletes a file related to a specific PR. Unlike os.Remove, this is idempotent: it does not return an error if the file does not exist.
func FindPRsByCommit ¶
FindPRsByCommit returns all (0 or more) the PR snapshots that are currently associated with the given commit hash. This is used when processing Bitbucket commit events, to identify the relevant PR(s). To do this, this function scans through all the PR snapshots and checks their current commit hashes. Lastly, this function prunes redundant PR details, to reduce Temporal log size and noise.
func FreezeTurns ¶
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 GetActivityTime ¶
GetActivityTime returns the last activity timestamp of a specific user in a specific PR. If the user is not found or is a bot, this function returns a zero timestamp.
func InitTurns ¶
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. Happens only once per PR, in the beginning, so no need for a Temporal activity, mutex, etc.
func ReadCurrentTurnEmails ¶
ReadCurrentTurnEmails 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 ReadPRSnapshot ¶
ReadPRSnapshot reads a snapshot of a PR, which is used to detect and analyze metadata changes. If a snapshot doesn't exist, this function returns a nil map and no error.
func ReadPRsPerSlackUser ¶
func ReadPRsPerSlackUser(ctx context.Context, onlyCurrentTurn, authors, reviewers bool, idFilter []string) (map[string][]string, error)
ReadPRsPerSlackUser scans all stored PR turn files, and returns a mapping from Slack user IDs to all the PR URLs they need to be reminded about.
func RemoveReviewerFromTurns ¶
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.
func SetReviewerTurn ¶
SetReviewerTurn records that it's a specific user's turn to review a specific PR: either because they were added as a reviewer, or because they're an existing reviewer and were nudged. This function is idempotent either way, but the return values indicate the state for nudge calls: The first boolean indicates whether the requested nudge is allowed (the user is tracked as a reviewer), and the second one indicates whether the user already approved the PR (in case the first value is false).
func SwitchTurn ¶
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 UnfreezeTurns ¶
UnfreezeTurns is the inverse of FreezeTurns. If the turn is not frozen, this function returns false and does nothing.
func UpdateActivityTime ¶
UpdateActivityTime updates the last activity timestamp of a specific user in a specific PR. If the user is not found or is a 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 ¶
func UpdateBitbucketBuilds(_ context.Context, prURL, commitHash, key string, cs CommitStatus) error
Types ¶
type CommitStatus ¶
type Frozen ¶
Frozen is used to return the result of IsFrozen in a single struct, instead of two separate values.
type PRStatus ¶
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 ¶
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 User ¶
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 Slack commands, used when creating channels.
Followers []string `json:"followers,omitempty"`
Created time.Time `json:"created,omitzero"`
Updated time.Time `json:"updated,omitzero"`
Deleted time.Time `json:"deleted,omitzero"`
}
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).