bitbucketapp

package
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bitbucketapp implements OAuth2 and the small slice of Bitbucket Cloud's REST API this control plane needs once connected.

Bitbucket Cloud only: no instance URL parameter anywhere in this package, unlike internal/gitlabapp. Bitbucket Server/Data Center has no OAuth-consumer equivalent and is out of scope (docs/design/git-provider-integrations.md section 3); a Data Center repo can still be connected today through the existing generic deploy-token path (PUT /api/v1/apps/{name}/git-source).

Index

Constants

This section is empty.

Variables

View Source
var ErrChangedFilesTruncated = errors.New("bitbucketapp: changed file list is truncated")

ErrChangedFilesTruncated means a change touched more files than the client pages through, so the list is incomplete and must not drive a decision.

Functions

func AuthorizeURL

func AuthorizeURL(clientID, redirectURI, state string) string

AuthorizeURL builds Bitbucket's OAuth2 authorization-code flow entry point: a real browser redirect (GET), the same "the operator's browser must navigate here itself" shape every other provider's own authorize/manifest entry point requires. No scope parameter: unlike GitLab's own AuthorizeURL, Bitbucket OAuth consumers have their permissions configured once on the consumer itself (Repositories: Read, Webhooks: Read and Write), not requested per authorization (the Bitbucket provider design).

Types

type Account

type Account struct {
	ID    string
	Login string
}

Account is the authenticated user behind an access token.

type Branch

type Branch struct {
	Name      string
	CommitSHA string
}

Branch is one branch of one repository.

type BuildStatusState added in v0.2.0

type BuildStatusState string

BuildStatusState is Bitbucket's own documented "state" enum for POST .../commit/{commit}/statuses/build.

const (
	// BuildStatusInProgress marks a build status as still in progress.
	BuildStatusInProgress BuildStatusState = "INPROGRESS"
	// BuildStatusSuccessful marks a build status as succeeded.
	BuildStatusSuccessful BuildStatusState = "SUCCESSFUL"
	// BuildStatusFailed marks a build status as failed.
	BuildStatusFailed BuildStatusState = "FAILED"
)
const BuildStatusStopped BuildStatusState = "STOPPED"

BuildStatusStopped marks a build status as stopped before completing.

type Client

type Client struct {
	HTTP       *http.Client
	TokenURL   string
	APIBaseURL string
}

Client is a small, purpose-built Bitbucket Cloud REST/OAuth client, not a general-purpose Bitbucket SDK. TokenURL/APIBaseURL are overridable, the same "tests point this at an httptest.Server" pattern internal/githubapp.Client's own BaseURL field establishes: production code always leaves them empty and gets the real Bitbucket Cloud hosts.

func NewClient

func NewClient() *Client

NewClient returns a Client with a bounded per-request timeout, the same reasoning internal/githubapp.NewClient's own doc comment gives.

func (*Client) CompareChangedFiles added in v0.2.0

func (c *Client) CompareChangedFiles(ctx context.Context, accessToken, fullName, head, base string) ([]string, error)

CompareChangedFiles lists the files that differ between head and base.

func (*Client) CreateCommitBuildStatus added in v0.2.0

func (c *Client) CreateCommitBuildStatus(ctx context.Context, accessToken, fullName, commit string, state BuildStatusState, targetURL, description, key string) error

CreateCommitBuildStatus sets a build status on commit of fullName ("workspace/repo_slug"), authenticated the same way CreatePullRequestComment is. key identifies this status distinctly from any other build system posting to the same commit (support.atlassian.com/bitbucket-cloud/docs/build-status-for-commits), the same role GitHub's own "context" plays; repeat calls with the same key update the existing status rather than adding a new one.

func (*Client) CreatePullRequestComment added in v0.2.0

func (c *Client) CreatePullRequestComment(ctx context.Context, accessToken, fullName string, prID int, body string) (int64, error)

CreatePullRequestComment posts a new comment on pull request prID of fullName ("workspace/repo_slug") and returns its ID.

func (*Client) CreateRepoWebhook

func (c *Client) CreateRepoWebhook(ctx context.Context, accessToken, fullName, hookURL, secret string) error

CreateRepoWebhook registers a repo:push and pullrequest:* webhook on fullName ("workspace/repo_slug") pointed at hookURL, with secret set as the value Bitbucket signs each delivery's X-Hub-Signature header with (HMAC-SHA256, the same header name GitHub uses for its own SHA-1 predecessor, see internal/api/git_webhook.go's own verification branch for the distinction). Each pull request event key must be requested explicitly: without them Bitbucket never delivers the events internal/webhook's Bitbucket pull-request parsing expects, so preview environments would silently never trigger for a connected repo.

func (*Client) CurrentUser

func (c *Client) CurrentUser(ctx context.Context, accessToken string) (Account, error)

CurrentUser returns the user an access token belongs to. It needs the account scope on the OAuth consumer.

func (*Client) ExchangeCode

func (c *Client) ExchangeCode(ctx context.Context, key, secret, code string) (Tokens, error)

ExchangeCode exchanges an OAuth authorization code for an access token.

func (*Client) GetRepo

func (c *Client) GetRepo(ctx context.Context, accessToken, fullName string) (Repo, error)

GetRepo looks up a single repository by its "workspace/repo_slug" full name.

func (*Client) ListBranches

func (c *Client) ListBranches(ctx context.Context, accessToken, fullName string) ([]Branch, error)

ListBranches lists every branch of fullName ("workspace/repo_slug"), the same cursor-pagination shape ListRepos follows.

func (*Client) ListPullRequestComments added in v0.2.0

func (c *Client) ListPullRequestComments(ctx context.Context, accessToken, fullName string, prID int) ([]gitprovider.Comment, error)

ListPullRequestComments returns the comments of pull request prID, following Bitbucket's own next links up to gitprovider.MaxCommentPages pages.

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context, accessToken string, opts gitprovider.ListOptions) ([]Repo, gitprovider.ListResult, error)

ListRepos lists repositories the token's account is at least a member of. Bitbucket paginates by an opaque "next" URL in the response body: each iteration follows it until it is absent or the MaxItems cap is hit.

func (*Client) PullRequestChangedFiles added in v0.2.0

func (c *Client) PullRequestChangedFiles(ctx context.Context, accessToken, fullName string, prID int) ([]string, error)

PullRequestChangedFiles lists the files changed by pull request prID.

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context, key, secret, refreshToken string) (Tokens, error)

RefreshToken exchanges a still-valid refresh token for a new access token.

func (*Client) UpdatePullRequestComment added in v0.2.0

func (c *Client) UpdatePullRequestComment(ctx context.Context, accessToken, fullName string, prID int, commentID int64, body string) error

UpdatePullRequestComment replaces the body of an existing comment.

type Repo

type Repo struct {
	FullName      string
	Name          string
	Private       bool
	DefaultBranch string
	CloneURL      string
	WebURL        string
	Fork          bool
}

Repo is one Bitbucket repository accessible to the connected account, the subset of Bitbucket's Repository object this control plane's repo picker and "use as source" action need. FullName ("workspace/repo_slug") is the identifier callers pass back to GetRepo/ListBranches/ CreateWebhook: Bitbucket has no separate numeric ID in the sense GitLab's Project.ID is used here.

type Tokens

type Tokens struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
}

Tokens is ExchangeCode's and RefreshToken's shared result.

Jump to

Keyboard shortcuts

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