bitbucket

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeautifyInlineComment added in v1.0.0

func BeautifyInlineComment(ctx workflow.Context, comment *Comment, msg string) (string, []byte)

BeautifyInlineComment adds an informative prefix to the comment's text. If the comment contains a suggestion code block, it removes that block and also generates a diff snippet to attach to the Slack message instead.

func BitbucketToSlackIDs added in v1.0.0

func BitbucketToSlackIDs(ctx workflow.Context, accountIDs []string) []string

func ChannelMembers added in v1.1.0

func ChannelMembers(ctx workflow.Context, pr PullRequest) []string

ChannelMembers returns a list of opted-in Slack user IDs who are PR authors and reviewers. The output is guaranteed to be sorted, without repetitions, and not contain teams/apps.

func DeleteSlackMsg added in v1.1.0

func DeleteSlackMsg(ctx workflow.Context, url string) error

func Diffstat added in v1.0.0

func Diffstat(ctx workflow.Context, event PullRequestEvent) []bitbucket.Diffstat

func EditSlackMsg added in v1.1.0

func EditSlackMsg(ctx workflow.Context, url, msg string) error

func HTMLURL added in v1.0.0

func HTMLURL(links map[string]Link) string

func ImpersonateUserInMsg added in v1.0.0

func ImpersonateUserInMsg(ctx workflow.Context, url, channelID, alertsChannel string, user Account, msg string, diff []byte) error

func ImpersonateUserInReply added in v1.0.0

func ImpersonateUserInReply(ctx workflow.Context, url, parentURL, alertsChannel string, user Account, msg string, diff []byte) error

func ImpersonationToMention added in v1.0.0

func ImpersonationToMention(msg string) string

ImpersonationToMention converts a message that was meant to be used in ImpersonateUserInMsg or ImpersonateUserInReply into a message that can be used in MentionUserInMsg or MentionUserInReply, by adjusting the prefix.

This is potentially relevant only for file and inline comments: if the message includes a file (i.e. contains a Slack file permalink), we can't impersonate the user, because the Slack API won't allow us to update or delete the message later.

func InitPRData added in v1.0.0

func InitPRData(ctx workflow.Context, event PullRequestEvent, prChannelID, slackAlertsChannel string)

InitPRData saves the initial state of a new PR: snapshots of PR metadata, and a 2-way ID mapping for syncs between Bitbucket and Slack. If there are errors, they are logged but ignored, as we can try to recreate the data later.

func MapToStruct added in v1.0.0

func MapToStruct(m any, pr *PullRequest) error

MapToStruct converts a map-based representation of JSON data into a PullRequest struct.

func MentionUserInMsg added in v1.0.0

func MentionUserInMsg(ctx workflow.Context, channelID string, user Account, msg string)

func MentionUserInReply added in v1.0.0

func MentionUserInReply(ctx workflow.Context, parentURL string, user Account, msg string) error

func ReviewerMentions added in v1.0.0

func ReviewerMentions(ctx workflow.Context, added, removed []string) string

ReviewerMentions returns a Slack message mentioning all the newly added/removed reviewers.

func ReviewersDiff added in v1.0.0

func ReviewersDiff(prev, curr PullRequest) (added, removed []string)

ReviewerDiff returns the lists of added and removed reviewers, compared to the previous snapshot of the PR. The output is guaranteed to be sorted, without repetitions, and not contain teams/apps.

func SetChannelBookmarks added in v1.0.0

func SetChannelBookmarks(ctx workflow.Context, channelID, prURL string, pr PullRequest)

func SlackDisplayName added in v1.0.0

func SlackDisplayName(ctx workflow.Context, user Account) string

SlackDisplayName returns the Slack display name corresponding to the given Bitbucket user, linked to their Slack profile if possible. We use this instead of users.BitbucketIDToSlackRef in cases where we want to mention the user without actually spamming them with echoes of their own actions.

func UpdateChannelBookmarks added in v1.0.0

func UpdateChannelBookmarks(ctx workflow.Context, pr PullRequest, prURL, channelID string)

UpdateChannelBookmarks updates the bookmarks in the PR's Slack channel, based on the latest PR event. This is a deferred call that doesn't return an error, because handling the event itself is more important.

func UpdateChannelBuildsBookmark added in v1.0.0

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

UpdateChannelBuildsBookmark updates the "Builds" bookmark in the PR's Slack channel, based on the latest repository event. This is a deferred call that doesn't return an error, because handling the event itself is more important.

Types

type Account

type Account = bitbucket.User

type Branch

type Branch struct {
	Name string `json:"name"`

	Links          map[string]Link `json:"links,omitempty"`
	SyncStrategies []string        `json:"sync_strategies,omitempty"`
}

type Comment

type Comment = bitbucket.Comment

type Commit

type Commit = bitbucket.Commit

func Commits added in v1.0.0

func Commits(ctx workflow.Context, event PullRequestEvent) []Commit

type CommitStatus added in v0.6.0

type CommitStatus struct {
	Name        string `json:"name"`
	State       string `json:"state"`
	Description string `json:"description"`
	Key         string `json:"key"`
	URL         string `json:"url"`

	Refname *string `json:"refname"`
	Commit  *Commit `json:"commit,omitempty"`

	CreatedOn string `json:"created_on"`
	UpdatedOn string `json:"updated_on"`

	Links map[string]Link `json:"links"`
}

https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Build-status-created

type Inline

type Inline = bitbucket.Inline
type Link = bitbucket.Link

type Participant

type Participant struct {
	User           Account `json:"user"`
	Role           string  `json:"role"` // "PARTICIPANT" / "REVIEWER".
	Approved       bool    `json:"approved"`
	State          *string `json:"state"` // Nil / "changes_requested" / "approved".
	ParticipatedOn *string `json:"participated_on"`
}

type Project

type Project struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	UUID string `json:"uuid"`

	Links map[string]Link `json:"links"`
}

type PullRequest

type PullRequest struct {
	ID          int    `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	State       string `json:"state"` // "OPEN", "MERGED", "DECLINED".
	Draft       bool   `json:"draft"`

	Source      Reference `json:"source"`
	Destination Reference `json:"destination"`

	CreatedOn    string `json:"created_on"`
	UpdatedOn    string `json:"updated_on"`
	CommentCount int    `json:"comment_count"`
	TaskCount    int    `json:"task_count"`

	CommitCount        int `json:"commit_count"`         // Populated and used only in RevChat.
	ChangeRequestCount int `json:"change_request_count"` // Populated and used only in RevChat.

	Author       Account       `json:"author"`
	Participants []Participant `json:"participants"`
	Reviewers    []Account     `json:"reviewers"`
	ClosedBy     *Account      `json:"closed_by"`
	Reason       string        `json:"reason"`

	CloseSourceBranch bool    `json:"close_source_branch"`
	MergeCommit       *Commit `json:"merge_commit"`

	Links map[string]Link `json:"links"`
}

func SwitchSnapshot added in v1.0.0

func SwitchSnapshot(ctx workflow.Context, prURL string, snapshot PullRequest) (*PullRequest, error)

SwitchSnapshot stores the given new PR snapshot, and returns the previous one (if there is one).

type PullRequestEvent

type PullRequestEvent struct {
	Type string `json:"type"` // Populated and used only in RevChat.

	PullRequest PullRequest `json:"pullrequest"`
	Repository  Repository  `json:"repository"`
	Actor       Account     `json:"actor"`

	Approval       *Review  `json:"approval,omitempty"`
	ChangesRequest *Review  `json:"changes_request,omitempty"`
	Comment        *Comment `json:"comment,omitempty"`
}

https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Pull-request-events https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Common-entities-for-event-payloads

type Reference

type Reference struct {
	Branch     Branch     `json:"branch"`
	Commit     Commit     `json:"commit"`
	Repository Repository `json:"repository"`
}

type Repository

type Repository struct {
	FullName string `json:"full_name"`
	Name     string `json:"name"`
	UUID     string `json:"uuid"`

	SCM       string `json:"scm,omitempty"`
	IsPrivate bool   `json:"is_private,omitempty"`
	Website   string `json:"website,omitempty"`

	Workspace *Workspace `json:"workspace,omitempty"`
	Project   *Project   `json:"project,omitempty"`
	Owner     *Account   `json:"owner,omitempty"`

	Links map[string]Link `json:"links"`
}

type RepositoryEvent

type RepositoryEvent struct {
	Type string `json:"type"` // Populated and used only in RevChat.

	Repository Repository `json:"repository"`
	Actor      Account    `json:"actor"`

	Commit       *Commit       `json:"commit,omitempty"`
	Comment      *Comment      `json:"comment,omitempty"`
	CommitStatus *CommitStatus `json:"commit_status,omitempty"`
}

https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Repository-events

type Review

type Review struct {
	Date string  `json:"date"`
	User Account `json:"user"`
}

type Workspace

type Workspace struct {
	Slug string `json:"slug"`
	Name string `json:"name"`
	UUID string `json:"uuid"`

	Links map[string]Link `json:"links"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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