bitbucket

package
v0.22.2 Latest Latest
Warning

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

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

Documentation

Overview

Package bitbucket is a minimal Bitbucket Cloud REST API client covering only the endpoints notifycat needs for validation and path routing. It is intentionally narrow — adding a new endpoint means adding one method, not pulling in a full SDK.

Index

Constants

This section is empty.

Variables

View Source
var ErrDiffstatUnavailable = errors.New("bitbucket: diffstat unavailable (stale source ref)")

ErrDiffstatUnavailable is returned by ListPullRequestFiles when Bitbucket redirects the diffstat request to a stale source ref (spec=None), meaning the changed-file set cannot be resolved. Callers treat it as a soft failure.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Method  string
	Status  int
	Message string
}

APIError represents a non-2xx Bitbucket response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client talks to the Bitbucket Cloud REST API.

func NewClient

func NewClient(hc *http.Client, token, email string, opts ...Option) *Client

NewClient builds a Client. The httpClient is used as-is; callers should configure timeouts on it. token is the Bitbucket access token; email, when non-empty, switches auth to HTTP Basic (base64 of email:token) instead of a bearer token.

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(ctx context.Context, workspace, repoSlug string, id int) (PullRequestState, error)

GetPullRequest fetches a single PR's state and draft flag. A non-2xx response is returned as a typed *APIError.

func (*Client) GetRepository

func (c *Client) GetRepository(ctx context.Context, workspace, repoSlug string) (Repository, error)

GetRepository fetches a single repository. A non-2xx response is returned as a typed *APIError (e.g. Status 404 for a missing or inaccessible repo).

func (*Client) ListHookEvents

func (c *Client) ListHookEvents(ctx context.Context, workspace, repoSlug, urlSuffix string) ([]string, error)

ListHookEvents returns the union of events configured across active hooks pointing at notifycat (matched by `urlSuffix` against hook.url). Returns an empty slice when no matching hook exists, so callers can distinguish "no notifycat hook" from "hook misconfigured".

func (*Client) ListPullRequestFiles

func (c *Client) ListPullRequestFiles(ctx context.Context, workspace, repoSlug string, id int) ([]string, error)

ListPullRequestFiles returns the repo-relative paths of every file changed in a PR, following Bitbucket's diffstat pagination. Bitbucket 302-redirects the diffstat request to a spec-pinned URL; this call follows the redirect while replaying auth. A redirect to a stale source ref (spec=None) surfaces as ErrDiffstatUnavailable so path routing can soft-fail to the repo tier.

func (*Client) ListWorkspaceRepos

func (c *Client) ListWorkspaceRepos(ctx context.Context, workspace string) ([]string, error)

ListWorkspaceRepos returns the slugs of every repository in the workspace, following Bitbucket's pagination envelope. An empty result is a normal outcome (empty workspace or all repos filtered by token scope).

type Hook

type Hook struct {
	UUID   string   `json:"uuid"`
	URL    string   `json:"url"`
	Active bool     `json:"active"`
	Events []string `json:"events"`
}

Hook is the subset of a repository webhook record we care about.

type Option

type Option func(*Client)

Option configures Client construction.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the Bitbucket API base URL.

type PullRequestState

type PullRequestState struct {
	State string `json:"state"`
	Draft bool   `json:"draft"`
}

PullRequestState is the subset of a PR's status the stuck-PR digest needs. The State field is Bitbucket's raw value (OPEN, MERGED, DECLINED, SUPERSEDED) and is not normalized.

type Repository

type Repository struct {
	FullName  string `json:"full_name"`
	Slug      string `json:"slug"`
	IsPrivate bool   `json:"is_private"`
}

Repository is the subset of a repository record notifycat validates against.

Jump to

Keyboard shortcuts

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