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
- Variables
- func ExecGitCredential(host string) (string, string, error)
- func Plugin(opts Options) protocol.Plugin
- func ToCR(p *PR) *protocol.CR
- type Auth
- type Client
- type Endpoint
- type GitCredential
- type Options
- type PR
- type Provider
- func (p *Provider) CancelAutoMerge(int) error
- func (p *Provider) CreateCR(n protocol.NewCR) (*protocol.CR, error)
- func (p *Provider) FindCRForBranch(branch string) (*protocol.CR, error)
- func (p *Provider) GetBranch(name string) (*protocol.Branch, error)
- func (p *Provider) GetCR(n int) (*protocol.CR, error)
- func (p *Provider) GetRepo() (*protocol.RepoSettings, error)
- func (p *Provider) ListCRsTargeting(branch string) ([]*protocol.CR, error)
- func (p *Provider) MarkReady(n int) (*protocol.CR, error)
- func (p *Provider) Merge(n int, method, sha string) (*protocol.CR, error)
- func (p *Provider) SearchCRs(text string) ([]*protocol.CR, error)
- func (p *Provider) SyncStack([]int) error
- func (p *Provider) Unstack([]int) error
- func (p *Provider) UpdateCR(n int, u protocol.Update) (*protocol.CR, error)
- type Reviewer
Constants ¶
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 ¶
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 ¶
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.
Types ¶
type Auth ¶
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 ¶
Client makes Bitbucket API calls for one repository.
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 ¶
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 ¶
CancelAutoMerge does nothing: Bitbucket Cloud has no auto-merge to cancel.
func (*Provider) FindCRForBranch ¶
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 ¶
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) GetRepo ¶
func (p *Provider) GetRepo() (*protocol.RepoSettings, error)
GetRepo returns the main branch's default merge strategy.
func (*Provider) ListCRsTargeting ¶
ListCRsTargeting returns open PRs, not from forks, whose base is branch.
func (*Provider) Merge ¶
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 ¶
SearchCRs returns open PRs whose description contains text. BBQL's ~ is case-insensitive, so matches are checked again here.
func (*Provider) SyncStack ¶
SyncStack is a no-op: Bitbucket has no stack object; the description block is the stack.