Help us shape the future of Go! Take the 2026 Go Developer Survey

bitbucket

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package bitbucket is the Bitbucket Cloud provider. Bitbucket has no gh- or glab-like CLI that runs on every platform, so it calls the 2.0 REST API directly.

Index

Constants

View Source
const (
	// Host is Bitbucket Cloud's git host.
	Host = "bitbucket.org"
	// DefaultBaseURL is Bitbucket Cloud's API root.
	DefaultBaseURL = "https://api.bitbucket.org/2.0"
)

Variables

View Source
var Info = protocol.Info{
	Name:         "bitbucket",
	Terms:        protocol.Terms{Short: "PR", Long: "pull request"},
	BlockStyle:   protocol.BlockLinkRef,
	MergeMethods: []string{protocol.MethodMerge, protocol.MethodSquash, protocol.MethodRebase},
}

Info describes the Bitbucket provider. Bitbucket has no short syntax for pull requests in Markdown (#12 links an issue), so CRs are linked by URL, and it may escape raw HTML, so the block hides in link references.

Functions

func ExecGitCredential

func ExecGitCredential(host string) (string, string, error)

ExecGitCredential runs `git credential fill`, never prompting: with no stored credential, git would otherwise ask through GIT_ASKPASS (an editor's askpass, say) or Git Credential Manager would open a login window.

func Plugin

func Plugin(opts Options) protocol.Plugin

Plugin is the Bitbucket Cloud provider plugin, for protocol.Serve. It has no Detect: bitbucket.org is a known host, and Data Center is not supported.

func ToCR

func ToCR(p *PR) *protocol.CR

ToCR converts a Bitbucket pull request. HeadSHA is Bitbucket's abbreviated (12 character) hash.

Types

type Auth

type Auth func(req *http.Request)

Auth adds credentials to a request.

func Credentials

func Credentials(getenv func(string) string, git GitCredential) (Auth, error)

Credentials picks the first credential available, in order: BITBUCKET_TOKEN (Bearer), BITBUCKET_EMAIL with BITBUCKET_API_TOKEN (Basic), then git's credential helpers for bitbucket.org (Basic, or Bearer for an access token stored under git's x-token-auth user).

type Client

type Client struct {
	HTTP      *http.Client
	BaseURL   string
	Auth      Auth
	Workspace string
	Slug      string
}

Client makes Bitbucket API calls for one repository.

func (*Client) GetPR

func (c *Client) GetPR(id int) (*PR, error)

GetPR fetches a pull request.

func (*Client) ListPRs

func (c *Client) ListPRs(q string, first bool, states ...string) ([]*PR, error)

ListPRs returns the pull requests in one of states matching the BBQL query q, newest first. Bitbucket returns only open pull requests unless states are given; a state condition in q does not widen that.

type Endpoint

type Endpoint struct {
	Branch struct {
		Name string `json:"name"`
	} `json:"branch"`
	Commit struct {
		Hash string `json:"hash"`
	} `json:"commit"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

Endpoint is the source or destination of a pull request.

type GitCredential

type GitCredential func(host string) (user, password string, err error)

GitCredential asks git's credential helpers for the credential of an https host, as `git credential fill` does.

type Options

type Options struct {
	BaseURL       string
	HTTP          *http.Client
	Getenv        func(string) string
	GitCredential GitCredential
	// Sleep waits between polls of an asynchronous merge.
	Sleep func(time.Duration)
}

Options configures the plugin; the zero value talks to Bitbucket Cloud with credentials from the environment or git.

type PR

type PR struct {
	ID          int        `json:"id"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	State       string     `json:"state"` // OPEN, MERGED, DECLINED, SUPERSEDED
	Draft       bool       `json:"draft"`
	Source      Endpoint   `json:"source"`
	Destination Endpoint   `json:"destination"`
	Reviewers   []Reviewer `json:"reviewers"`
	// CloseSourceBranch is the "delete branch after merging" option.
	CloseSourceBranch bool `json:"close_source_branch"`
	Links             struct {
		HTML struct {
			Href string `json:"href"`
		} `json:"html"`
	} `json:"links"`
}

PR is the subset of a Bitbucket pull request that git-stack uses.

type Provider

type Provider struct {
	C *Client
	// contains filtered or unexported fields
}

Provider adapts Client to protocol.Provider.

func (*Provider) CancelAutoMerge

func (p *Provider) CancelAutoMerge(int) error

CancelAutoMerge does nothing: Bitbucket Cloud has no auto-merge to cancel.

func (*Provider) CreateCR

func (p *Provider) CreateCR(n protocol.NewCR) (*protocol.CR, error)

CreateCR opens a pull request.

func (*Provider) FindCRForBranch

func (p *Provider) FindCRForBranch(branch string) (*protocol.CR, error)

FindCRForBranch returns the open PR whose head is branch, else the most recently merged one, else nil. PRs from forks are ignored.

func (*Provider) GetBranch

func (p *Provider) GetBranch(name string) (*protocol.Branch, error)

GetBranch reports whether name is the main branch, and whether a branch restriction guards it. Reading restrictions needs admin rights; without them the branch counts as unprotected.

func (*Provider) GetCR

func (p *Provider) GetCR(n int) (*protocol.CR, error)

GetCR fetches a pull request.

func (*Provider) GetRepo

func (p *Provider) GetRepo() (*protocol.RepoSettings, error)

GetRepo returns the main branch's default merge strategy.

func (*Provider) ListCRsTargeting

func (p *Provider) ListCRsTargeting(branch string) ([]*protocol.CR, error)

ListCRsTargeting returns open PRs, not from forks, whose base is branch.

func (*Provider) MarkReady

func (p *Provider) MarkReady(n int) (*protocol.CR, error)

MarkReady takes a pull request out of draft.

func (*Provider) Merge

func (p *Provider) Merge(n int, method, sha string) (*protocol.CR, error)

Merge merges the pull request at once. Bitbucket cannot pin the head commit, so the PR is checked to be at sha first. A merge that Bitbucket runs asynchronously is waited for.

func (*Provider) SearchCRs

func (p *Provider) SearchCRs(text string) ([]*protocol.CR, error)

SearchCRs returns open PRs whose description contains text. BBQL's ~ is case-insensitive, so matches are checked again here.

func (*Provider) SyncStack

func (p *Provider) SyncStack([]int) error

SyncStack is a no-op: Bitbucket has no stack object; the description block is the stack.

func (*Provider) Unstack

func (p *Provider) Unstack([]int) error

Unstack is a no-op, like SyncStack.

func (*Provider) UpdateCR

func (p *Provider) UpdateCR(n int, u protocol.Update) (*protocol.CR, error)

UpdateCR changes the base, title or description.

type Reviewer

type Reviewer struct {
	UUID string `json:"uuid"`
}

Reviewer is a pull request reviewer.

Jump to

Keyboard shortcuts

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