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

cloud

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cloud implements the Bitbucket Cloud forge driver (driver type "bitbucket") on top of the Bitbucket Cloud REST API 2.0.

Bitbucket's model is Workspace -> (Project) -> Repository. A Trove repository's Namespace is the workspace slug and its Name the repository slug (not the display name).

Notable platform facts this driver is built around (verified against the published OpenAPI description and the Bitbucket Cloud changelog, 2026):

  • The cross-workspace listing endpoints (GET /2.0/repositories, GET /2.0/workspaces, GET /2.0/user/permissions/workspaces, GET /2.0/snippets) were removed on 14 April 2026 (CHANGE-2770). Workspaces are discovered with GET /2.0/user/workspaces and every listing is then made per workspace.
  • The native issue tracker and its API were removed on 20 August 2026, so this driver declares no issue capabilities.
  • Git over SSH moves from bitbucket.org to ssh.bitbucket.org (the old host stops accepting SSH in November 2026), so computed SSH clone URLs use ssh.bitbucket.org.
  • Bitbucket has no repository archive flag, no releases, no notifications API, no pipeline re-run endpoint and no fetchable pull request refs; the corresponding capabilities are not declared.

Provider-specific account configuration (read through Account.Decode):

workspace: my-workspace   # default workspace; required for access tokens

Index

Constants

View Source
const DriverType = "bitbucket"

DriverType is the registry key of this driver.

Variables

This section is empty.

Functions

func NewDriver

func NewDriver() forge.Driver

NewDriver returns the Bitbucket Cloud driver.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is a Bitbucket Cloud provider bound to one account.

func (*Provider) AddSSHKey

func (p *Provider) AddSSHKey(ctx context.Context, title, key string) (*domain.SSHKey, error)

AddSSHKey implements forge.SSHKeyProvider.

func (*Provider) AuthStatus

func (p *Provider) AuthStatus(ctx context.Context) (*auth.Status, error)

AuthStatus implements forge.Authenticator.

func (*Provider) CancelPipeline

func (p *Provider) CancelPipeline(ctx context.Context, ref domain.RepositoryRef, id string) error

CancelPipeline implements forge.PipelineCanceler (POST .../stopPipeline).

func (*Provider) Capabilities

func (p *Provider) Capabilities() forge.Capabilities

Capabilities implements forge.Provider. Only what the Bitbucket Cloud API genuinely supports is declared (see the package documentation).

func (*Provider) ClosePullRequest

func (p *Provider) ClosePullRequest(ctx context.Context, ref domain.RepositoryRef, number int) error

ClosePullRequest implements forge.PullRequestCloser by declining the pull request (Bitbucket's "closed without merging" state).

func (*Provider) CreatePullRequest

CreatePullRequest implements forge.PullRequestCreator. A SourceRepo ("workspace/slug") targets a fork; an empty TargetBranch lets Bitbucket use the repository's main branch.

func (*Provider) CreateRepository

func (p *Provider) CreateRepository(ctx context.Context, req forge.CreateRepositoryRequest) (*domain.Repository, error)

CreateRepository implements forge.RepositoryCreator with POST /repositories/{workspace}/{slug}. The workspace defaults to the account's configured workspace. Bitbucket always creates empty repositories whose main branch is set by the first push, so AutoInit and DefaultBranch are rejected rather than silently ignored.

func (*Provider) CreateSnippet

func (p *Provider) CreateSnippet(ctx context.Context, req forge.CreateSnippetRequest) (*domain.Snippet, error)

CreateSnippet implements forge.SnippetCreator with a multipart/form-data POST (title, is_private and one "file" part per file) to /snippets/{workspace}, or /snippets (the caller's own account) when no workspace is given or configured. Bitbucket snippets have a title but no separate description: a description alone is used as the title, and supplying both is rejected rather than dropping one silently.

func (*Provider) CurrentUser

func (p *Provider) CurrentUser(ctx context.Context) (*domain.User, error)

CurrentUser implements forge.Provider.

Access tokens (repository/project/workspace) are not tied to a user and GET /user rejects them. For those the driver validates the token against the configured workspace (GET /repositories/{workspace}?pagelen=1) and returns a user that describes the token: ID "access-token:<workspace>", empty Username and Name "<workspace> access token".

func (*Provider) DeleteRepository

func (p *Provider) DeleteRepository(ctx context.Context, ref domain.RepositoryRef) error

DeleteRepository implements forge.RepositoryDeleter.

func (*Provider) ForkRepository

func (p *Provider) ForkRepository(ctx context.Context, ref domain.RepositoryRef, req forge.ForkRequest) (*domain.Repository, error)

ForkRepository implements forge.RepositoryForker with POST /repositories/{workspace}/{slug}/forks. The target workspace is req.Namespace or the configured workspace; when neither is set Bitbucket forks into the caller's personal workspace.

func (*Provider) GetNamespace

func (p *Provider) GetNamespace(ctx context.Context, path string) (*domain.Namespace, error)

GetNamespace implements forge.NamespaceProvider. path is a workspace slug ("acme") or a project inside a workspace ("acme/PROJ", by project key).

func (*Provider) GetPipeline

func (p *Provider) GetPipeline(ctx context.Context, ref domain.RepositoryRef, id string) (*domain.Pipeline, error)

GetPipeline implements forge.PipelineProvider. id is the pipeline UUID (with braces, as Bitbucket returns it); its steps become the jobs.

func (*Provider) GetPullRequest

func (p *Provider) GetPullRequest(ctx context.Context, ref domain.RepositoryRef, number int) (*domain.PullRequest, error)

GetPullRequest implements forge.PullRequestProvider.

func (*Provider) GetRepository

func (p *Provider) GetRepository(ctx context.Context, ref domain.RepositoryRef) (*domain.Repository, error)

GetRepository implements forge.RepositoryProvider.

func (*Provider) GetSnippet

func (p *Provider) GetSnippet(ctx context.Context, id string) (*domain.Snippet, error)

GetSnippet implements forge.SnippetProvider. File contents are fetched with GET /snippets/{workspace}/{id}/files/{path}, which redirects (on the API host) to the latest revision of each file.

func (*Provider) GitCredentials

func (p *Provider) GitCredentials(ctx context.Context) (string, string, error)

GitCredentials implements forge.GitAuthenticator using Bitbucket's documented Git-over-HTTPS usernames: "x-bitbucket-api-token-auth" for Atlassian API tokens and "x-token-auth" for access tokens and OAuth access tokens. Expired OAuth tokens are refreshed first.

func (*Provider) ListGPGKeys

func (p *Provider) ListGPGKeys(ctx context.Context) ([]domain.GPGKey, error)

ListGPGKeys implements forge.GPGKeyProvider. The key fingerprint is the identifier Bitbucket uses in /gpg-keys/{fingerprint}.

func (*Provider) ListNamespaces

func (p *Provider) ListNamespaces(ctx context.Context, opts forge.ListOptions) ([]domain.Namespace, error)

ListNamespaces implements forge.NamespaceProvider by listing the caller's workspaces (GET /user/workspaces). Access tokens cannot enumerate workspaces; for them the configured workspace is returned.

func (*Provider) ListPipelines

func (p *Provider) ListPipelines(ctx context.Context, ref domain.RepositoryRef, opts forge.PipelineListOptions) ([]domain.Pipeline, error)

ListPipelines implements forge.PipelineProvider (newest first). Ref is filtered server-side (target.ref_name); Status is filtered client-side because one normalized status covers several Bitbucket states.

func (*Provider) ListPullRequests

ListPullRequests implements forge.PullRequestProvider. States are passed as repeated state parameters; Author and TargetBranch become BBQL filters (author.uuid for "{uuid}" values, author.nickname otherwise).

func (*Provider) ListRepositories

func (p *Provider) ListRepositories(ctx context.Context, opts forge.ListRepositoryOptions) ([]domain.Repository, error)

ListRepositories implements forge.RepositoryProvider.

With a namespace, GET /repositories/{workspace} lists every repository of that workspace visible to the caller. Without one, the listing visits each workspace returned by GET /user/workspaces with role=member (Bitbucket no longer offers a cross-workspace repository listing). OwnedOnly maps to role=owner. Bitbucket has no archive flag, so IncludeArchived is moot.

func (*Provider) ListSSHKeys

func (p *Provider) ListSSHKeys(ctx context.Context) ([]domain.SSHKey, error)

ListSSHKeys implements forge.SSHKeyProvider.

func (*Provider) ListSnippets

func (p *Provider) ListSnippets(ctx context.Context, opts forge.ListOptions) ([]domain.Snippet, error)

ListSnippets implements forge.SnippetProvider. The cross-workspace GET /snippets listing no longer exists, so each of the caller's workspaces is listed with GET /snippets/{workspace}?role=member.

func (*Provider) Login

func (p *Provider) Login(ctx context.Context, req auth.Request) (*auth.Result, error)

Login implements forge.Authenticator. Supported methods:

  • basic: Atlassian account email (req.Username or the account's username) + API token (req.Token), sent with HTTP Basic auth.
  • access-token: a repository, project or workspace access token (req.Token), sent as a Bearer token. Requires the account's `workspace` setting, because such tokens have no user to validate.
  • oauth: an OAuth consumer (req.ClientID + req.ClientSecret) using the client credentials grant, or a pre-issued OAuth access token (req.Token without a client secret, which cannot be refreshed).

The credential is validated against the API but not persisted.

func (*Provider) MergeMethods

func (p *Provider) MergeMethods() []domain.MergeMethod

MergeMethods implements forge.PullRequestMerger. Bitbucket's strategies map as merge -> merge_commit, squash -> squash and rebase -> rebase_fast_forward (rebase onto the destination, then fast-forward). The repository's branch settings decide which strategies are allowed.

func (*Provider) MergePullRequest

func (p *Provider) MergePullRequest(ctx context.Context, ref domain.RepositoryRef, number int, req forge.MergePullRequestRequest) error

MergePullRequest implements forge.PullRequestMerger with a synchronous POST .../pullrequests/{id}/merge.

func (*Provider) Metadata

func (p *Provider) Metadata() forge.Metadata

Metadata implements forge.Provider.

func (*Provider) PipelineLogs

func (p *Provider) PipelineLogs(ctx context.Context, ref domain.RepositoryRef, pipelineID, jobID string, w io.Writer) error

PipelineLogs implements forge.PipelineLogger. Completed step logs are served through a 307 redirect to long-term storage; the redirect is followed without our Authorization header (see checkRedirect). With an empty jobID every step is written, each preceded by "==> <step name>".

func (*Provider) RefreshCredential

func (p *Provider) RefreshCredential(ctx context.Context) (*auth.Status, error)

RefreshCredential implements forge.Refresher for OAuth consumer credentials: it uses the refresh token (or re-runs the client credentials grant) and persists the result through the account's credential store.

func (*Provider) RemoveSSHKey

func (p *Provider) RemoveSSHKey(ctx context.Context, id string) error

RemoveSSHKey implements forge.SSHKeyProvider. id is the key UUID.

func (*Provider) RenameRepository

func (p *Provider) RenameRepository(ctx context.Context, ref domain.RepositoryRef, newName string) (*domain.Repository, error)

RenameRepository implements forge.RepositoryRenamer with PUT /repositories/{workspace}/{slug} {"name": ...}. Bitbucket re-derives the slug from the new name, so the returned repository may live at a new path.

func (*Provider) RepositoryURLs

func (p *Provider) RepositoryURLs(ref domain.RepositoryRef) domain.RepositoryURLs

RepositoryURLs computes URLs without an API call, honoring the account's CloneBaseURL, SSHHost and WebURL overrides.

func (*Provider) RunPipeline

RunPipeline implements forge.PipelineRunner. It triggers the pipeline for the branch req.Ref; req.Workflow selects a custom pipeline (selector type "custom") defined in bitbucket-pipelines.yml.

func (*Provider) Search

Search implements forge.Searcher.

  • Repositories: BBQL name~"<query>" per workspace (q.Namespace, or every workspace of the caller).
  • Code: GET /workspaces/{workspace}/search/code; needs a workspace from q.Namespace, q.Repository or the account's `workspace` setting. q.Repository narrows the search with the "repo:" qualifier. Atlassian has announced this API's deprecation for 1 November 2026.
  • Issues: unsupported; the Bitbucket Cloud issue tracker and its API were removed on 20 August 2026.

func (*Provider) Summary

func (p *Provider) Summary(ctx context.Context) (*domain.AccountSummary, error)

Summary implements forge.SummaryProvider:

  • Repositories: the sum of "size" of GET /repositories/{workspace} ?role=member&pagelen=1 over the caller's workspaces (nil if Bitbucket omits size for any of them).
  • OpenPullRequests: the sum of "size" of GET /workspaces/{workspace}/pullrequests/{user}?state=OPEN&pagelen=1 (pull requests authored by the caller; nil for access tokens or when any count is unavailable).

Issues, pipelines and notifications have no cheap account-wide count.

Jump to

Keyboard shortcuts

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