api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBasicAuthHeader

func AddBasicAuthHeader(rt http.RoundTripper, cfg tokenGetter) http.RoundTripper

AddBasicAuthHeader adds Basic Auth header for Bitbucket API requests. Bitbucket uses Basic Auth with username:app_password format.

func CurrentLoginName

func CurrentLoginName(client *Client, hostname string) (string, error)

CurrentLoginName returns the username of the currently authenticated user. Bitbucket API: GET /2.0/user

func ExtractHeader

func ExtractHeader(name string, dest *string) func(http.RoundTripper) http.RoundTripper

ExtractHeader extracts a named header from any response received by this client and, if non-blank, saves it to dest.

func HandleHTTPError

func HandleHTTPError(resp *http.Response) error

HandleHTTPError parses an HTTP response into an HTTPError.

func IsConflictError

func IsConflictError(err error) bool

IsConflictError checks if an error is a 409 Conflict error.

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError checks if an error is a 403 Forbidden error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error is a 404 Not Found error.

func IsUnauthorizedError

func IsUnauthorizedError(err error) bool

IsUnauthorizedError checks if an error is a 401 Unauthorized error.

func NewHTTPClient

func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error)

NewHTTPClient creates a new HTTP client configured for the Bitbucket API.

func RESTPrefix

func RESTPrefix(hostname string) string

RESTPrefix returns the REST API base URL for a hostname. This is exported for use by other packages.

Types

type Author

type Author struct {
	Raw  string `json:"raw"` // "Name <email>"
	User *User  `json:"user,omitempty"`
}

Author represents a commit author (may or may not be linked to a user).

type Branch

type Branch struct {
	Name   string  `json:"name"`
	Type   string  `json:"type"` // "branch", "named_branch"
	Target *Commit `json:"target,omitempty"`
	Links  Links   `json:"links"`
}

Branch represents a git branch.

type BranchRef

type BranchRef struct {
	Name string `json:"name"`
}

BranchRef represents a branch by name.

type Client

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

Client is a Bitbucket API client.

func NewClientFromHTTP

func NewClientFromHTTP(httpClient *http.Client) *Client

NewClientFromHTTP creates a new Client from an existing http.Client.

func (*Client) Delete

func (c *Client) Delete(hostname string, path string) error

Delete performs a DELETE request.

func (*Client) Get

func (c *Client) Get(hostname string, path string, data interface{}) error

Get performs a GET request and parses the response.

func (*Client) HTTP

func (c *Client) HTTP() *http.Client

HTTP returns the underlying http.Client.

func (*Client) Patch

func (c *Client) Patch(hostname string, path string, input interface{}, data interface{}) error

Patch performs a PATCH request with a JSON body.

func (*Client) Post

func (c *Client) Post(hostname string, path string, input interface{}, data interface{}) error

Post performs a POST request with a JSON body.

func (*Client) Put

func (c *Client) Put(hostname string, path string, input interface{}, data interface{}) error

Put performs a PUT request with a JSON body.

func (*Client) REST

func (c *Client) REST(hostname string, method string, path string, body io.Reader, data interface{}) error

REST performs a REST request and parses the response.

func (*Client) RESTWithContext

func (c *Client) RESTWithContext(ctx context.Context, hostname string, method string, path string, body io.Reader, data interface{}) error

RESTWithContext performs a REST request with a context.

func (*Client) RESTWithNext

func (c *Client) RESTWithNext(hostname string, method string, path string, body io.Reader, data interface{}) (string, error)

RESTWithNext performs a REST request and returns the next page URL from the response. This is used for Bitbucket's pagination which includes a "next" field in the response body.

func (*Client) RESTWithNextURL

func (c *Client) RESTWithNextURL(method string, url string, body io.Reader, data interface{}) (string, error)

RESTWithNextURL performs a REST request to a full URL and returns the next page URL.

func (*Client) RESTWithURL

func (c *Client) RESTWithURL(method string, url string, body io.Reader, data interface{}) error

RESTWithURL performs a REST request to a full URL and parses the response.

type CloneLink struct {
	Href string `json:"href"`
	Name string `json:"name"` // "https", "ssh"
}

CloneLink represents a clone URL.

type Commit

type Commit struct {
	Hash       string      `json:"hash"`
	Type       string      `json:"type"` // "commit"
	Message    string      `json:"message"`
	Author     Author      `json:"author"`
	Date       time.Time   `json:"date"`
	Parents    []Commit    `json:"parents,omitempty"`
	Repository *Repository `json:"repository,omitempty"`
	Links      Links       `json:"links"`
}

Commit represents a git commit.

type Component

type Component struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Links Links  `json:"links"`
}

Component represents an issue component.

type Content

type Content struct {
	Raw    string `json:"raw"`
	Markup string `json:"markup"` // "markdown", "creole", "plaintext"
	HTML   string `json:"html"`
}

Content represents the content of a comment.

type ContentInput

type ContentInput struct {
	Raw string `json:"raw"`
}

ContentInput represents content input for issues/comments.

type CreateIssueInput

type CreateIssueInput struct {
	Title    string        `json:"title"`
	Content  *ContentInput `json:"content,omitempty"`
	Kind     string        `json:"kind,omitempty"`     // "bug", "enhancement", "proposal", "task"
	Priority string        `json:"priority,omitempty"` // "trivial", "minor", "major", "critical", "blocker"
	Assignee *UserRef      `json:"assignee,omitempty"`
}

CreateIssueInput represents the input for creating an issue.

type CreateProjectInput

type CreateProjectInput struct {
	Name        string `json:"name"`
	Key         string `json:"key"`
	Description string `json:"description,omitempty"`
	IsPrivate   bool   `json:"is_private,omitempty"`
}

CreateProjectInput represents the input for creating a project.

type CreatePullRequestInput

type CreatePullRequestInput struct {
	Title             string                `json:"title"`
	Description       string                `json:"description,omitempty"`
	Source            CreatePullRequestRef  `json:"source"`
	Destination       *CreatePullRequestRef `json:"destination,omitempty"` // Optional, defaults to main branch
	CloseSourceBranch bool                  `json:"close_source_branch,omitempty"`
	Reviewers         []UserRef             `json:"reviewers,omitempty"`
}

CreatePullRequestInput represents the input for creating a pull request.

type CreatePullRequestRef

type CreatePullRequestRef struct {
	Branch BranchRef `json:"branch"`
}

CreatePullRequestRef represents a branch reference for PR creation.

type DeclinePullRequestInput

type DeclinePullRequestInput struct {
	Reason string `json:"reason,omitempty"`
}

DeclinePullRequestInput represents the input for declining a pull request.

type ErrorResponse

type ErrorResponse struct {
	Type  string `json:"type"` // "error"
	Error struct {
		Message string                 `json:"message"`
		Detail  string                 `json:"detail,omitempty"`
		Data    map[string]interface{} `json:"data,omitempty"`
	} `json:"error"`
}

ErrorResponse represents an error response from the Bitbucket API.

type HTTPClientOptions

type HTTPClientOptions struct {
	AppVersion         string
	CacheTTL           time.Duration
	Config             tokenGetter
	EnableCache        bool
	Log                io.Writer
	LogColorize        bool
	LogVerboseHTTP     bool
	SkipDefaultHeaders bool
}

HTTPClientOptions configures the HTTP client.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
	RequestURL *url.URL
	Body       string
}

HTTPError represents an HTTP error response from the Bitbucket API.

func (HTTPError) Error

func (e HTTPError) Error() string

type InlineComment

type InlineComment struct {
	From int    `json:"from,omitempty"`
	To   int    `json:"to,omitempty"`
	Path string `json:"path"`
}

InlineComment represents an inline comment position.

type Issue

type Issue struct {
	ID         int        `json:"id"`
	Title      string     `json:"title"`
	Content    Content    `json:"content"`
	State      string     `json:"state"`    // "new", "open", "resolved", "on hold", "invalid", "duplicate", "wontfix", "closed"
	Priority   string     `json:"priority"` // "trivial", "minor", "major", "critical", "blocker"
	Kind       string     `json:"kind"`     // "bug", "enhancement", "proposal", "task"
	Type       string     `json:"type"`     // "issue"
	Reporter   User       `json:"reporter"`
	Assignee   *User      `json:"assignee,omitempty"`
	Component  *Component `json:"component,omitempty"`
	Milestone  *Milestone `json:"milestone,omitempty"`
	Version    *Version   `json:"version,omitempty"`
	Votes      int        `json:"votes"`
	Watches    int        `json:"watches"`
	Repository Repository `json:"repository"`
	Links      Links      `json:"links"`
	CreatedOn  time.Time  `json:"created_on"`
	UpdatedOn  time.Time  `json:"updated_on"`
	EditedOn   *time.Time `json:"edited_on,omitempty"`
}

Issue represents a Bitbucket issue.

type IssueComment

type IssueComment struct {
	ID        int       `json:"id"`
	Type      string    `json:"type"` // "issue_comment"
	Content   Content   `json:"content"`
	User      User      `json:"user"`
	CreatedOn time.Time `json:"created_on"`
	UpdatedOn time.Time `json:"updated_on"`
	Links     Links     `json:"links"`
}

IssueComment represents a comment on an issue.

type Link struct {
	Href string `json:"href"`
	Name string `json:"name,omitempty"`
}

Link represents a single hypermedia link.

type Links struct {
	Self         *Link       `json:"self,omitempty"`
	HTML         *Link       `json:"html,omitempty"`
	Avatar       *Link       `json:"avatar,omitempty"`
	Clone        []CloneLink `json:"clone,omitempty"`
	Commits      *Link       `json:"commits,omitempty"`
	Watchers     *Link       `json:"watchers,omitempty"`
	Branches     *Link       `json:"branches,omitempty"`
	Tags         *Link       `json:"tags,omitempty"`
	Forks        *Link       `json:"forks,omitempty"`
	Downloads    *Link       `json:"downloads,omitempty"`
	PullRequests *Link       `json:"pullrequests,omitempty"`
	Issues       *Link       `json:"issues,omitempty"`
	Diff         *Link       `json:"diff,omitempty"`
	DiffStat     *Link       `json:"diffstat,omitempty"`
	Patch        *Link       `json:"patch,omitempty"`
	Comments     *Link       `json:"comments,omitempty"`
	Approve      *Link       `json:"approve,omitempty"`
	Merge        *Link       `json:"merge,omitempty"`
	Decline      *Link       `json:"decline,omitempty"`
	Activity     *Link       `json:"activity,omitempty"`
	Statuses     *Link       `json:"statuses,omitempty"`
}

Links represents hypermedia links in API responses.

type MergePullRequestInput

type MergePullRequestInput struct {
	CloseSourceBranch bool   `json:"close_source_branch,omitempty"`
	MergeStrategy     string `json:"merge_strategy,omitempty"` // "merge_commit", "squash", "fast_forward"
	Message           string `json:"message,omitempty"`
}

MergePullRequestInput represents the input for merging a pull request.

type Milestone

type Milestone struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Links Links  `json:"links"`
}

Milestone represents an issue milestone.

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Size     int    `json:"size"`
	Page     int    `json:"page"`
	PageLen  int    `json:"pagelen"`
	Next     string `json:"next,omitempty"`
	Previous string `json:"previous,omitempty"`
	Values   []T    `json:"values"`
}

PaginatedResponse represents a paginated response from the Bitbucket API. All list endpoints return this structure with a "values" array and pagination info.

type Participant

type Participant struct {
	User           User      `json:"user"`
	Role           string    `json:"role"` // "PARTICIPANT", "REVIEWER"
	Approved       bool      `json:"approved"`
	State          string    `json:"state"` // "approved", "changes_requested", null
	ParticipatedOn time.Time `json:"participated_on"`
}

Participant represents a participant in a pull request.

type Project

type Project struct {
	UUID        string    `json:"uuid"`
	Key         string    `json:"key"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	IsPrivate   bool      `json:"is_private"`
	Type        string    `json:"type"` // "project"
	Owner       Workspace `json:"owner"`
	Links       Links     `json:"links"`
	CreatedOn   time.Time `json:"created_on"`
	UpdatedOn   time.Time `json:"updated_on"`
}

Project represents a Bitbucket project within a workspace.

type PullRequest

type PullRequest struct {
	ID                int              `json:"id"`
	Title             string           `json:"title"`
	Description       string           `json:"description"`
	State             PullRequestState `json:"state"`
	Type              string           `json:"type"` // "pullrequest"
	Author            User             `json:"author"`
	Source            PullRequestRef   `json:"source"`
	Destination       PullRequestRef   `json:"destination"`
	MergeCommit       *Commit          `json:"merge_commit,omitempty"`
	CloseSourceBranch bool             `json:"close_source_branch"`
	ClosedBy          *User            `json:"closed_by,omitempty"`
	Reason            string           `json:"reason,omitempty"` // Decline reason
	CreatedOn         time.Time        `json:"created_on"`
	UpdatedOn         time.Time        `json:"updated_on"`
	Links             Links            `json:"links"`
	CommentCount      int              `json:"comment_count"`
	TaskCount         int              `json:"task_count"`
	Reviewers         []User           `json:"reviewers,omitempty"`
	Participants      []Participant    `json:"participants,omitempty"`
}

PullRequest represents a Bitbucket pull request.

type PullRequestComment

type PullRequestComment struct {
	ID        int                 `json:"id"`
	Type      string              `json:"type"` // "pullrequest_comment"
	Content   Content             `json:"content"`
	User      User                `json:"user"`
	CreatedOn time.Time           `json:"created_on"`
	UpdatedOn time.Time           `json:"updated_on"`
	Parent    *PullRequestComment `json:"parent,omitempty"`
	Inline    *InlineComment      `json:"inline,omitempty"`
	Links     Links               `json:"links"`
	Deleted   bool                `json:"deleted"`
	Pending   bool                `json:"pending"`
}

PullRequestComment represents a comment on a pull request.

type PullRequestRef

type PullRequestRef struct {
	Branch     Branch      `json:"branch"`
	Commit     Commit      `json:"commit"`
	Repository *Repository `json:"repository,omitempty"`
}

PullRequestRef represents a branch reference in a pull request.

type PullRequestState

type PullRequestState string

PullRequestState represents the state of a pull request.

const (
	PullRequestStateOpen       PullRequestState = "OPEN"
	PullRequestStateMerged     PullRequestState = "MERGED"
	PullRequestStateDeclined   PullRequestState = "DECLINED"
	PullRequestStateSuperseded PullRequestState = "SUPERSEDED"
)

type Repository

type Repository struct {
	UUID        string      `json:"uuid"`
	Name        string      `json:"name"`
	Slug        string      `json:"slug"`
	FullName    string      `json:"full_name"` // workspace/repo_slug
	Description string      `json:"description"`
	IsPrivate   bool        `json:"is_private"`
	ForkPolicy  string      `json:"fork_policy"` // "allow_forks", "no_public_forks", "no_forks"
	Language    string      `json:"language"`
	Type        string      `json:"type"` // "repository"
	Project     *Project    `json:"project,omitempty"`
	Workspace   Workspace   `json:"workspace"`
	Owner       User        `json:"owner"`
	MainBranch  *Branch     `json:"mainbranch,omitempty"`
	Parent      *Repository `json:"parent,omitempty"` // For forks
	Links       Links       `json:"links"`
	Size        int64       `json:"size"`
	CreatedOn   time.Time   `json:"created_on"`
	UpdatedOn   time.Time   `json:"updated_on"`
	SCM         string      `json:"scm"` // "git" or "hg"
	HasIssues   bool        `json:"has_issues"`
	HasWiki     bool        `json:"has_wiki"`
}

Repository represents a Bitbucket repository.

type User

type User struct {
	UUID        string `json:"uuid"`
	AccountID   string `json:"account_id"`
	Username    string `json:"username"`
	DisplayName string `json:"display_name"`
	Nickname    string `json:"nickname"`
	Type        string `json:"type"` // "user"
	Links       Links  `json:"links"`
}

User represents a Bitbucket user account.

func CurrentUser

func CurrentUser(client *Client, hostname string) (*User, error)

CurrentUser returns the full user object for the currently authenticated user. Bitbucket API: GET /2.0/user

type UserRef

type UserRef struct {
	UUID      string `json:"uuid,omitempty"`
	AccountID string `json:"account_id,omitempty"`
}

UserRef represents a user reference by UUID or account_id.

type Version

type Version struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Links Links  `json:"links"`
}

Version represents an issue version.

type Workspace

type Workspace struct {
	UUID    string `json:"uuid"`
	Name    string `json:"name"`
	Slug    string `json:"slug"`
	Type    string `json:"type"` // "workspace"
	Links   Links  `json:"links"`
	IsAdmin bool   `json:"is_admin,omitempty"`
}

Workspace represents a Bitbucket workspace (formerly team).

Jump to

Keyboard shortcuts

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