bitbucket

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "https://api.bitbucket.org/2.0"

DefaultBaseURL is the Bitbucket Cloud API v2 base URL.

Variables

View Source
var (
	// ErrUnauthorized is returned when Bitbucket rejects the OAuth token (401).
	ErrUnauthorized = errors.New("bitbucket unauthorized")

	// ErrForbidden is returned when the token lacks the required permission (403).
	ErrForbidden = errors.New("bitbucket forbidden")

	// ErrNotFound is returned when the Bitbucket resource does not exist (404).
	ErrNotFound = errors.New("bitbucket not found")

	// ErrInvalidRepoURL is returned when a repository URL is not a valid
	// https://bitbucket.org/{workspace}/{slug} URL.
	ErrInvalidRepoURL = errors.New("invalid bitbucket repository URL")

	// ErrUnexpectedOrigin is returned when an absolute upstream URL, such as a
	// pagination next link, points at an origin other than the configured API
	// base URL. The request is rejected before the bearer token is attached.
	ErrUnexpectedOrigin = errors.New("bitbucket next url has unexpected origin")
)

Functions

func ParseRepoSlug added in v0.18.0

func ParseRepoSlug(repoURL string) (string, string, error)

ParseRepoSlug extracts the workspace and repository slug from a Bitbucket Cloud repository URL of the form https://bitbucket.org/{workspace}/{slug}. Trailing slashes, deeper paths, and a .git suffix are tolerated. Non-HTTPS URLs, foreign hosts, and paths with fewer than two segments are rejected with ErrInvalidRepoURL.

Types

type APIError added in v0.18.0

type APIError struct {
	StatusCode int
	Message    string
}

APIError represents an unexpected Bitbucket API response or a transport failure. StatusCode is 0 for transport/network failures. Error text never includes upstream response bodies, secrets, or the Authorization header.

func (*APIError) Error added in v0.18.0

func (e *APIError) Error() string

Error implements the error interface with a sanitized message.

type Attachment added in v0.2.0

type Attachment struct {
	User     User   `json:"user"`
	Issue    int    `json:"issue"`
	URL      string `json:"url"`
	Filename string `json:"filename"`
	Path     string `json:"path"`
}

Attachment represents a single attachment from BitBucket export.

type Client added in v0.18.0

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

Client is a minimal Bitbucket Cloud API v2 client for repository webhooks.

func NewClient added in v0.18.0

func NewClient(baseURL string, httpClient *http.Client) *Client

NewClient creates a Client for the given API base URL and HTTP client. An empty baseURL selects DefaultBaseURL; a trailing slash is normalized away. The HTTP client carries the request timeout, so it must not be a client without one.

func (*Client) CreateHook added in v0.18.0

func (c *Client) CreateHook(ctx context.Context, workspace, repoSlug, token string, input HookInput) (*Hook, error)

CreateHook registers a new repository webhook.

func (*Client) DeleteHook added in v0.18.0

func (c *Client) DeleteHook(ctx context.Context, workspace, repoSlug, hookUUID, token string) error

DeleteHook removes the repository webhook with the given uuid. The uuid is URL-escaped, including its braces.

func (*Client) ListHooks added in v0.18.0

func (c *Client) ListHooks(ctx context.Context, workspace, repoSlug, token string) ([]Hook, error)

ListHooks returns all repository webhooks, following each response's pagination next link up to maxListPages page requests. An absolute next link is only followed when it stays on the configured API origin.

func (*Client) UpdateHook added in v0.18.0

func (c *Client) UpdateHook(
	ctx context.Context,
	workspace, repoSlug, hookUUID, token string,
	input HookInput,
) (*Hook, error)

UpdateHook updates the repository webhook with the given uuid. The uuid is URL-escaped, including its braces.

type Comment

type Comment struct {
	ID        int        `json:"id"`
	Issue     int        `json:"issue"`
	User      User       `json:"user"`
	Content   string     `json:"content"`
	CreatedOn time.Time  `json:"created_on"`
	UpdatedOn *time.Time `json:"updated_on"`
}

Comment represents a comment from BitBucket export.

type Event added in v0.18.0

type Event string

Event is a Bitbucket Cloud webhook event key, as used in the events array of a repository webhook subscription and in delivered event payloads.

const (
	EventRepoPush                 Event = "repo:push"
	EventRepoFork                 Event = "repo:fork"
	EventRepoUpdated              Event = "repo:updated"
	EventRepoCommitCommentCreated Event = "repo:commit_comment_created"
	EventRepoCommitStatusCreated  Event = "repo:commit_status_created"
	EventRepoCommitStatusUpdated  Event = "repo:commit_status_updated"
)

Repository events.

const (
	EventPullRequestCreated               Event = "pullrequest:created"
	EventPullRequestPush                  Event = "pullrequest:push"
	EventPullRequestUpdated               Event = "pullrequest:updated"
	EventPullRequestApproved              Event = "pullrequest:approved"
	EventPullRequestUnapproved            Event = "pullrequest:unapproved"
	EventPullRequestChangesRequestCreated Event = "pullrequest:changes_request_created"
	EventPullRequestChangesRequestRemoved Event = "pullrequest:changes_request_removed"
	EventPullRequestFulfilled             Event = "pullrequest:fulfilled"
	EventPullRequestRejected              Event = "pullrequest:rejected"
	EventPullRequestCommentCreated        Event = "pullrequest:comment_created"
	EventPullRequestCommentUpdated        Event = "pullrequest:comment_updated"
	EventPullRequestCommentDeleted        Event = "pullrequest:comment_deleted"
	EventPullRequestCommentResolved       Event = "pullrequest:comment_resolved"
	EventPullRequestCommentReopened       Event = "pullrequest:comment_reopened"
)

Pull request events.

const (
	EventIssueCreated        Event = "issue:created"
	EventIssueUpdated        Event = "issue:updated"
	EventIssueCommentCreated Event = "issue:comment_created"
)

Issue events.

const (
	EventPipelineSpanCreated Event = "pipeline:span_created"
)

Pipeline events.

type Export

type Export struct {
	Meta        map[string]any `json:"meta"`
	Issues      []Issue        `json:"issues"`
	Attachments []Attachment   `json:"attachments"`
	Comments    []Comment      `json:"comments"`
	Logs        []any          `json:"logs"`
}

Export represents the full JSON export structure.

type Hook added in v0.18.0

type Hook struct {
	UUID        string    `json:"uuid"`
	Description string    `json:"description"`
	URL         string    `json:"url"`
	Active      bool      `json:"active"`
	Secret      string    `json:"secret,omitempty"`
	Events      []Event   `json:"events"`
	CreatedOn   time.Time `json:"created_on"`
	UpdatedOn   time.Time `json:"updated_on"`
}

Hook is a Bitbucket Cloud repository webhook as returned by the API v2 /repositories/{workspace}/{repo_slug}/hooks endpoints.

type HookInput added in v0.18.0

type HookInput struct {
	Description string  `json:"description"`
	URL         string  `json:"url"`
	Active      bool    `json:"active"`
	Secret      string  `json:"secret,omitempty"`
	Events      []Event `json:"events"`
}

HookInput is the payload for creating or updating a repository webhook. Secret is write-only: Bitbucket never returns it in responses.

type Issue

type Issue struct {
	ID        int       `json:"id"`
	Title     string    `json:"title"`
	Reporter  User      `json:"reporter"`
	Assignee  *User     `json:"assignee"`
	Content   string    `json:"content"`
	CreatedOn time.Time `json:"created_on"`
	UpdatedOn time.Time `json:"updated_on"`
	Status    string    `json:"status"`
	Priority  string    `json:"priority"`
	Kind      string    `json:"kind"`
	Milestone any       `json:"milestone"`
	Component any       `json:"component"`
	Version   any       `json:"version"`
	Watchers  []User    `json:"watchers"`
	Voters    []User    `json:"voters"`
}

Issue represents a single issue from BitBucket export.

type User

type User struct {
	DisplayName string `json:"display_name"`
	AccountID   string `json:"account_id"`
}

User represents a user in BitBucket export.

Jump to

Keyboard shortcuts

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