Documentation
¶
Index ¶
- func AddBasicAuthHeader(rt http.RoundTripper, cfg tokenGetter) http.RoundTripper
- func CurrentLoginName(client *Client, hostname string) (string, error)
- func ExtractHeader(name string, dest *string) func(http.RoundTripper) http.RoundTripper
- func HandleHTTPError(resp *http.Response) error
- func IsConflictError(err error) bool
- func IsForbiddenError(err error) bool
- func IsNotFoundError(err error) bool
- func IsUnauthorizedError(err error) bool
- func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error)
- func RESTPrefix(hostname string) string
- type Author
- type Branch
- type BranchRef
- type Client
- func (c *Client) Delete(hostname string, path string) error
- func (c *Client) Get(hostname string, path string, data interface{}) error
- func (c *Client) HTTP() *http.Client
- func (c *Client) Patch(hostname string, path string, input interface{}, data interface{}) error
- func (c *Client) Post(hostname string, path string, input interface{}, data interface{}) error
- func (c *Client) Put(hostname string, path string, input interface{}, data interface{}) error
- func (c *Client) REST(hostname string, method string, path string, body io.Reader, data interface{}) error
- func (c *Client) RESTWithContext(ctx context.Context, hostname string, method string, path string, ...) error
- func (c *Client) RESTWithNext(hostname string, method string, path string, body io.Reader, data interface{}) (string, error)
- func (c *Client) RESTWithNextURL(method string, url string, body io.Reader, data interface{}) (string, error)
- func (c *Client) RESTWithURL(method string, url string, body io.Reader, data interface{}) error
- type CloneLink
- type Commit
- type Component
- type Content
- type ContentInput
- type CreateIssueInput
- type CreateProjectInput
- type CreatePullRequestInput
- type CreatePullRequestRef
- type DeclinePullRequestInput
- type ErrorResponse
- type HTTPClientOptions
- type HTTPError
- type InlineComment
- type Issue
- type IssueComment
- type Link
- type Links
- type MergePullRequestInput
- type Milestone
- type PaginatedResponse
- type Participant
- type Project
- type PullRequest
- type PullRequestComment
- type PullRequestRef
- type PullRequestState
- type Repository
- type User
- type UserRef
- type Version
- type Workspace
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 ¶
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 ¶
HandleHTTPError parses an HTTP response into an HTTPError.
func IsConflictError ¶
IsConflictError checks if an error is a 409 Conflict error.
func IsForbiddenError ¶
IsForbiddenError checks if an error is a 403 Forbidden error.
func IsNotFoundError ¶
IsNotFoundError checks if an error is a 404 Not Found error.
func IsUnauthorizedError ¶
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 ¶
RESTPrefix returns the REST API base URL for a hostname. This is exported for use by other packages.
Types ¶
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 ¶
NewClientFromHTTP creates a new Client from an existing http.Client.
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.
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 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 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 Links ¶
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 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.
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.