data

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 21 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

View Source
const (
	BitbucketPRSnapshotFileSuffix = "_snapshot.json"
)
View Source
const (
	TurnsFileSuffix = "_turns.json"
)

Variables

This section is empty.

Functions

func AddReviewerToTurns added in v1.1.0

func AddReviewerToTurns(ctx workflow.Context, prURL, email string) error

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

func BitbucketIDToEmail(ctx workflow.Context, accountID string) string

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

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 DeleteBitbucketPR added in v0.2.0

func DeleteBitbucketPR(ctx workflow.Context, url string)

func DeleteDiffstat added in v1.1.0

func DeleteDiffstat(ctx workflow.Context, url string)

func DeleteReminder added in v0.5.0

func DeleteReminder(ctx workflow.Context, userID string)

func DeleteSlackBotIDs added in v0.4.0

func DeleteSlackBotIDs(ctx workflow.Context, botID string) error

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 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, 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 Frozen added in v1.2.1

func Frozen(ctx workflow.Context, url string) (time.Time, string)

func GetCurrentTurn added in v0.6.0

func GetCurrentTurn(ctx workflow.Context, prURL 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.

func GetSlackBotUserID added in v0.4.0

func GetSlackBotUserID(ctx workflow.Context, botID string) (string, error)

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 ListReminders added in v0.5.0

func ListReminders(ctx workflow.Context) (map[string]string, error)

func LoadBitbucketPR added in v0.2.0

func LoadBitbucketPR(ctx workflow.Context, url string) (map[string]any, error)

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

func LogSlackChannelCreated added in v0.6.0

func LogSlackChannelCreated(ctx workflow.Context, channelID, name, url 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 Nudge added in v0.7.0

func Nudge(ctx workflow.Context, prURL, email string) (ok, approved bool, err error)

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 ReadBitbucketDiffstatPaths(url string) []string

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, 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 SetReminder added in v0.5.0

func SetReminder(ctx workflow.Context, userID, kitchenTime, tz string) error

func SetSlackBotUserID added in v0.4.0

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

func StoreBitbucketPR added in v0.2.0

func StoreBitbucketPR(ctx workflow.Context, url string, pr any)

StoreBitbucketPR writes a snapshot of a Bitbucket PR, which is used to detect metadata changes.

func SwitchTurn added in v0.6.0

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

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

func UpdateBitbucketDiffstat(url string, ds []bitbucket.Diffstat) error

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 struct {
	Name  string `json:"name"`
	State string `json:"state"`
	Desc  string `json:"desc"`
	URL   string `json:"url"`
}

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.

func ReadBitbucketBuilds added in v0.7.0

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

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
}

func (*RWMutexMap) Get added in v0.7.0

func (mm *RWMutexMap) Get(key string) *sync.RWMutex

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).

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)

func (User) IsOptedIn added in v1.1.0

func (u User) IsOptedIn() bool

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