Documentation
¶
Overview ¶
Package server is the Bitbucket Data Center (a.k.a. "Server") adapter for the backend.Client interface.
Index ¶
- Constants
- type Client
- func (c *Client) AddAnnotations(project, slug, hash, key string, in []backend.CodeInsightsAnnotationInput) error
- func (c *Client) AddCommentReaction(ns, slug string, prID, commentID int, emoji string) error
- func (c *Client) AddCommitComment(ns, slug, hash string, in backend.AddCommitCommentInput) (backend.CommitComment, error)
- func (c *Client) AddCommitCommentReaction(ns, slug, hash string, commentID int, emoji string) error
- func (c *Client) AddPRComment(ns, slug string, id int, in backend.AddPRCommentInput) (backend.PRComment, error)
- func (c *Client) ApprovePR(ns, slug string, id int) error
- func (c *Client) CreateBranch(ns, slug string, in backend.CreateBranchInput) (backend.Branch, error)
- func (c *Client) CreateBranchProtection(ns, slug string, in backend.CreateBranchProtectionInput) (backend.BranchProtection, error)
- func (c *Client) CreatePR(ns, slug string, in backend.CreatePRInput) (backend.PullRequest, error)
- func (c *Client) CreateRepo(ns string, in backend.CreateRepoInput) (backend.Repository, error)
- func (c *Client) CreateTag(ns, slug string, in backend.CreateTagInput) (backend.Tag, error)
- func (c *Client) CreateWebhook(ns, slug string, in backend.CreateWebhookInput) (backend.Webhook, error)
- func (c *Client) DeclinePR(ns, slug string, id int) error
- func (c *Client) DefaultReviewers(ns, slug, fromBranch, toBranch string) ([]backend.User, error)
- func (c *Client) DeleteAnnotations(project, slug, hash, key string) error
- func (c *Client) DeleteBranch(ns, slug, branch string) error
- func (c *Client) DeleteBranchProtection(ns, slug string, id int) error
- func (c *Client) DeleteCommitComment(ns, slug, hash string, commentID int) error
- func (c *Client) DeleteMergeCheck(project, slug, key string) error
- func (c *Client) DeletePRComment(ns, slug string, id, commentID int) error
- func (c *Client) DeleteRepo(ns, slug string) error
- func (c *Client) DeleteReport(project, slug, hash, key string) error
- func (c *Client) DeleteTag(ns, slug, name string) error
- func (c *Client) DeleteWebhook(ns, slug, id string) error
- func (c *Client) DisableAutoMerge(ns, slug string, id int) error
- func (c *Client) EditCommitComment(ns, slug, hash string, commentID int, body string) (backend.CommitComment, error)
- func (c *Client) EditPRComment(ns, slug string, id, commentID int, body string) (backend.PRComment, error)
- func (c *Client) EnableAutoMerge(ns, slug string, id int, strategy string) error
- func (c *Client) GetCommit(ns, slug, hash string) (backend.Commit, error)
- func (c *Client) GetCurrentUser() (backend.User, error)
- func (c *Client) GetFileContent(ns, slug, ref, pathInRepo string) ([]byte, error)
- func (c *Client) GetLoggingConfig() (backend.LoggingConfig, error)
- func (c *Client) GetMergeCheck(project, slug, key string) (backend.MergeCheck, error)
- func (c *Client) GetPR(ns, slug string, id int) (backend.PullRequest, error)
- func (c *Client) GetPRActivity(ns, slug string, id int, limit int) ([]backend.PRActivityEvent, error)
- func (c *Client) GetPRDiff(ns, slug string, id int) (string, error)
- func (c *Client) GetRepo(ns, slug string) (backend.Repository, error)
- func (c *Client) GetReport(project, slug, hash, key string) (backend.CodeInsightsReport, error)
- func (c *Client) GetWebhook(ns, slug, id string) (backend.Webhook, error)
- func (c *Client) GrantProjectPermission(_ context.Context, project string, subject backend.PermissionSubject, ...) error
- func (c *Client) GrantRepoPermission(_ context.Context, project, slug string, subject backend.PermissionSubject, ...) error
- func (c *Client) ListAnnotations(project, slug, hash, key string) ([]backend.CodeInsightsAnnotation, error)
- func (c *Client) ListBranchProtections(ns, slug string, limit int) ([]backend.BranchProtection, error)
- func (c *Client) ListBranches(ns, slug string, limit int) ([]backend.Branch, error)
- func (c *Client) ListCommentReactions(ns, slug string, prID, commentID int) ([]backend.CommentReaction, error)
- func (c *Client) ListCommitCommentReactions(ns, slug, hash string, commentID int) ([]backend.CommentReaction, error)
- func (c *Client) ListCommitComments(ns, slug, hash string, limit int) ([]backend.CommitComment, error)
- func (c *Client) ListCommitStatuses(_, _, hash string) ([]backend.CommitStatus, error)
- func (c *Client) ListCommits(ns, slug, branch string, limit int) ([]backend.Commit, error)
- func (c *Client) ListMyPRs(ns, slug string) ([]backend.MyPREntry, error)
- func (c *Client) ListPRComments(ns, slug string, id int) ([]backend.PRComment, error)
- func (c *Client) ListPRs(ns, slug, state string, limit int) ([]backend.PullRequest, error)
- func (c *Client) ListProjectPermissions(_ context.Context, project string) ([]backend.PermissionGrant, error)
- func (c *Client) ListRepoPermissions(_ context.Context, project, slug string) ([]backend.PermissionGrant, error)
- func (c *Client) ListReports(project, slug, hash string) ([]backend.CodeInsightsReport, error)
- func (c *Client) ListRepos(_ string, limit int) ([]backend.Repository, error)
- func (c *Client) ListTags(ns, slug string, limit int) ([]backend.Tag, error)
- func (c *Client) ListTree(ns, slug, ref, pathInRepo string) ([]backend.TreeEntry, error)
- func (c *Client) ListWebhooks(ns, slug string) ([]backend.Webhook, error)
- func (c *Client) MergePR(ns, slug string, id int, in backend.MergePRInput) (backend.PullRequest, error)
- func (c *Client) ReadyPR(ns, slug string, id int) error
- func (c *Client) RemoveCommentReaction(ns, slug string, prID, commentID int, emoji string) error
- func (c *Client) RemoveCommitCommentReaction(ns, slug, hash string, commentID int, emoji string) error
- func (c *Client) RenameRepo(ns, slug, newName string) (backend.Repository, error)
- func (c *Client) ReopenPR(ns, slug string, id int) error
- func (c *Client) RequestReview(ns, slug string, id int, users []string) error
- func (c *Client) RevokeProjectPermission(_ context.Context, project string, subject backend.PermissionSubject) error
- func (c *Client) RevokeRepoPermission(_ context.Context, project, slug string, subject backend.PermissionSubject) error
- func (c *Client) RotateSecrets() error
- func (c *Client) SetLoggingConfig(in backend.LoggingConfigInput) error
- func (c *Client) SetMergeCheck(project, slug, key string, in backend.MergeCheckInput) error
- func (c *Client) SetPRCommentState(ns, slug string, id, commentID int, state string) error
- func (c *Client) SetReport(project, slug, hash, key string, in backend.CodeInsightsReportInput) (backend.CodeInsightsReport, error)
- func (c *Client) SubmitReview(ns, slug string, id int, in backend.SubmitReviewInput) error
- func (c *Client) UnapprovePR(ns, slug string, id int) error
- func (c *Client) UpdatePR(ns, slug string, id int, in backend.UpdatePRInput) (backend.PullRequest, error)
- func (c *Client) UpdatePRBranch(ns, slug string, prID int) error
- type HTTPClient
- type PagedResponse
Constants ¶
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) AddCommentReaction ¶ added in v1.40.0
AddCommentReaction adds an emoji reaction to a pull-request comment.
API: POST /rest/api/1.0/projects/{ns}/repos/{slug}/pull-requests/{prID}/comments/{commentID}/reactions
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) AddCommitCommentReaction ¶ added in v1.41.0
AddCommitCommentReaction adds an emoji reaction to a commit comment.
API: POST /rest/api/1.0/projects/{ns}/repos/{slug}/commits/{hash}/comments/{commentID}/reactions
func (*Client) AddPRComment ¶ added in v1.6.0
func (*Client) ApprovePR ¶
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) CreateWebhook ¶ added in v1.15.0
func (*Client) DefaultReviewers ¶ added in v1.17.0
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
DeleteAnnotations removes all annotations under a given report key.
func (*Client) DeleteBranch ¶
func (*Client) DeleteBranchProtection ¶ added in v1.17.0
DeleteBranchProtection removes the restriction with the given numeric ID.
func (*Client) DeleteCommitComment ¶ added in v1.27.0
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
DeleteMergeCheck removes a merge-check configuration.
func (*Client) DeletePRComment ¶ added in v1.24.0
func (*Client) DeleteRepo ¶
func (*Client) DeleteReport ¶ added in v1.23.0
DeleteReport removes a Code Insights report and all its annotations.
func (*Client) DeleteWebhook ¶ added in v1.15.0
func (*Client) DisableAutoMerge ¶ added in v1.30.0
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 (*Client) EnableAutoMerge ¶ added in v1.30.0
EnableAutoMerge queues a PR for automatic merge on Bitbucket Server / DC.
func (*Client) GetCurrentUser ¶
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
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) GetLoggingConfig ¶ added in v1.38.0
func (c *Client) GetLoggingConfig() (backend.LoggingConfig, error)
GetLoggingConfig returns the current log level and async-logging setting. GET /rest/api/1.0/admin/logging
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) GetPRActivity ¶ added in v1.26.0
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 (*Client) GrantProjectPermission ¶ added in v1.37.0
func (c *Client) GrantProjectPermission(_ context.Context, project string, subject backend.PermissionSubject, perm string) error
GrantProjectPermission grants (or upgrades/downgrades) a user or group permission on a project.
func (*Client) GrantRepoPermission ¶ added in v1.37.0
func (c *Client) GrantRepoPermission(_ context.Context, project, slug string, subject backend.PermissionSubject, perm string) error
GrantRepoPermission grants (or upgrades/downgrades) a user or group permission on a repository.
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 (*Client) ListCommentReactions ¶ added in v1.40.0
func (c *Client) ListCommentReactions(ns, slug string, prID, commentID int) ([]backend.CommentReaction, error)
ListCommentReactions lists the reactions on a pull-request comment, grouped by emoji.
API: GET /rest/api/1.0/projects/{ns}/repos/{slug}/pull-requests/{prID}/comments/{commentID}/reactions
func (*Client) ListCommitCommentReactions ¶ added in v1.41.0
func (c *Client) ListCommitCommentReactions(ns, slug, hash string, commentID int) ([]backend.CommentReaction, error)
ListCommitCommentReactions lists the reactions on a commit comment, grouped by emoji.
API: GET /rest/api/1.0/projects/{ns}/repos/{slug}/commits/{hash}/comments/{commentID}/reactions
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 (*Client) ListMyPRs ¶ added in v1.28.0
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 (*Client) ListProjectPermissions ¶ added in v1.37.0
func (c *Client) ListProjectPermissions(_ context.Context, project string) ([]backend.PermissionGrant, error)
ListProjectPermissions returns all user and group permission grants for the given project, merged and sorted by permission level then subject name.
func (*Client) ListRepoPermissions ¶ added in v1.37.0
func (c *Client) ListRepoPermissions(_ context.Context, project, slug string) ([]backend.PermissionGrant, error)
ListRepoPermissions returns all user and group permission grants for the given repository, merged and sorted by permission level then subject name.
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 ¶
ListRepos lists all repositories accessible to the authenticated user. ns is ignored for Bitbucket Server (the REST API lists across all projects).
func (*Client) ListTree ¶ added in v1.22.0
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 (*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 ¶
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) RemoveCommentReaction ¶ added in v1.40.0
RemoveCommentReaction removes an emoji reaction from a pull-request comment.
API: DELETE /rest/api/1.0/projects/{ns}/repos/{slug}/pull-requests/{prID}/comments/{commentID}/reactions/{emoji}
func (*Client) RemoveCommitCommentReaction ¶ added in v1.41.0
func (c *Client) RemoveCommitCommentReaction(ns, slug, hash string, commentID int, emoji string) error
RemoveCommitCommentReaction removes an emoji reaction from a commit comment.
API: DELETE /rest/api/1.0/projects/{ns}/repos/{slug}/commits/{hash}/comments/{commentID}/reactions/{emoji}
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
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 (*Client) RevokeProjectPermission ¶ added in v1.37.0
func (c *Client) RevokeProjectPermission(_ context.Context, project string, subject backend.PermissionSubject) error
RevokeProjectPermission removes any permission grant a user or group has on a project.
func (*Client) RevokeRepoPermission ¶ added in v1.37.0
func (c *Client) RevokeRepoPermission(_ context.Context, project, slug string, subject backend.PermissionSubject) error
RevokeRepoPermission removes any permission grant a user or group has on a repository.
func (*Client) RotateSecrets ¶ added in v1.38.0
RotateSecrets rotates the cluster's internal HTTPS secret. POST /rest/api/1.0/admin/secrets — no request body; 200 OK = success.
func (*Client) SetLoggingConfig ¶ added in v1.38.0
func (c *Client) SetLoggingConfig(in backend.LoggingConfigInput) error
SetLoggingConfig updates the log level and/or async-logging setting. If in.Persistent is true: PUT /rest/api/1.0/admin/logging/properties Otherwise: PUT /rest/api/1.0/admin/logging
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) SetPRCommentState ¶ added in v1.39.0
SetPRCommentState sets the state of a task comment (BLOCKER severity) on a pull request. It first fetches the current comment to get the version token (GET), then issues a PUT with the new state and the fetched version. state must be "OPEN" or "RESOLVED".
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
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 ¶
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)
type HTTPClient ¶
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.
Source Files
¶
- admin.go
- branch_protect.go
- branches.go
- client.go
- codeinsights.go
- commit.go
- commit_comment.go
- commit_comment_reactions.go
- commit_status.go
- default_reviewers.go
- permissions.go
- pr_activity.go
- pr_comments.go
- pr_lifecycle.go
- pr_review.go
- pr_status.go
- pr_update_branch.go
- prs.go
- reactions.go
- repos.go
- source.go
- tag.go
- webhooks.go