data

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

View Source
const (
	URLs     = internal.URLs
	Channels = internal.Channels
)
View Source
const (
	DiffstatFileSuffix = internal.DiffstatFileSuffix
)
View Source
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

func CleanupPRData(ctx workflow.Context, channelID, prURL string)

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 DeleteBitbucketBuilds(ctx workflow.Context, prURL string)

func DeleteDiffstat added in v1.1.0

func DeleteDiffstat(ctx workflow.Context, prURL string)

func DeletePRSnapshot added in v1.5.0

func DeletePRSnapshot(ctx workflow.Context, prURL string)

func DeleteScheduledUserReminder added in v1.9.0

func DeleteScheduledUserReminder(ctx workflow.Context, userID string)

func DeleteTurns added in v0.8.0

func DeleteTurns(ctx workflow.Context, prURL string)

func DeleteURLAndIDMapping added in v0.2.0

func DeleteURLAndIDMapping(ctx workflow.Context, key string)

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

func FindPRsByCommit(ctx workflow.Context, hash string) ([]map[string]any, error)

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 FollowUser(ctx workflow.Context, followerSlackID, followedSlackID string) bool

func FreezeTurns added in v1.3.1

func FreezeTurns(ctx workflow.Context, opts client.Options, prURL, email string) (bool, error)

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

func GetActivityTime(ctx workflow.Context, opts client.Options, prURL, email string) time.Time

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 GetSlackBotUserID(ctx workflow.Context, botID string) string

func InitTurns added in v0.8.0

func InitTurns(ctx workflow.Context, prURL, authorEmail string)

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

func IsFrozen(ctx workflow.Context, opts client.Options, prURL string) (time.Time, string)

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 ListScheduledUserReminders(ctx workflow.Context) (map[string]string, error)

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 LoadDiffstatPaths(ctx workflow.Context, prURL string) []string

func LoadPRSnapshot added in v1.5.0

func LoadPRSnapshot(ctx workflow.Context, prURL string) (map[string]any, error)

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 LogSlackChannelArchived(ctx workflow.Context, channelID, prURL string)

func LogSlackChannelCreated added in v0.6.0

func LogSlackChannelCreated(ctx workflow.Context, channelID, prURL, name string)

func MapURLAndID added in v0.2.0

func MapURLAndID(ctx workflow.Context, url, ids string) error

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 ReadAllURLsOrChannels(ctx workflow.Context, what string) ([]string, error)

func RemoveFollower added in v1.1.0

func RemoveFollower(ctx workflow.Context, followerSlackID string)

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 SetScheduledUserReminder(ctx workflow.Context, userID, kitchenTime, tz string) error

func SetSlackBotUserID added in v0.4.0

func SetSlackBotUserID(ctx workflow.Context, botID, userID string)

func StoreDiffstat added in v1.9.0

func StoreDiffstat(ctx workflow.Context, prURL string, files any)

func StorePRSnapshot added in v1.5.0

func StorePRSnapshot(ctx workflow.Context, prURL string, pr any)

StorePRSnapshot writes a snapshot of a PR, which is used to detect and analyze metadata changes.

func SwitchTurn added in v0.6.0

func SwitchTurn(ctx workflow.Context, opts client.Options, prURL, email string, force bool) error

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

func SwitchURLAndID(ctx workflow.Context, key string) (string, error)

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 UnfollowUser(ctx workflow.Context, followerSlackID, followedSlackID string) bool

func UnfreezeTurns added in v1.3.1

func UnfreezeTurns(ctx workflow.Context, opts client.Options, prURL string) (bool, error)

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

func UpdateActivityTime(ctx workflow.Context, opts client.Options, prURL, email string)

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.

func UpsertUser added in v0.6.0

func UpsertUser(ctx workflow.Context, email, realName, bitbucketID, githubID, slackID, thrippyLink string) error

Types

type CommitStatus added in v0.7.0

type CommitStatus = internal.CommitStatus

type PRStatus added in v0.7.0

type PRStatus = internal.PRStatus

func ReadBitbucketBuilds added in v0.7.0

func ReadBitbucketBuilds(ctx workflow.Context, prURL string) PRStatus

type User added in v0.6.0

type User = internal.User

func SelectUserByBitbucketID added in v0.6.0

func SelectUserByBitbucketID(ctx workflow.Context, accountID string) User

func SelectUserByEmail added in v0.6.0

func SelectUserByEmail(ctx workflow.Context, email string) User

func SelectUserByGitHubID added in v0.6.0

func SelectUserByGitHubID(ctx workflow.Context, login string) User

func SelectUserByRealName added in v1.0.0

func SelectUserByRealName(ctx workflow.Context, realName string) User

func SelectUserBySlackID added in v0.6.0

func SelectUserBySlackID(ctx workflow.Context, userID string) (User, bool, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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