backend

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("not found")
	ErrAuth              = errors.New("authentication required")
	ErrPermission        = errors.New("permission denied")
	ErrUnsupportedOnHost = errors.New("operation unsupported on this host")
	ErrConflict          = errors.New("conflict")
	ErrTransport         = errors.New("transport error")
)

Sentinel errors describing the bounded set of domain-level failure modes. Adapters classify wire errors into one of these so commands and the MCP surface can branch deterministically via errors.Is.

AllCodes lists every published ErrorCode. The errfmt test suite iterates this slice and asserts each code has a catalogue entry, so adding a new constant above without a matching errfmt entry fails the build.

When adding a new code:

  1. Append it to the const block above.
  2. Append it here.
  3. Add the matching catalogue entry in pkg/errfmt/errfmt.go.

Functions

func DefaultBranch added in v1.8.0

func DefaultBranch(bl BranchLister, ns, slug string) (string, error)

DefaultBranch resolves a repository's default branch by inspecting the IsDefault flag on its branch list. It returns "" with no error when no branch in the list is marked default (e.g. on Bitbucket Cloud, whose branch endpoint omits IsDefault), so callers can fall back to local git state or another heuristic.

Errors from the underlying ListBranches call are propagated unchanged so no command silently masks them with a literal "main".

func StampCode added in v1.19.0

func StampCode(err error, code ErrorCode, resource, id, feature string) error

StampCode is an adapter convenience: when err is a *DomainError, sets the fields on a copy and returns the copy as an error; otherwise returns err unchanged. This lets call sites annotate post-classification errors with operation-specific codes (e.g. pr.merge.conflict vs the bare ErrConflict kind) without per-call boilerplate.

Empty arguments are skipped so a caller can stamp only Code while leaving Resource/ID/Feature alone, or fill in just Resource+ID for a not-found path.

The returned error preserves Kind, Host, Cause, and Message — only the specified fields are overwritten.

Types

type AddPRCommentInput added in v1.6.0

type AddPRCommentInput struct {
	Text string
}

AddPRCommentInput carries the parameters for adding a comment to a PR.

type AppProperties

type AppProperties struct {
	Version     string
	BuildNumber string
	DisplayName string
}

AppProperties holds Bitbucket server version metadata.

type Branch

type Branch struct {
	Name       string
	IsDefault  bool
	LatestHash string
}

Branch is the domain representation of a repository branch.

type BranchCreator

type BranchCreator interface {
	CreateBranch(ns, slug string, in CreateBranchInput) (Branch, error)
}

type BranchDeleter

type BranchDeleter interface {
	DeleteBranch(ns, slug, branch string) error
}

type BranchLister

type BranchLister interface {
	ListBranches(ns, slug string, limit int) ([]Branch, error)
}

type BranchProtection added in v1.17.0

type BranchProtection struct {
	ID          int
	Type        string
	MatcherID   string
	MatcherKind string
	Users       []string
	Groups      []string
}

BranchProtection is a single branch-restriction record on Bitbucket Server / Data Center. Cloud has a similar concept under a different, non-trivial wire shape that we don't model yet — BranchProtection is surfaced only via the BranchProtector optional interface.

Type values match BBS exactly (lowercased, dash-separated):

read-only           — disallow all writes
no-deletes          — disallow branch deletion
fast-forward-only   — disallow non-fast-forward writes
pull-request-only   — only PR merges may write

MatcherKind is the BBS matcher type id ("BRANCH", "PATTERN", "MODEL_BRANCH", "MODEL_CATEGORY") and MatcherID is the corresponding value (a branch name, glob, or model id). Users / Groups list slugs that are exempted from the restriction.

type BranchProtector added in v1.17.0

type BranchProtector interface {
	ListBranchProtections(ns, slug string, limit int) ([]BranchProtection, error)
	CreateBranchProtection(ns, slug string, in CreateBranchProtectionInput) (BranchProtection, error)
	DeleteBranchProtection(ns, slug string, id int) error
}

BranchProtector exposes branch-restriction management on Bitbucket Server / Data Center. The Cloud backend has a different "branch restrictions" shape that's not modelled here — calls against a Cloud client surface ErrUnsupportedOnHost via AsBranchProtector.

func AsBranchProtector added in v1.17.0

func AsBranchProtector(c Client, host string) (BranchProtector, error)

AsBranchProtector returns the BranchProtector view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) when called against a backend that doesn't model branch protections (currently Cloud).

type CodeSearchHit added in v1.21.0

type CodeSearchHit struct {
	Repository        string
	Path              string
	PathMatches       []SearchSegment
	ContentMatches    []ContentMatch
	ContentMatchCount int
	FileURL           string
}

CodeSearchHit is one result row from Bitbucket Cloud's workspace-scoped code search. The hit may match on the file path (PathMatches non-empty), on file content (ContentMatches non-empty), or both. Renderers use the SearchSegment.Match flag to bold the matched runs.

Repository is "workspace/slug" — the Cloud "full_name" form, kept verbatim so JSON consumers can split it themselves and the table renderer needs no extra column.

type CodeSearcher added in v1.21.0

type CodeSearcher interface {
	SearchCode(workspace, query string, limit int) ([]CodeSearchHit, error)
}

CodeSearcher performs workspace-scoped code search on Bitbucket Cloud. Bitbucket Server / Data Center does not expose a first-class REST code- search endpoint (search there is provided by the separate Sourcegraph integration or third-party plugins), so the entire surface is gated behind AsCodeSearcher. Server adapters intentionally do NOT implement this interface — the type-assertion in AsCodeSearcher is what surfaces the typed host.unsupported error to callers.

func AsCodeSearcher added in v1.21.0

func AsCodeSearcher(c Client, host string) (CodeSearcher, error)

AsCodeSearcher returns the CodeSearcher view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) when called against a backend that doesn't model code search (currently Server/DC).

type Commit

type Commit struct {
	Hash      string
	Message   string // subject line only (first line of commit message)
	Author    User
	Timestamp time.Time
	WebURL    string
}

Commit is the domain representation of a single repository commit.

type CommitLister

type CommitLister interface {
	ListCommits(ns, slug, branch string, limit int) ([]Commit, error)
}

type CommitReader

type CommitReader interface {
	GetCommit(ns, slug, hash string) (Commit, error)
}

type CommitStatus added in v1.6.0

type CommitStatus struct {
	Key         string
	State       string // SUCCESSFUL | FAILED | INPROGRESS | STOPPED
	Name        string
	Description string
	URL         string
}

CommitStatus is a build / CI status reported against a commit hash.

type CommitStatusLister added in v1.6.0

type CommitStatusLister interface {
	ListCommitStatuses(ns, slug, hash string) ([]CommitStatus, error)
}

type ContentMatch added in v1.21.0

type ContentMatch struct {
	Line     int
	Segments []SearchSegment
}

ContentMatch is a single matched line within a file: the 1-based line number plus a sequence of segments. Cloud groups consecutive matched lines into "content_matches" objects each with a "lines" array; bitbottle flattens those to a single ContentMatch slice in arrival order.

type Context added in v1.21.0

type Context struct {
	Host          string      `json:"host"`
	Project       string      `json:"project"`
	Slug          string      `json:"slug"`
	Branch        string      `json:"branch"`
	DefaultBranch string      `json:"default_branch"`
	Ahead         *int        `json:"ahead,omitempty"`
	Behind        *int        `json:"behind,omitempty"`
	User          ContextUser `json:"user"`
	Backend       string      `json:"backend"`
}

Context is the one-call orientation primitive returned by `bitbottle context` and the MCP `get_context` tool. It collapses three previously independent calls (auth status / repo view / git status) into a single structured response so AI agents can orient themselves in one round-trip.

Zero-valued Project / Slug / Branch / DefaultBranch indicate "outside a git repo" — the rest of the shape (Host, User, Backend) still resolves through config + the backend's current-user endpoint.

Ahead and Behind are *int with omitempty so that "unknown" (git failed, no upstream, base ref missing, outside a repo) is encoded as the keys being absent from JSON — never as 0/0, which would lie to agents that would otherwise conclude "in sync". Both pointers are populated as a pair: either both non-nil, or both nil.

Backend is the literal "cloud" or "server" string matching the bbinstance backend-type vocabulary, so consumers can branch on host shape without re-deriving it.

User is a Context-local shape with JSON tags so the public contract emits {"slug": ..., "display_name": ...} without bleeding tags onto backend.User (which is reused across many wire surfaces and would regress existing JSON outputs if tagged here).

type ContextUser added in v1.21.0

type ContextUser struct {
	Slug        string `json:"slug"`
	DisplayName string `json:"display_name"`
}

ContextUser is the user shape carried inside Context. It mirrors User but stamps explicit JSON tags so the documented contract is stable (`{"slug": ..., "display_name": ...}`) regardless of how backend.User is later reshaped.

type CreateBranchInput

type CreateBranchInput struct {
	Name    string
	StartAt string // branch name or commit hash
}

CreateBranchInput carries the parameters for creating a branch.

type CreateBranchProtectionInput added in v1.17.0

type CreateBranchProtectionInput struct {
	Type        string
	MatcherID   string
	MatcherKind string
	Users       []string
	Groups      []string
}

CreateBranchProtectionInput carries the parameters for adding a branch-restriction. All fields except Type and MatcherID are optional. MatcherKind defaults to "BRANCH" when empty (the most common case).

type CreateIssueInput added in v1.17.0

type CreateIssueInput struct {
	Title    string
	Content  string
	Kind     string
	Priority string
}

CreateIssueInput carries the parameters for opening a new issue. Bitbucket Cloud applies sane defaults (kind=bug, priority=major) when fields are empty, so callers can omit everything but Title.

type CreatePRInput

type CreatePRInput struct {
	Title       string
	Description string
	Draft       bool
	FromBranch  string
	ToBranch    string
	Reviewers   []string
}

CreatePRInput carries the parameters for creating a pull request.

Reviewers are user slugs (Server) or usernames / account IDs (Cloud). Both adapters serialise the same logical list into their backend's wire shape. A nil or empty slice creates a PR with no reviewers — Bitbucket does NOT auto-apply repo "default reviewers" on the create endpoint, so callers that want that behaviour must fetch them via DefaultReviewersResolver and merge the result here.

type CreateRepoInput

type CreateRepoInput struct {
	Name        string
	SCM         string
	Public      bool
	Description string
}

CreateRepoInput carries the parameters for creating a repository.

type CreateTagInput

type CreateTagInput struct {
	Name    string
	StartAt string // branch name or commit hash
	Message string // empty = lightweight tag; non-empty = annotated tag
}

CreateTagInput carries the parameters for creating a tag.

type CreateWebhookInput added in v1.15.0

type CreateWebhookInput struct {
	URL    string
	Events []string
	Active bool
	Secret string
}

CreateWebhookInput carries the parameters for creating a webhook. Secret is write-only — neither backend returns it on read.

type DefaultReviewersResolver added in v1.17.0

type DefaultReviewersResolver interface {
	DefaultReviewers(ns, slug, fromBranch, toBranch string) ([]User, error)
}

DefaultReviewersResolver looks up the configured "default reviewers" for a repository given a source/target ref pair. Only Bitbucket Server / Data Center exposes this — Cloud has a similar feature with a different, non-trivial wire shape that we don't model yet.

Implementations may need additional context (e.g. numeric repo ID) which they obtain themselves; callers pass only the values they natively know.

func AsDefaultReviewersResolver added in v1.17.0

func AsDefaultReviewersResolver(c Client, host string) (DefaultReviewersResolver, error)

AsDefaultReviewersResolver returns the DefaultReviewersResolver view of c, or a typed *DomainError when the backend doesn't implement it (currently Cloud). Callers use the returned error to decide whether to skip the auto-apply step entirely.

type DomainError added in v1.8.0

type DomainError struct {
	Kind     error
	Code     ErrorCode
	Host     string
	Feature  string
	Resource string
	ID       string
	Message  string
	Cause    error
}

DomainError wraps an underlying cause with structured context for renderers (CLI plain-text, MCP structured payload). Kind is one of the package-level sentinels; errors.Is(err, backend.ErrXxx) walks Kind, enabling deterministic branching without parsing prose.

Optional fields populated when known:

  • Host: the hostname the request was directed at
  • Feature: capability name, populated for ErrUnsupportedOnHost
  • Resource: domain kind ("pull-request", "branch", "repository", ...)
  • ID: resource identifier ("42", "feat/x", "ws/repo", ...)
  • Code: dotted ErrorCode token used by errfmt to look up the user-facing title + hint. Auto-attached for HTTP 401 by ClassifyHTTPError; otherwise stamped by adapters at the call site (where they have op-specific context). May be empty — Render then falls back to a Kind-based humanisation.

func ClassifyHTTPError added in v1.8.0

func ClassifyHTTPError(host string, err *HTTPError) *DomainError

ClassifyHTTPError translates an HTTPError into a DomainError, picking a Kind sentinel from the response status code. Statuses outside the bounded domain set leave Kind unset; the original HTTPError is preserved as Cause in every case so adapters can attach further context (resource, ID, etc.).

Only HTTP 401 receives an automatic Code (CodeAuthInvalidToken) — re-login is an unambiguous remedy that does not need adapter context. 403/404/409 each map to multiple user-facing situations (which resource? which write op?) and so the adapter that issued the request stamps the appropriate Code at the call site, where the necessary context lives.

func ClassifyTransportError added in v1.19.0

func ClassifyTransportError(host string, err error) *DomainError

ClassifyTransportError translates a transport-level error (one that failed before an HTTP response existed — TLS handshake failure, DNS resolution timeout, dial timeout, read timeout, etc.) into a DomainError carrying a network-cluster ErrorCode. host is attached so the renderer can name which Bitbucket instance produced the failure.

Returns nil if err is nil, or if err is not a recognised transport failure shape — callers should treat the original error as untranslated and either return it as-is or fall through to a generic renderer. The intent is "do no harm": never mis-label an error.

Recognised shapes:

  • x509.UnknownAuthorityError (anywhere in the unwrap chain) → CodeNetworkTLSUnknownAuthority. Triggered by self-signed CAs; the catalogue hints at -k / skip_tls_verify.
  • context.DeadlineExceeded (anywhere in the unwrap chain) → CodeTransportTimeout. Triggered by per-request deadlines.
  • any net.Error whose Timeout() returns true → CodeTransportTimeout. Covers dial timeouts and read timeouts surfaced as *net.OpError.

Kind is set to ErrTransport in every classified case so callers can branch on errors.Is(err, backend.ErrTransport).

func (*DomainError) Error added in v1.8.0

func (e *DomainError) Error() string

Error renders a single-line human-readable form. Structured emission (e.g. MCP) should read the fields directly rather than parsing this string.

func (*DomainError) HTTPStatus added in v1.19.0

func (e *DomainError) HTTPStatus() int

HTTPStatus returns the HTTP status code that produced this DomainError, or 0 if the underlying cause is not an *HTTPError. Useful for adapters that need to refine call-site Code stamping based on status (e.g. 404 → not found, 409 → conflict). Walks the unwrap chain via errors.As.

func (*DomainError) Is added in v1.8.0

func (e *DomainError) Is(target error) bool

Is matches against the Kind sentinel. The wrapped Cause is reached via Unwrap by errors.Is's default walk — intentionally not duplicated here.

func (*DomainError) Unwrap added in v1.8.0

func (e *DomainError) Unwrap() error

Unwrap exposes the underlying cause for errors.Is / errors.As walks.

type ErrorCode added in v1.18.0

type ErrorCode string

ErrorCode is a stable, dotted token identifying a specific user-visible failure mode (e.g. "auth.invalid_token"). Codes are the join key between the API layer (which classifies wire errors) and the errfmt renderer (which looks up titles + hints). Treat them as part of the public API: add new codes freely, never repurpose existing ones.

const (
	// auth cluster — credentials missing, expired, or insufficient
	CodeAuthNoToken       ErrorCode = "auth.no_token"
	CodeAuthInvalidToken  ErrorCode = "auth.invalid_token"
	CodePermWriteRequired ErrorCode = "perm.write_required"

	// repo cluster — repository-shaped failures
	CodeRepoNotFound ErrorCode = "repo.not_found"

	// pr cluster — pull-request lifecycle failures
	CodePRNotFound              ErrorCode = "pr.not_found"
	CodePRMergeConflict         ErrorCode = "pr.merge.conflict"
	CodePRMergeBehind           ErrorCode = "pr.merge.behind"
	CodePRCreateDuplicateBranch ErrorCode = "pr.create.duplicate_branch"
	CodePRReviewerUnknown       ErrorCode = "pr.reviewer.unknown"

	// branch cluster — branch-protection / write-side failures
	CodeBranchProtected ErrorCode = "branch.protected"

	// host cluster — feature unavailable on the targeted Bitbucket flavour
	CodeHostUnsupported ErrorCode = "host.unsupported"

	// network cluster — pre-classify codes attached at the transport
	// layer before an HTTPError exists. ClassifyTransportError stamps
	// these.
	CodeNetworkTLSUnknownAuthority ErrorCode = "network.tls_unknown_authority"
	CodeTransportTimeout           ErrorCode = "transport.timeout"
)

Catalogue of error codes. Group by cluster prefix; keep alphabetical inside each cluster. errfmt has a matching catalogue of titles + hints.

type Feature added in v1.8.0

type Feature string

Feature names a capability that some backends may not implement. The registry maps each Feature to the optional interface a Client must satisfy to expose that capability.

const (
	FeaturePipelines Feature = "pipelines"
	FeatureRepoFork  Feature = "repo-fork"
)
const FeatureBranchProtect Feature = "branch-protect"

FeatureBranchProtect names the branch-protection capability for typed- error reporting.

const FeatureCodeSearch Feature = "code-search"

FeatureCodeSearch names the code-search capability for typed-error reporting.

const FeatureDefaultReviewers Feature = "default-reviewers"

FeatureDefaultReviewers names the default-reviewers capability for typed-error reporting.

const FeatureIssues Feature = "issues"

FeatureIssues names the issues capability for typed-error reporting.

const FeaturePRReopen Feature = "pr-reopen"

FeaturePRReopen names the PR-reopen capability for typed-error reporting. Bitbucket Cloud has no reopen primitive (BCLOUD-23807), so callers gate the feature behind AsPRReopener.

const FeatureWorkspaces Feature = "workspaces"

FeatureWorkspaces names the workspace/project listing capability for typed-error reporting.

type ForkRepoInput added in v1.16.0

type ForkRepoInput struct {
	Workspace string
	Name      string
}

ForkRepoInput carries the parameters for forking a Bitbucket Cloud repository. Workspace is required (the fork's destination workspace). Name is optional — when empty, Bitbucket Cloud reuses the source name.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
	RequestURL string
}

HTTPError represents an error HTTP response from the Bitbucket API.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error implements the error interface.

type Issue added in v1.17.0

type Issue struct {
	ID        int
	Title     string
	State     string // new, open, on hold, resolved, duplicate, invalid, wontfix, closed
	Kind      string // bug, enhancement, proposal, task
	Priority  string // trivial, minor, major, critical, blocker
	Reporter  User
	Assignee  *User // nil when unassigned
	CreatedOn time.Time
	UpdatedOn time.Time
	WebURL    string
	Content   string // raw markdown body
}

Issue is a Bitbucket Cloud issue. Issues are a Cloud-only feature gated by per-repository "issue tracker" enablement; the API returns 404 on repositories where the tracker is disabled. We surface that as the adapter's standard ErrNotFound.

Assignee is a pointer so the zero value cleanly distinguishes "unassigned" from "assigned to user with empty username". Reporter is always present on Cloud and uses the value type.

type IssueClient added in v1.17.0

type IssueClient interface {
	ListIssues(ns, slug, state string, limit int) ([]Issue, error)
	GetIssue(ns, slug string, id int) (Issue, error)
	CreateIssue(ns, slug string, in CreateIssueInput) (Issue, error)
	UpdateIssue(ns, slug string, id int, in UpdateIssueInput) (Issue, error)
}

IssueClient is implemented only by Bitbucket Cloud clients. Bitbucket Server / Data Center has no built-in issue tracker, so the entire issue surface is gated behind AsIssueClient.

func AsIssueClient added in v1.17.0

func AsIssueClient(c Client, host string) (IssueClient, error)

AsIssueClient returns the IssueClient view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) when called against a Server/DC backend.

type MergePRInput

type MergePRInput struct {
	Message  string
	Strategy string
}

MergePRInput carries the parameters for merging a pull request.

type Options added in v1.1.1

type Options struct {
	Token         string
	SkipTLSVerify bool
	// Email is the Atlassian account email address used as the HTTP Basic auth
	// identity for Bitbucket Cloud when authenticating with an Atlassian API
	// token. Leave empty when using a Bearer / OAuth2 token.
	Email string
	// Username is the Bitbucket Server/DC username used as the HTTP Basic auth
	// identity. Not used for Bitbucket Cloud.
	Username string
}

Options overrides the stored config when constructing a backend client. Used by auth login to validate a new token before it is persisted.

type PRApprover

type PRApprover interface {
	ApprovePR(ns, slug string, id int) error
}

type PRChangesRequester

type PRChangesRequester interface {
	RequestChangesPR(ns, slug string, id int) error
}

PRChangesRequester can request changes on a pull request (Cloud only). Access via type assertion — not embedded in Client.

type PRComment added in v1.6.0

type PRComment struct {
	ID        int
	Author    User
	Text      string
	CreatedAt time.Time
}

PRComment is the domain representation of a general comment on a pull request.

type PRCommentAdder added in v1.6.0

type PRCommentAdder interface {
	AddPRComment(ns, slug string, id int, in AddPRCommentInput) (PRComment, error)
}

type PRCommentLister added in v1.6.0

type PRCommentLister interface {
	ListPRComments(ns, slug string, id int) ([]PRComment, error)
}

type PRCreator

type PRCreator interface {
	CreatePR(ns, slug string, in CreatePRInput) (PullRequest, error)
}

type PRDecliner

type PRDecliner interface {
	DeclinePR(ns, slug string, id int) error
}

type PRDiffer

type PRDiffer interface {
	GetPRDiff(ns, slug string, id int) (string, error)
}

type PREditor

type PREditor interface {
	UpdatePR(ns, slug string, id int, in UpdatePRInput) (PullRequest, error)
}

type PRLister

type PRLister interface {
	ListPRs(ns, slug, state string, limit int) ([]PullRequest, error)
}

type PRMerger

type PRMerger interface {
	MergePR(ns, slug string, id int, in MergePRInput) (PullRequest, error)
}

type PRReader

type PRReader interface {
	GetPR(ns, slug string, id int) (PullRequest, error)
}

type PRReadier

type PRReadier interface {
	ReadyPR(ns, slug string, id int) error
}

type PRReopener added in v1.21.0

type PRReopener interface {
	ReopenPR(ns, slug string, id int) error
}

PRReopener reverses a decline. Implemented only by Bitbucket Server / Data Center (POST /pull-requests/{id}/reopen). Bitbucket Cloud has no reopen primitive — declined PRs are terminal there (BCLOUD-23807) — so callers route through AsPRReopener so the Cloud-only constraint surfaces as a typed ErrUnsupportedOnHost rather than a panic.

func AsPRReopener added in v1.21.0

func AsPRReopener(c Client, host string) (PRReopener, error)

AsPRReopener returns the PRReopener view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) when the backend at host has no reopen primitive (currently Bitbucket Cloud).

type PRReviewRequester

type PRReviewRequester interface {
	RequestReview(ns, slug string, id int, users []string) error
}

type PRUnapprover

type PRUnapprover interface {
	UnapprovePR(ns, slug string, id int) error
}

type Pipeline

type Pipeline struct {
	UUID        string
	BuildNumber int
	State       string // PENDING, IN_PROGRESS, SUCCESSFUL, FAILED, ERROR, STOPPED
	RefType     string // "branch", "tag", "commit"
	RefName     string
	CreatedOn   string
	Duration    int // seconds
	WebURL      string
}

Pipeline is the domain representation of a Bitbucket Cloud pipeline run.

type PipelineClient

type PipelineClient interface {
	ListPipelines(ns, slug string, limit int) ([]Pipeline, error)
	GetPipeline(ns, slug, uuid string) (Pipeline, error)
	RunPipeline(ns, slug string, in RunPipelineInput) (Pipeline, error)
	ListPipelineSteps(ns, slug, uuid string) ([]PipelineStep, error)
	GetPipelineStepLog(ns, slug, pipelineUUID, stepUUID string) (io.ReadCloser, error)
	ListPipelineVariables(ns, slug string) ([]PipelineVariable, error)
	SetPipelineVariable(ns, slug string, in PipelineVariableInput) (PipelineVariable, error)
	DeletePipelineVariable(ns, slug, key string) error
}

PipelineClient is implemented only by Bitbucket Cloud clients.

func AsPipelineClient

func AsPipelineClient(c Client, host string) (PipelineClient, error)

AsPipelineClient returns the PipelineClient view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) if the backend at host does not implement the Pipelines capability.

type PipelineStep added in v1.15.0

type PipelineStep struct {
	UUID     string
	Name     string
	State    string // PENDING, IN_PROGRESS, SUCCESSFUL, FAILED, ERROR, STOPPED
	Result   string // populated when State has flattened from COMPLETED
	Duration int    // seconds
}

PipelineStep is the domain representation of a single step within a Bitbucket Cloud pipeline run.

type PipelineVariable added in v1.15.0

type PipelineVariable struct {
	UUID    string
	Key     string
	Value   string
	Secured bool
}

PipelineVariable is a repository-level pipeline variable on Bitbucket Cloud. Value is empty when Secured is true (the API never returns secured values).

type PipelineVariableInput added in v1.15.0

type PipelineVariableInput struct {
	Key     string
	Value   string
	Secured bool
}

PipelineVariableInput carries the parameters for upserting a pipeline variable by Key.

type Project added in v1.17.0

type Project struct {
	Key    string
	Name   string
	UUID   string
	WebURL string
}

Project is a Bitbucket Cloud project (a logical group of repositories inside a workspace). The naming clashes with Server/DC's "project" — which is the namespace itself — but Cloud's project sits one level deeper. Listed via WorkspaceClient.ListProjects(workspace).

type PullRequest

type PullRequest struct {
	ID          int
	Title       string
	Description string
	State       string
	Draft       bool
	Author      User
	FromBranch  string
	ToBranch    string
	WebURL      string
}

PullRequest is the domain representation of a Bitbucket pull request.

type RepoDeleter

type RepoDeleter interface {
	DeleteRepo(ns, slug string) error
}

type RepoForker added in v1.16.0

type RepoForker interface {
	ForkRepo(ns, slug string, in ForkRepoInput) (Repository, error)
}

RepoForker is implemented only by Bitbucket Cloud clients — Bitbucket Server / Data Center has no fork primitive in its REST API. Access via AsRepoForker so the Cloud-only constraint surfaces as a typed ErrUnsupportedOnHost error rather than a panic.

func AsRepoForker added in v1.16.0

func AsRepoForker(c Client, host string) (RepoForker, error)

AsRepoForker returns the RepoForker view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) if the backend at host has no fork primitive (Bitbucket Server / Data Center).

type RepoLister

type RepoLister interface {
	// ListRepos lists repositories. ns is the workspace (Bitbucket Cloud) or
	// project key (Bitbucket Server); pass "" for Server to list all repos.
	ListRepos(ns string, limit int) ([]Repository, error)
}

type RepoReader

type RepoReader interface {
	GetRepo(ns, slug string) (Repository, error)
}

type RepoRenamer added in v1.16.0

type RepoRenamer interface {
	RenameRepo(ns, slug, newName string) (Repository, error)
}

type RepoWriter

type RepoWriter interface {
	CreateRepo(ns string, in CreateRepoInput) (Repository, error)
}

type Repository

type Repository struct {
	Slug        string
	Name        string
	Namespace   string
	SCM         string
	WebURL      string
	Description string
	ID          int
}

Repository is the domain representation of a Bitbucket repository.

ID is the backend's numeric identifier (Server / Data Center). Cloud uses opaque UUIDs surfaced through other channels; for Cloud repos this field stays zero. ID is exposed so the BBS default-reviewers endpoint (which requires source/target repo IDs as query params) has what it needs without an adapter-internal cache.

type RunPipelineInput

type RunPipelineInput struct {
	Branch string
}

RunPipelineInput carries the parameters for triggering a pipeline run.

type SearchSegment added in v1.21.0

type SearchSegment struct {
	Text  string
	Match bool
}

SearchSegment is one run of text in a path or content match. Match=true marks the substring that triggered the hit so renderers can highlight it.

type ServerCapabilities

type ServerCapabilities interface {
	GetApplicationProperties() (AppProperties, error)
}

ServerCapabilities is implemented only by Bitbucket Data Center clients.

type Tag

type Tag struct {
	Name    string
	Hash    string
	Message string // empty for lightweight tags; first line for annotated
	WebURL  string
}

Tag is the domain representation of a repository tag.

type TagCreator

type TagCreator interface {
	CreateTag(ns, slug string, in CreateTagInput) (Tag, error)
}

type TagDeleter

type TagDeleter interface {
	DeleteTag(ns, slug, name string) error
}

type TagLister

type TagLister interface {
	ListTags(ns, slug string, limit int) ([]Tag, error)
}

type UpdateIssueInput added in v1.17.0

type UpdateIssueInput struct {
	Title    string
	Content  string
	State    string
	Kind     string
	Priority string
}

UpdateIssueInput carries the parameters for changing an issue. Empty strings mean "no change". `issue close` sets State="closed" and leaves the rest untouched.

type UpdatePRInput

type UpdatePRInput struct {
	Title       string // empty = no change
	Description string // empty = no change
}

UpdatePRInput carries the parameters for editing a pull request.

type User

type User struct {
	Slug        string
	DisplayName string
}

User is the domain representation of a Bitbucket user.

type UserGetter

type UserGetter interface {
	GetCurrentUser() (User, error)
}

type Webhook added in v1.15.0

type Webhook struct {
	ID     string
	URL    string
	Events []string
	Active bool
}

Webhook is the domain representation of a repository webhook. Both Bitbucket Cloud and Server/DC expose a similar shape — a remote URL, a list of subscribed events, and an active flag. ID is the backend's stable identifier (UUID on Cloud, integer-as-string on Server/DC).

type WebhookCreator added in v1.15.0

type WebhookCreator interface {
	CreateWebhook(ns, slug string, in CreateWebhookInput) (Webhook, error)
}

type WebhookDeleter added in v1.15.0

type WebhookDeleter interface {
	DeleteWebhook(ns, slug, id string) error
}

type WebhookLister added in v1.15.0

type WebhookLister interface {
	ListWebhooks(ns, slug string) ([]Webhook, error)
}

type WebhookReader added in v1.15.0

type WebhookReader interface {
	GetWebhook(ns, slug, id string) (Webhook, error)
}

type Workspace added in v1.17.0

type Workspace struct {
	Slug   string
	Name   string
	UUID   string
	WebURL string
}

Workspace is a Bitbucket Cloud workspace (the top-level ownership unit containing repositories and projects). Bitbucket Server / Data Center has no analogous concept — projects sit directly under the instance — so Workspace is Cloud-only and surfaced via the WorkspaceClient optional interface.

type WorkspaceClient added in v1.17.0

type WorkspaceClient interface {
	ListWorkspaces(limit int) ([]Workspace, error)
	ListProjects(workspace string, limit int) ([]Project, error)
}

WorkspaceClient is implemented only by Bitbucket Cloud clients. Bitbucket Server / Data Center has no workspace concept — its projects live directly under the instance — so the workspace and project list operations are Cloud-only and accessed via the AsWorkspaceClient type assertion.

func AsWorkspaceClient added in v1.17.0

func AsWorkspaceClient(c Client, host string) (WorkspaceClient, error)

AsWorkspaceClient returns the WorkspaceClient view of c, or a typed *DomainError (Kind=ErrUnsupportedOnHost) if the backend at host does not support workspaces.

Jump to

Keyboard shortcuts

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