data

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 18 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

This section is empty.

Variables

This section is empty.

Functions

func AddReviewerToPR added in v0.6.0

func AddReviewerToPR(url, email string) error

AddReviewerToPR 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 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(url string) error

func DeleteBitbucketDiffstat added in v0.8.0

func DeleteBitbucketDiffstat(url string) error

func DeleteBitbucketPR added in v0.2.0

func DeleteBitbucketPR(url string) error

DeleteBitbucketPR deletes the snapshot of a Bitbucket pull request when it becomes obsolete (i.e. when the PR is merged, closed, or marked as a draft). This function is idempotent: it does not return an error if the snapshot does not exist.

func DeleteReminder added in v0.5.0

func DeleteReminder(userID string) error

func DeleteSlackBotIDs added in v0.4.0

func DeleteSlackBotIDs(botID string) error

func DeleteTurns added in v0.8.0

func DeleteTurns(url string) error

DeleteTurns removes the attention state file of a specific PR. This is used when the PR is closed or marked as a draft.

func DeleteURLAndIDMapping added in v0.2.0

func DeleteURLAndIDMapping(key string) error

DeleteURLAndIDMapping deletes the 2-way mapping between PR URLs and chat channel and thread IDs when they become obsolete (i.e. when the PR is merged, closed, or marked as a draft).

func FollowUser added in v1.0.0

func FollowUser(followerSlackID, followedSlackID string) error

func FreezeTurn added in v1.0.0

func FreezeTurn(url, email string) (bool, error)

FreezeTurn marks the attention state of a specific PR as frozen by a specific user. This prevents any 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

func GetCurrentTurn(url 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(botID string) (string, error)

func InitTurns added in v0.8.0

func InitTurns(url, author string, reviewers []string) error

InitTurns initializes the attention state of a new PR. Users are specified using their email addresses.

func IsOptedIn

func IsOptedIn(u User) bool

func ListReminders added in v0.5.0

func ListReminders() (map[string]string, error)

func LoadBitbucketPR added in v0.2.0

func LoadBitbucketPR(url string) (map[string]any, error)

LoadBitbucketPR loads a snapshot of a Bitbucket pull request. This is used to detect changes in the pull request over time. This function returns nil if no snapshot is found.

func LogSlackChannelArchived added in v0.6.0

func LogSlackChannelArchived(channelID, url string) error

func LogSlackChannelCreated added in v0.6.0

func LogSlackChannelCreated(channelID, name, url string) error

func LogSlackChannelDeleted added in v0.6.0

func LogSlackChannelDeleted(channelID string) error

func LogSlackChannelRenamed added in v0.6.0

func LogSlackChannelRenamed(channelID, name string) error

func MapURLAndID added in v0.2.0

func MapURLAndID(url, id string) error

MapURLAndID saves a 2-way mapping between a PR URL and its dedicated chat channel or thread IDs.

func Nudge added in v0.7.0

func Nudge(url, email string) (bool, 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. It returns true if the nudge is valid (the user is in the current turn list).

func ReadBitbucketDiffstatLength added in v0.8.0

func ReadBitbucketDiffstatLength(url string) int

func ReadBitbucketDiffstatPaths added in v0.8.0

func ReadBitbucketDiffstatPaths(url string) []string

func RemoveFromTurn added in v0.6.0

func RemoveFromTurn(url, email string) error

RemoveFromTurn completely removes a reviewer from the attention state of a specific PR. This is used when that reviewer approves the PR, or is unassigned from the PR. 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(userID, kitchenTime, tz string) error

func SetSlackBotUserID added in v0.4.0

func SetSlackBotUserID(botID, userID string) error

func StoreBitbucketPR added in v0.2.0

func StoreBitbucketPR(url string, pr any) error

StoreBitbucketPR saves a snapshot of a Bitbucket pull request. This is used to detect changes in the pull request over time.

func SummarizeBitbucketBuilds added in v0.7.0

func SummarizeBitbucketBuilds(url string) string

func SwitchTurn added in v0.6.0

func SwitchTurn(url, email string) error

SwitchTurn switches the turn of a specific user in a specific PR. If the user is not found, or if the turn is frozen, this function does nothing. 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(key string) (string, error)

SwitchURLAndID converts a PR URL to its mapped chat channel or thread IDs, and vice versa.

func UnfollowUser added in v1.0.0

func UnfollowUser(unfollowerSlackID, followedSlackID string) error

func UnfreezeTurn added in v1.0.0

func UnfreezeTurn(url string) (bool, error)

UnfreezeTurn is the inverse of FreezeTurn. If the turn is not frozen, this function returns false and does nothing.

func UpdateBitbucketBuilds added in v0.7.0

func UpdateBitbucketBuilds(url, commitHash, key string, cs CommitStatus) error

func UpdateBitbucketDiffstat added in v0.8.0

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

func UpsertUser added in v0.6.0

func UpsertUser(email, bitbucketID, githubID, slackID, realName, 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"`
}

func ReadBitbucketBuilds added in v0.7.0

func ReadBitbucketBuilds(url string) *PRStatus

type PRTurn added in v0.6.0

type PRTurn struct {
	Author    string          `json:"author"`    // Email address of the PR author.
	Reviewers map[string]bool `json:"reviewers"` // Email address -> is it their turn?

	FrozenAt string `json:"frozen_at,omitempty"`
	FrozenBy string `json:"frozen_by,omitempty"`
}

PRTurn represents the attention state for all the author-reviewer pairs in a specific pull request.

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 {
	Created string `json:"created,omitempty"`
	Updated string `json:"updated,omitempty"`
	Deleted string `json:"deleted,omitempty"`

	Email       string `json:"email,omitempty"`
	BitbucketID string `json:"bitbucket_id,omitempty"`
	GitHubID    string `json:"github_id,omitempty"`
	SlackID     string `json:"slack_id,omitempty"`
	RealName    string `json:"real_name,omitempty"`

	ThrippyLink string `json:"thrippy_link,omitempty"`

	// Slack user IDs, controlled by the un/follow slash commands, used when creating channels.
	Followers []string `json:"followers,omitempty"`
}

User represents a mapping between various user IDs and email addresses across different platforms (Bitbucket, GitHub, Slack).

func SelectUserByBitbucketID added in v0.6.0

func SelectUserByBitbucketID(bitbucketID string) (User, error)

func SelectUserByEmail added in v0.6.0

func SelectUserByEmail(email string) (User, error)

func SelectUserByGitHubID added in v0.6.0

func SelectUserByGitHubID(githubID string) (User, error)

func SelectUserByRealName added in v1.0.0

func SelectUserByRealName(realName string) (User, error)

func SelectUserBySlackID added in v0.6.0

func SelectUserBySlackID(slackID string) (User, error)

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