server

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package server is the Bitbucket Data Center (a.k.a. "Server") adapter for the backend.Client interface.

Index

Constants

View Source
const FeaturePRReviewRequestChanges backend.Feature = "pr-review-request-changes"

FeaturePRReviewRequestChanges names the request-changes branch of the compound `pr review` action for typed-error reporting. Bitbucket Server / Data Center has no request-changes endpoint — only Cloud does — so the action surfaces as a typed *DomainError(Kind=ErrUnsupportedOnHost) rather than a generic 405/404 on Server.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the Bitbucket Data Center HTTP client.

func NewClient

func NewClient(httpClient HTTPClient, baseURL, token, username string) *Client

NewClient constructs a Client. If token is non-empty Bearer auth is used; else if username is non-empty Basic auth is used with username:token as credentials.

func (*Client) AddAnnotations added in v1.23.0

func (c *Client) AddAnnotations(project, slug, hash, key string, in []backend.CodeInsightsAnnotationInput) error

AddAnnotations bulk-POSTs all annotations in a single request.

func (*Client) AddCommitComment added in v1.27.0

func (c *Client) AddCommitComment(ns, slug, hash string, in backend.AddCommitCommentInput) (backend.CommitComment, error)

AddCommitComment posts a new comment on a commit.

func (*Client) AddPRComment added in v1.6.0

func (c *Client) AddPRComment(ns, slug string, id int, in backend.AddPRCommentInput) (backend.PRComment, error)

func (*Client) ApprovePR

func (c *Client) ApprovePR(ns, slug string, id int) error

ApprovePR approves a PR on behalf of the authenticated user. Bitbucket Server (like Cloud) exposes a dedicated POST .../approve endpoint; the participants/{userSlug} path requires an actual slug and does not accept ~.

func (*Client) CreateBranch

func (c *Client) CreateBranch(ns, slug string, in backend.CreateBranchInput) (backend.Branch, error)

CreateBranch creates a new branch in the given repository. Server accepts both branch names and commit hashes in startPoint.

func (*Client) CreateBranchProtection added in v1.17.0

func (c *Client) CreateBranchProtection(ns, slug string, in backend.CreateBranchProtectionInput) (backend.BranchProtection, error)

CreateBranchProtection creates a single branch restriction. Empty MatcherKind defaults to "BRANCH" — the most common case for users passing a literal branch name on the CLI.

func (*Client) CreatePR

func (c *Client) CreatePR(ns, slug string, in backend.CreatePRInput) (backend.PullRequest, error)

func (*Client) CreateRepo

func (c *Client) CreateRepo(ns string, in backend.CreateRepoInput) (backend.Repository, error)

func (*Client) CreateTag

func (c *Client) CreateTag(ns, slug string, in backend.CreateTagInput) (backend.Tag, error)

func (*Client) CreateWebhook added in v1.15.0

func (c *Client) CreateWebhook(ns, slug string, in backend.CreateWebhookInput) (backend.Webhook, error)

func (*Client) DeclinePR

func (c *Client) DeclinePR(ns, slug string, id int) error

DeclinePR declines an open pull request.

func (*Client) DefaultReviewers added in v1.17.0

func (c *Client) DefaultReviewers(ns, slug, fromBranch, toBranch string) ([]backend.User, error)

DefaultReviewers fetches the configured default reviewers for a PR with the given source/target refs. We do an extra GET on the repo to learn its numeric ID — Bitbucket Server's default-reviewers endpoint requires sourceRepoId and targetRepoId as query params, and same-repo PRs are the overwhelmingly common case (so source and target are the same ID).

Cross-repo (fork) PRs would need a different code path that takes a distinct source repo; that's out of scope here. The current contract targets the 99% same-repo case and falls back gracefully (returns no reviewers) when the response is empty.

func (*Client) DeleteAnnotations added in v1.23.0

func (c *Client) DeleteAnnotations(project, slug, hash, key string) error

DeleteAnnotations removes all annotations under a given report key.

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(ns, slug, branch string) error

func (*Client) DeleteBranchProtection added in v1.17.0

func (c *Client) DeleteBranchProtection(ns, slug string, id int) error

DeleteBranchProtection removes the restriction with the given numeric ID.

func (*Client) DeleteCommitComment added in v1.27.0

func (c *Client) DeleteCommitComment(ns, slug, hash string, commentID int) error

DeleteCommitComment removes a commit comment. Server requires the current version as a query param for optimistic concurrency.

func (*Client) DeleteMergeCheck added in v1.23.0

func (c *Client) DeleteMergeCheck(project, slug, key string) error

DeleteMergeCheck removes a merge-check configuration.

func (*Client) DeletePRComment added in v1.24.0

func (c *Client) DeletePRComment(ns, slug string, id, commentID int) error

func (*Client) DeleteRepo

func (c *Client) DeleteRepo(ns, slug string) error

func (*Client) DeleteReport added in v1.23.0

func (c *Client) DeleteReport(project, slug, hash, key string) error

DeleteReport removes a Code Insights report and all its annotations.

func (*Client) DeleteTag

func (c *Client) DeleteTag(ns, slug, name string) error

func (*Client) DeleteWebhook added in v1.15.0

func (c *Client) DeleteWebhook(ns, slug, id string) error

func (*Client) DisableAutoMerge added in v1.30.0

func (c *Client) DisableAutoMerge(ns, slug string, id int) error

DisableAutoMerge cancels a queued auto-merge on Bitbucket Server / DC.

func (*Client) EditCommitComment added in v1.27.0

func (c *Client) EditCommitComment(ns, slug, hash string, commentID int, body string) (backend.CommitComment, error)

EditCommitComment updates the body of a commit comment. Server requires the current version for optimistic concurrency — the comment is fetched first to obtain it, then the PUT is issued.

func (*Client) EditPRComment added in v1.24.0

func (c *Client) EditPRComment(ns, slug string, id, commentID int, body string) (backend.PRComment, error)

func (*Client) EnableAutoMerge added in v1.30.0

func (c *Client) EnableAutoMerge(ns, slug string, id int, strategy string) error

EnableAutoMerge queues a PR for automatic merge on Bitbucket Server / DC.

func (*Client) GetCommit

func (c *Client) GetCommit(ns, slug, hash string) (backend.Commit, error)

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() (backend.User, error)

GetCurrentUser fetches the authenticated user. Bitbucket Server does not support GET /users/~ (Cloud-only), so when a userSlug was provided at construction time we call GET /users/{slug} instead.

func (*Client) GetFileContent added in v1.22.0

func (c *Client) GetFileContent(ns, slug, ref, pathInRepo string) ([]byte, error)

GetFileContent returns the raw bytes of a file at ref. Server's /raw endpoint always returns the file's bytes verbatim, so directory paths are caught by Server returning a 404 (mapped to ErrNotFound by the transport's DomainError classifier) and surface to the caller with the same shape as Cloud.

func (*Client) GetMergeCheck added in v1.23.0

func (c *Client) GetMergeCheck(project, slug, key string) (backend.MergeCheck, error)

GetMergeCheck fetches the current merge-check configuration for a key.

func (*Client) GetPR

func (c *Client) GetPR(ns, slug string, id int) (backend.PullRequest, error)

func (*Client) GetPRActivity added in v1.26.0

func (c *Client) GetPRActivity(ns, slug string, id int, limit int) ([]backend.PRActivityEvent, error)

func (*Client) GetPRDiff

func (c *Client) GetPRDiff(ns, slug string, id int) (string, error)

func (*Client) GetRepo

func (c *Client) GetRepo(ns, slug string) (backend.Repository, error)

func (*Client) GetReport added in v1.23.0

func (c *Client) GetReport(project, slug, hash, key string) (backend.CodeInsightsReport, error)

GetReport fetches a single Code Insights report by key.

func (*Client) GetWebhook added in v1.15.0

func (c *Client) GetWebhook(ns, slug, id string) (backend.Webhook, error)

func (*Client) ListAnnotations added in v1.23.0

func (c *Client) ListAnnotations(project, slug, hash, key string) ([]backend.CodeInsightsAnnotation, error)

ListAnnotations returns all annotations under a given report key.

func (*Client) ListBranchProtections added in v1.17.0

func (c *Client) ListBranchProtections(ns, slug string, limit int) ([]backend.BranchProtection, error)

ListBranchProtections lists branch restrictions for the given repo.

func (*Client) ListBranches

func (c *Client) ListBranches(ns, slug string, limit int) ([]backend.Branch, error)

func (*Client) ListCommitComments added in v1.27.0

func (c *Client) ListCommitComments(ns, slug, hash string, limit int) ([]backend.CommitComment, error)

ListCommitComments lists all comments on a commit using the standard Bitbucket Server paged response. Uses paging.Collect to handle pagination.

func (*Client) ListCommitStatuses added in v1.6.0

func (c *Client) ListCommitStatuses(_, _, hash string) ([]backend.CommitStatus, error)

ListCommitStatuses lists build / CI statuses reported against a commit hash. Bitbucket Server / Data Center exposes these on a separate REST root, /rest/build-status/1.0, rather than the regular /rest/api/1.0 base.

The ns/slug arguments are unused by the Server build-status API (statuses are keyed only by commit hash) but are kept for interface symmetry.

func (*Client) ListCommits

func (c *Client) ListCommits(ns, slug, branch string, limit int) ([]backend.Commit, error)

func (*Client) ListMyPRs added in v1.28.0

func (c *Client) ListMyPRs(ns, slug string) ([]backend.MyPREntry, error)

ListMyPRs returns the authenticated user's open PRs. REVIEWER PRs come from /inbox/pull-requests. AUTHOR PRs come from the scoped repo endpoint filtered by author slug.

func (*Client) ListPRComments added in v1.6.0

func (c *Client) ListPRComments(ns, slug string, id int) ([]backend.PRComment, error)

func (*Client) ListPRs

func (c *Client) ListPRs(ns, slug, state string, limit int) ([]backend.PullRequest, error)

func (*Client) ListReports added in v1.23.0

func (c *Client) ListReports(project, slug, hash string) ([]backend.CodeInsightsReport, error)

ListReports returns all Code Insights reports attached to a commit.

func (*Client) ListRepos

func (c *Client) ListRepos(_ string, limit int) ([]backend.Repository, error)

ListRepos lists all repositories accessible to the authenticated user. ns is ignored for Bitbucket Server (the REST API lists across all projects).

func (*Client) ListTags

func (c *Client) ListTags(ns, slug string, limit int) ([]backend.Tag, error)

func (*Client) ListTree added in v1.22.0

func (c *Client) ListTree(ns, slug, ref, pathInRepo string) ([]backend.TreeEntry, error)

ListTree returns the immediate children of pathInRepo at ref. Server's /browse endpoint nests the entries under "children.values" with its standard {start, isLastPage, nextPageStart} pagination, but the transport's serverPaginator inspects the top-level fields — which Server replicates at the outer level too. Iterating with GetAllJSON + re-decoding the children block per page covers both single- and multi-page directories.

func (*Client) ListWebhooks added in v1.15.0

func (c *Client) ListWebhooks(ns, slug string) ([]backend.Webhook, error)

func (*Client) MergePR

func (c *Client) MergePR(ns, slug string, id int, in backend.MergePRInput) (backend.PullRequest, error)

MergePR merges a pull request. Bitbucket Server uses optimistic concurrency: the POST body must include the current PR version (from GET), otherwise the server returns HTTP 409.

func (*Client) ReadyPR

func (c *Client) ReadyPR(ns, slug string, id int) error

ReadyPR marks a draft pull request as ready for review.

Bitbucket Server's PUT endpoint for a PR requires the full PR object (title, fromRef, toRef, ...), so we GET the current PR first, flip the draft flag, and PUT the full body back.

func (*Client) RenameRepo added in v1.16.0

func (c *Client) RenameRepo(ns, slug, newName string) (backend.Repository, error)

func (*Client) ReopenPR added in v1.21.0

func (c *Client) ReopenPR(ns, slug string, id int) error

ReopenPR reverses a decline, returning the PR to OPEN.

Bitbucket Server uses optimistic concurrency on its PR lifecycle endpoints: the POST body must include the current PR version (from GET), otherwise the server returns HTTP 409 "Pull request was updated…" against any non-zero- version declined PR. Mirrors MergePR's GET-then-POST(version) pattern.

func (*Client) RequestReview

func (c *Client) RequestReview(ns, slug string, id int, users []string) error

func (*Client) SetMergeCheck added in v1.23.0

func (c *Client) SetMergeCheck(project, slug, key string, in backend.MergeCheckInput) error

SetMergeCheck creates or replaces a merge-check configuration. Uses the partly-undocumented /rest/insights/latest/.../merge-check/ path.

func (*Client) SetReport added in v1.23.0

func (c *Client) SetReport(project, slug, hash, key string, in backend.CodeInsightsReportInput) (backend.CodeInsightsReport, error)

SetReport creates or replaces a Code Insights report (PUT / upsert).

func (*Client) SubmitReview added in v1.25.0

func (c *Client) SubmitReview(ns, slug string, id int, in backend.SubmitReviewInput) error

SubmitReview implements backend.PRReviewer for Bitbucket Server / DC. Mirrors the Cloud sequence (body → inline → action) but rejects "request_changes" up front with a typed ErrUnsupportedOnHost — Server has no equivalent endpoint.

func (*Client) UnapprovePR

func (c *Client) UnapprovePR(ns, slug string, id int) error

UnapprovePR removes the authenticated user's approval from a pull request. Mirrors the approve endpoint: DELETE .../approve (not DELETE .../participants/~, which requires an actual user slug and is rejected by Bitbucket Server).

func (*Client) UpdatePR

func (c *Client) UpdatePR(ns, slug string, id int, in backend.UpdatePRInput) (backend.PullRequest, error)

func (*Client) UpdatePRBranch added in v1.28.0

func (c *Client) UpdatePRBranch(ns, slug string, prID int) error

UpdatePRBranch rebases a PR's source branch onto its base branch. POST /rest/api/1.0/projects/{key}/repos/{slug}/pull-requests/{prID}/rebase 200 OK on success.

type HTTPClient

type HTTPClient = httpx.Doer

HTTPClient is the transport interface for making HTTP requests. It is retained as an alias at the package boundary so callers in this repository continue to compile without importing the internal httpx package.

type PagedResponse

type PagedResponse[T any] struct {
	Values        []T  `json:"values"`
	Size          int  `json:"size"`
	IsLastPage    bool `json:"isLastPage"`
	NextPageStart *int `json:"nextPageStart"`
	Start         int  `json:"start"`
}

PagedResponse is the Bitbucket Data Center paged list envelope.

Jump to

Keyboard shortcuts

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