Documentation
¶
Overview ¶
Package data provides Temporal activity wrappers for nondeterministic functions to in an internal sub-package, to manage persistent data. For the time being, storage is file-based on the local filesystem. Future implementations may include a database and/or a key-value store.
Index ¶
- Constants
- func CleanupPRData(ctx workflow.Context, channelID, prURL string)
- func DeleteBitbucketBuilds(ctx workflow.Context, prURL string)
- func DeleteDiffstat(ctx workflow.Context, prURL string)
- func DeletePRSnapshot(ctx workflow.Context, prURL string)
- func DeleteScheduledUserReminder(ctx workflow.Context, userID string)
- func DeleteTurns(ctx workflow.Context, prURL string)
- func DeleteURLAndIDMapping(ctx workflow.Context, key string)
- func FindPRsByCommit(ctx workflow.Context, hash string) ([]map[string]any, error)
- func FollowUser(ctx workflow.Context, followerSlackID, followedSlackID string) bool
- func FreezeTurns(ctx workflow.Context, opts client.Options, prURL, email string) (bool, error)
- func GetActivityTime(ctx workflow.Context, opts client.Options, prURL, email string) time.Time
- func GetSlackBotUserID(ctx workflow.Context, botID string) string
- func InitTurns(ctx workflow.Context, prURL, authorEmail string)
- func IsFrozen(ctx workflow.Context, opts client.Options, prURL string) (time.Time, string)
- func ListPRsPerSlackUser(ctx workflow.Context, opts client.Options, ...) (userPRs map[string][]string, alerts [][]any)
- func ListScheduledUserReminders(ctx workflow.Context) (map[string]string, error)
- func LoadCurrentTurnEmails(ctx workflow.Context, opts client.Options, prURL string) ([]string, error)
- func LoadDiffstatPaths(ctx workflow.Context, prURL string) []string
- func LoadPRSnapshot(ctx workflow.Context, prURL string) (map[string]any, error)
- func LogSlackChannelArchived(ctx workflow.Context, channelID, prURL string)
- func LogSlackChannelCreated(ctx workflow.Context, channelID, prURL, name string)
- func MapURLAndID(ctx workflow.Context, url, ids string) error
- func ReadAllURLsOrChannels(ctx workflow.Context, what string) ([]string, error)
- func RemoveFollower(ctx workflow.Context, followerSlackID string)
- func RemoveReviewerFromTurns(ctx workflow.Context, opts client.Options, prURL, email string, approved bool) error
- func SetReviewerTurn(ctx workflow.Context, opts client.Options, prURL, email string, nudge bool) (done, approved bool, err error)
- func SetScheduledUserReminder(ctx workflow.Context, userID, kitchenTime, tz string) error
- func SetSlackBotUserID(ctx workflow.Context, botID, userID string)
- func StoreDiffstat(ctx workflow.Context, prURL string, files any)
- func StorePRSnapshot(ctx workflow.Context, prURL string, pr any)
- func SwitchTurn(ctx workflow.Context, opts client.Options, 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, opts client.Options, prURL string) (bool, error)
- func UpdateActivityTime(ctx workflow.Context, opts client.Options, prURL, email string)
- func UpdateBitbucketBuilds(ctx workflow.Context, prURL, commitHash, key string, cs CommitStatus)
- func UpsertUser(ctx workflow.Context, ...) error
- type CommitStatus
- type PRStatus
- 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)
Constants ¶
const ( URLs = internal.URLs Channels = internal.Channels )
const (
DiffstatFileSuffix = internal.DiffstatFileSuffix
)
const ( // SlackIDNotFound is a key suffix used in [ListPRsPerSlackUser] and by its callers. // It indicates that the key suffix (email address) couldn't be matched to a Slack user ID. SlackIDNotFound = internal.SlackIDNotFound )
Variables ¶
This section is empty.
Functions ¶
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 DeleteDiffstat ¶ added in v1.1.0
func DeletePRSnapshot ¶ added in v1.5.0
func DeleteScheduledUserReminder ¶ added in v1.9.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 FindPRsByCommit ¶ added in v1.9.0
FindPRsByCommit returns all (0 or more) the PR snapshots that are currently associated with the given commit hash.
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 GetActivityTime ¶ added in v1.5.0
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 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 IsFrozen ¶ added in v1.9.0
IsFrozen returns the timestamp and user email of when and who froze the attention state of a specific PR. If the turn is not frozen, it returns a zero timestamp and an empty string.
func ListPRsPerSlackUser ¶ added in v1.9.0
func ListPRsPerSlackUser( ctx workflow.Context, opts client.Options, currentTurn, authors, reviewers bool, filter []string, ) (userPRs map[string][]string, alerts [][]any)
ListPRsPerSlackUser 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. It also returns a list of details about user emails without a known Slack ID, for alerting.
func ListScheduledUserReminders ¶ added in v1.9.0
func LoadCurrentTurnEmails ¶ added in v1.9.0
func LoadCurrentTurnEmails(ctx workflow.Context, opts client.Options, prURL string) ([]string, error)
LoadCurrentTurnEmails 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 LoadDiffstatPaths ¶ added in v1.9.0
func LoadPRSnapshot ¶ added in v1.5.0
LoadPRSnapshot 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 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 ReadAllURLsOrChannels ¶ added in v1.9.3
func RemoveFollower ¶ added in v1.1.0
func RemoveReviewerFromTurns ¶ added in v1.1.0
func RemoveReviewerFromTurns(ctx workflow.Context, opts client.Options, prURL, email string, approved bool) error
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 SetReviewerTurn ¶ added in v1.9.0
func SetReviewerTurn(ctx workflow.Context, opts client.Options, prURL, email string, nudge bool) (done, approved bool, err error)
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 SetScheduledUserReminder ¶ added in v1.9.0
func SetSlackBotUserID ¶ added in v0.4.0
func StoreDiffstat ¶ added in v1.9.0
func StorePRSnapshot ¶ added in v1.5.0
StorePRSnapshot writes a snapshot of a PR, which is used to detect and analyze 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 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 ¶ 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.
Types ¶
type CommitStatus ¶ added in v0.7.0
type CommitStatus = internal.CommitStatus