bitbucket

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultOAuthCallbackPort = 8976

DefaultOAuthCallbackPort is the localhost port bbkt listens on for the OAuth authorization-code callback. A fixed port is required because Bitbucket validates the redirect_uri against the consumer's registered callback URL. Override at runtime with BBKT_OAUTH_CALLBACK_PORT if this port is in use.

Variables

This section is empty.

Functions

func APITokenLogin

func APITokenLogin(profileName string) error

APITokenLogin prompts the user for email + API Token and stores them.

func CredentialsPath

func CredentialsPath() (string, error)

CredentialsPath returns the path to the credentials file.

func FetchAccessibleWorkspaces

func FetchAccessibleWorkspaces(client *Client) []string

FetchAccessibleWorkspaces retrieves all workspace slugs the client can access.

func GetJSON

func GetJSON[T any](c *Client, path string) (*T, error)

GetJSON performs a GET and unmarshals the JSON response.

func GetLocalRepoInfo

func GetLocalRepoInfo() (workspace, repoSlug string, err error)

GetLocalRepoInfo attempts to parse the Bitbucket workspace and repo slug from the local git repository's remotes. It checks all remotes, prioritizing Bitbucket.

func OAuthLogin

func OAuthLogin(clientID, clientSecret, profileName string) error

OAuthLogin performs the Authorization Code Grant flow with a localhost callback. Opens the user's browser, waits for the callback, exchanges the code, and stores credentials.

func QueryEscape

func QueryEscape(s string) string

QueryEscape URL-encodes a string for use in paths.

func RefreshOAuth

func RefreshOAuth(creds *Credentials) error

RefreshOAuth uses the refresh token to get a new access token. Updates the Credentials in place and persists to disk.

func RemoveCredentials

func RemoveCredentials() error

RemoveCredentials deletes the stored credentials file.

func SaveProfile

func SaveProfile(creds *Credentials) error

SaveProfile saves a single credential under its ProfileName. If it is the first profile being saved, it is automatically marked as active.

func SaveProfileStore

func SaveProfileStore(store *ProfileStore) error

SaveProfileStore persists the entire ProfileStore to disk.

Types

type APIError

type APIError struct {
	Type  string `json:"type"`
	Error struct {
		Message string `json:"message"`
		Detail  string `json:"detail"`
	} `json:"error"`
}

APIError is the standard Bitbucket error response.

type AuthType

type AuthType string

AuthType distinguishes between credential storage methods.

const (
	AuthTypeAPIToken AuthType = "api_token"
	AuthTypeOAuth    AuthType = "oauth"
)

type Author

type Author struct {
	Raw  string `json:"raw"`
	User *User  `json:"user"`
}

Author represents a commit author.

type Branch

type Branch struct {
	Name   string  `json:"name"`
	Target *Commit `json:"target"`
	Type   string  `json:"type"`
	Links  Links   `json:"links"`
}

Branch represents a branch ref.

type Client

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

Client is the Bitbucket API v2.0 HTTP client.

func NewClient

func NewClient(username, password, token string) *Client

NewClient creates a Bitbucket API client. Provide either (username + password) for Basic Auth or token for Bearer Auth.

func NewClientFromCredentials

func NewClientFromCredentials(creds *Credentials) *Client

NewClientFromCredentials creates a client from stored credentials, preserving cached scopes.

func (*Client) ApprovePullRequest

func (c *Client) ApprovePullRequest(args PullRequestActionArgs) error

ApprovePullRequest approves a pull request.

func (*Client) CreateBranch

func (c *Client) CreateBranch(args CreateBranchArgs) (*Branch, error)

CreateBranch creates a new branch from a commit hash.

func (*Client) CreateIssue

func (c *Client) CreateIssue(args CreateIssueArgs) (*Issue, error)

CreateIssue creates a new issue.

func (*Client) CreatePRComment

func (c *Client) CreatePRComment(args CreatePRCommentArgs) (*PRComment, error)

CreatePRComment creates a comment on a pull request.

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(args CreatePullRequestArgs) (*PullRequest, error)

CreatePullRequest creates a new pull request.

func (*Client) CreateRepository

func (c *Client) CreateRepository(args CreateRepositoryArgs) (*Repository, error)

CreateRepository creates a new repository in a workspace.

func (*Client) CreateTag

func (c *Client) CreateTag(args CreateTagArgs) (*Tag, error)

CreateTag creates a new tag.

func (*Client) DeclinePullRequest

func (c *Client) DeclinePullRequest(args PullRequestActionArgs) error

DeclinePullRequest declines a pull request.

func (*Client) Delete

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

Delete performs a DELETE request.

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(args DeleteBranchArgs) error

DeleteBranch deletes a branch.

func (*Client) DeleteFile

func (c *Client) DeleteFile(args DeleteFileArgs) error

DeleteFile deletes a file from the repository.

func (*Client) DeletePRComment

func (c *Client) DeletePRComment(args CommentActionArgs) error

DeletePRComment deletes a comment on a pull request.

func (*Client) DeleteRepository

func (c *Client) DeleteRepository(args DeleteRepositoryArgs) error

DeleteRepository deletes a repository.

func (*Client) Get

func (c *Client) Get(path string) ([]byte, error)

Get performs a GET request and returns the response body.

func (*Client) GetCommit

func (c *Client) GetCommit(args GetCommitArgs) (*Commit, error)

GetCommit gets a single commit by hash.

func (*Client) GetDiff

func (c *Client) GetDiff(args GetDiffArgs) ([]byte, error)

GetDiff gets the diff between two revisions or for a single commit.

func (*Client) GetDiffStat

func (c *Client) GetDiffStat(args GetDiffStatArgs) (*Paginated[DiffStat], error)

GetDiffStat gets the diff stat for a revision spec.

func (*Client) GetFileContent

func (c *Client) GetFileContent(args GetFileContentArgs) (content []byte, contentType string, err error)

GetFileContent reads a file's content from the repository.

func (*Client) GetFileHistory

func (c *Client) GetFileHistory(args GetFileHistoryArgs) (*Paginated[json.RawMessage], error)

GetFileHistory gets the commit history for a specific file.

func (*Client) GetIssue

func (c *Client) GetIssue(args GetIssueArgs) (*Issue, error)

GetIssue gets details for a single issue.

func (*Client) GetPRDiff

func (c *Client) GetPRDiff(args PullRequestActionArgs) ([]byte, error)

GetPRDiff gets the diff for a pull request.

func (*Client) GetPRDiffStat

func (c *Client) GetPRDiffStat(args PullRequestActionArgs) (*Paginated[DiffStat], error)

GetPRDiffStat gets the diffstat for a pull request.

func (*Client) GetPipeline

func (c *Client) GetPipeline(args GetPipelineArgs) (*Pipeline, error)

GetPipeline gets details for a single pipeline run.

func (*Client) GetPipelineStepLog

func (c *Client) GetPipelineStepLog(args GetPipelineStepLogArgs) ([]byte, error)

GetPipelineStepLog gets the log output for a pipeline step.

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(args GetPullRequestArgs) (*PullRequest, error)

GetPullRequest gets details for a single pull request.

func (*Client) GetRaw

func (c *Client) GetRaw(path string) (data []byte, contentType string, err error)

GetRaw performs a GET and returns raw bytes (for file content, logs, etc.).

func (*Client) GetRepository

func (c *Client) GetRepository(args GetRepositoryArgs) (*Repository, error)

GetRepository gets details for a single repository.

func (*Client) GetWithScopes

func (c *Client) GetWithScopes(path string) (body []byte, scopes string, err error)

GetWithScopes performs a GET request and returns the response body and the x-oauth-scopes header.

func (*Client) GetWorkspace

func (c *Client) GetWorkspace(args GetWorkspaceArgs) (*Workspace, error)

GetWorkspace returns details for a single workspace.

func (*Client) ListBranches

func (c *Client) ListBranches(args ListBranchesArgs) (*Paginated[Branch], error)

ListBranches lists branches in a repository.

func (*Client) ListCommits

func (c *Client) ListCommits(args ListCommitsArgs) (*Paginated[Commit], error)

ListCommits lists commits for a repository or branch.

func (*Client) ListDirectory

func (c *Client) ListDirectory(args ListDirectoryArgs) (*Paginated[TreeEntry], error)

ListDirectory lists files and directories at a given path.

func (*Client) ListIssues

func (c *Client) ListIssues(args ListIssuesArgs) (*Paginated[Issue], error)

ListIssues lists issues for a repository.

func (*Client) ListPRComments

func (c *Client) ListPRComments(args ListPRCommentsArgs) (*Paginated[PRComment], error)

ListPRComments lists comments on a pull request.

func (*Client) ListPRCommits

func (c *Client) ListPRCommits(args PullRequestActionArgs) (*Paginated[Commit], error)

ListPRCommits lists commits in a pull request.

func (*Client) ListPipelineSteps

func (c *Client) ListPipelineSteps(args ListPipelineStepsArgs) (*Paginated[PipelineStep], error)

ListPipelineSteps lists steps in a pipeline.

func (*Client) ListPipelines

func (c *Client) ListPipelines(args ListPipelinesArgs) (*Paginated[Pipeline], error)

ListPipelines lists pipeline runs for a repository.

func (*Client) ListPullRequests

func (c *Client) ListPullRequests(args ListPullRequestsArgs) (*Paginated[PullRequest], error)

ListPullRequests lists pull requests for a repository.

func (*Client) ListRepositories

func (c *Client) ListRepositories(args ListRepositoriesArgs) (*Paginated[Repository], error)

ListRepositories lists repositories in a workspace.

func (*Client) ListTags

func (c *Client) ListTags(args ListTagsArgs) (*Paginated[Tag], error)

ListTags lists tags in a repository.

func (*Client) ListWorkspaces

func (c *Client) ListWorkspaces(args ListWorkspacesArgs) (*Paginated[Workspace], error)

ListWorkspaces returns workspaces for the authenticated user.

func (*Client) MergePullRequest

func (c *Client) MergePullRequest(args MergePullRequestArgs) (*PullRequest, error)

MergePullRequest merges a pull request.

func (*Client) Post

func (c *Client) Post(path string, body interface{}) ([]byte, error)

Post performs a POST request with a JSON body.

func (*Client) PostMultipart

func (c *Client) PostMultipart(path string, fields map[string]string, files map[string][]byte) ([]byte, error)

PostMultipart performs a POST request using multipart/form-data. It takes a map of form fields and a map of file fields (where key is the field name and value is the file content).

func (*Client) Put

func (c *Client) Put(path string, body interface{}) ([]byte, error)

Put performs a PUT request with a JSON body.

func (*Client) ResolvePRComment

func (c *Client) ResolvePRComment(args CommentActionArgs) error

ResolvePRComment resolves a comment thread.

func (*Client) Scopes

func (c *Client) Scopes() ([]string, error)

Scopes dynamically fetches and returns the token scopes by calling the API if not already cached.

func (*Client) SearchCode

func (c *Client) SearchCode(args SearchCodeArgs) ([]byte, error)

SearchCode searches for code in a repository using Bitbucket's code search.

func (*Client) StopPipeline

func (c *Client) StopPipeline(args StopPipelineArgs) error

StopPipeline stops a running pipeline.

func (*Client) TriggerPipeline

func (c *Client) TriggerPipeline(args TriggerPipelineArgs) (*Pipeline, error)

TriggerPipeline triggers a new pipeline run.

func (*Client) UnapprovePullRequest

func (c *Client) UnapprovePullRequest(args PullRequestActionArgs) error

UnapprovePullRequest removes approval from a pull request.

func (*Client) UnresolvePRComment

func (c *Client) UnresolvePRComment(args CommentActionArgs) error

UnresolvePRComment reopens a resolved comment thread.

func (*Client) UpdateIssue

func (c *Client) UpdateIssue(args UpdateIssueArgs) (*Issue, error)

UpdateIssue updates an existing issue.

func (*Client) UpdatePRComment

func (c *Client) UpdatePRComment(args UpdatePRCommentArgs) (*PRComment, error)

UpdatePRComment updates an existing comment.

func (*Client) UpdatePullRequest

func (c *Client) UpdatePullRequest(args UpdatePullRequestArgs) (*PullRequest, error)

UpdatePullRequest updates an existing pull request.

func (*Client) WriteFile

func (c *Client) WriteFile(args WriteFileArgs) error

WriteFile writes or updates a file in the repository.

type CommentActionArgs

type CommentActionArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
	CommentID int    `json:"comment_id" jsonschema:"Comment ID"`
}

type Commit

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

Commit represents a single commit.

type Content

type Content struct {
	Raw    string `json:"raw"`
	Markup string `json:"markup,omitempty"`
	HTML   string `json:"html,omitempty"`
}

Content represents rich content with raw/markup/html.

type CreateBranchArgs

type CreateBranchArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Name      string `json:"name" jsonschema:"Branch name"`
	Target    string `json:"target" jsonschema:"Target commit hash to branch from"`
}

type CreateBranchRequest

type CreateBranchRequest struct {
	Name   string            `json:"name"`
	Target map[string]string `json:"target"`
}

CreateBranchRequest is the body for creating a branch.

type CreateCommentRequest

type CreateCommentRequest struct {
	Content Content    `json:"content"`
	Inline  *Inline    `json:"inline,omitempty"`
	Parent  *ParentRef `json:"parent,omitempty"`
}

CreateCommentRequest is the body for creating a PR comment.

type CreateIssueArgs

type CreateIssueArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Title     string `json:"title" jsonschema:"Title of the issue"`
	Content   string `json:"content,omitempty" jsonschema:"Description of the issue (markdown)"`
	Kind      string `json:"kind,omitempty" jsonschema:"Kind: bug, enhancement, proposal, task (default: bug)"`
	Priority  string `json:"priority,omitempty" jsonschema:"Priority: trivial, minor, major, critical, blocker (default: major)"`
	Assignee  string `json:"assignee,omitempty" jsonschema:"Assignee account ID"`
}

type CreatePRCommentArgs

type CreatePRCommentArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
	Content   string `json:"content" jsonschema:"Markdown content of the comment"`
	FilePath  string `json:"file_path,omitempty" jsonschema:"File path for inline comments"`
	LineTo    int    `json:"line_to,omitempty" jsonschema:"Line number the comment applies to (for new/modified lines)"`
	LineFrom  int    `json:"line_from,omitempty" jsonschema:"Line number the comment applies to (for deleted lines)"`
	ParentID  int    `json:"parent_id,omitempty" jsonschema:"Parent comment ID to reply to"`
}

type CreatePRRequest

type CreatePRRequest struct {
	Title             string     `json:"title"`
	Description       string     `json:"description,omitempty"`
	Source            PREndpoint `json:"source"`
	Destination       PREndpoint `json:"destination,omitempty"`
	CloseSourceBranch bool       `json:"close_source_branch,omitempty"`
	Reviewers         []User     `json:"reviewers,omitempty"`
	Draft             bool       `json:"draft,omitempty"`
}

CreatePRRequest is the body for creating a pull request.

type CreatePullRequestArgs

type CreatePullRequestArgs struct {
	Workspace         string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug          string `json:"repo_slug" jsonschema:"Repository slug"`
	Title             string `json:"title" jsonschema:"Title of the pull request"`
	SourceBranch      string `json:"source_branch" jsonschema:"Source branch name"`
	DestinationBranch string `json:"destination_branch,omitempty" jsonschema:"Destination branch name (optional, defaults to repo default)"`
	Description       string `json:"description,omitempty" jsonschema:"Description of the pull request"`
	CloseSourceBranch bool   `json:"close_source_branch,omitempty" jsonschema:"Close source branch on merge"`
	Draft             bool   `json:"draft,omitempty" jsonschema:"Create as a draft PR"`
}

type CreateRepositoryArgs

type CreateRepositoryArgs struct {
	Workspace   string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug    string `json:"repo_slug" jsonschema:"Repository slug (URL-friendly name)"`
	Description string `json:"description,omitempty" jsonschema:"Repository description"`
	Language    string `json:"language,omitempty" jsonschema:"Primary programming language"`
	IsPrivate   *bool  `json:"is_private,omitempty" jsonschema:"Whether the repo is private (default true)"`
	ProjectKey  string `json:"project_key,omitempty" jsonschema:"Project key to assign the repo to"`
}

type CreateTagArgs

type CreateTagArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Name      string `json:"name" jsonschema:"Tag name"`
	Target    string `json:"target" jsonschema:"Target commit hash"`
}

type Credentials

type Credentials struct {
	ProfileName string    `json:"-"`
	AuthType    AuthType  `json:"auth_type"`
	CreatedAt   time.Time `json:"created_at"`

	// API Token fields (auth_type=api_token)
	Email    string `json:"email,omitempty"`
	APIToken string `json:"api_token,omitempty"`

	// OAuth fields (auth_type=oauth)
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Scopes       string `json:"scopes,omitempty"`
	ClientID     string `json:"client_id,omitempty"`
	ClientSecret string `json:"client_secret,omitempty"`

	// Derived cache data
	AccessibleWorkspaces []string `json:"accessible_workspaces,omitempty"`
}

Credentials holds persisted authentication data. Supports both API Token (Basic Auth) and OAuth 2.0 (Bearer Auth).

func LoadCredentials

func LoadCredentials() (*Credentials, error)

LoadCredentials gets the active credential profile based on context. Priority: 1. BBKT_PROFILE environment variable (or --profile CLI flag equivalent) 2. Exact match of local `git config user.email` to a profile's email 3. The configured 'ActiveProfile' in credentials.json

func (*Credentials) IsAPIToken

func (c *Credentials) IsAPIToken() bool

IsAPIToken returns true if these credentials use an API token.

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

IsExpired returns true if OAuth access token is expired (with 5 min buffer).

func (*Credentials) IsOAuth

func (c *Credentials) IsOAuth() bool

IsOAuth returns true if these credentials use OAuth.

type DeleteBranchArgs

type DeleteBranchArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Name      string `json:"name" jsonschema:"Branch name to delete"`
}

type DeleteFileArgs

type DeleteFileArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Path      string `json:"path" jsonschema:"Path to the file to delete"`
	Message   string `json:"message" jsonschema:"Commit message"`
	Branch    string `json:"branch,omitempty" jsonschema:"Branch to commit to"`
	Author    string `json:"author,omitempty" jsonschema:"Commit author in 'Name <email>' format"`
}

type DeleteRepositoryArgs

type DeleteRepositoryArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
}

type DiffStat

type DiffStat struct {
	Status       string       `json:"status"`
	LinesAdded   int          `json:"lines_added"`
	LinesRemoved int          `json:"lines_removed"`
	Old          *DiffStatRef `json:"old"`
	New          *DiffStatRef `json:"new"`
	Type         string       `json:"type"`
}

DiffStat represents a single file diff stat.

type DiffStatRef

type DiffStatRef struct {
	Path string `json:"path"`
	Type string `json:"type"`
}

DiffStatRef is a path reference in a diffstat.

type GetCommitArgs

type GetCommitArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Commit    string `json:"commit" jsonschema:"Commit hash"`
}

type GetDiffArgs

type GetDiffArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Spec      string `json:"spec" jsonschema:"Diff spec: single commit hash or 'hash1..hash2'"`
	Path      string `json:"path,omitempty" jsonschema:"Filter diff to this file path"`
}

type GetDiffStatArgs

type GetDiffStatArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Spec      string `json:"spec" jsonschema:"Diff spec: single commit hash or 'hash1..hash2'"`
}

type GetFileContentArgs

type GetFileContentArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Path      string `json:"path" jsonschema:"Path to the file"`
	Ref       string `json:"ref,omitempty" jsonschema:"Commit hash, branch, or tag (default: HEAD)"`
}

type GetFileHistoryArgs

type GetFileHistoryArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Path      string `json:"path" jsonschema:"Path to the file"`
	Ref       string `json:"ref,omitempty" jsonschema:"Commit hash, branch, or tag (default: HEAD)"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page (default: 25)"`
}

type GetIssueArgs

type GetIssueArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	IssueID   int    `json:"issue_id" jsonschema:"Issue ID"`
}

type GetPipelineArgs

type GetPipelineArgs struct {
	Workspace    string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug     string `json:"repo_slug" jsonschema:"Repository slug"`
	PipelineUUID string `json:"pipeline_uuid" jsonschema:"Pipeline UUID"`
}

type GetPipelineStepLogArgs

type GetPipelineStepLogArgs struct {
	Workspace    string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug     string `json:"repo_slug" jsonschema:"Repository slug"`
	PipelineUUID string `json:"pipeline_uuid" jsonschema:"Pipeline UUID"`
	StepUUID     string `json:"step_uuid" jsonschema:"Step UUID"`
}

type GetPullRequestArgs

type GetPullRequestArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
}

type GetRepositoryArgs

type GetRepositoryArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
}

type GetWorkspaceArgs

type GetWorkspaceArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug or UUID"`
}

type Inline

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

Inline represents inline comment location.

type Issue

type Issue struct {
	ID        int       `json:"id"`
	Title     string    `json:"title"`
	Content   Content   `json:"content"`
	State     string    `json:"state"`
	Priority  string    `json:"priority"`
	Kind      string    `json:"kind"`
	Assignee  *User     `json:"assignee,omitempty"`
	Reporter  *User     `json:"reporter,omitempty"`
	CreatedOn time.Time `json:"created_on"`
	UpdatedOn time.Time `json:"updated_on"`
	Votes     int       `json:"votes"`
	Watches   int       `json:"watches"`
	Links     Links     `json:"links"`
}

Issue represents a Bitbucket issue.

type Links map[string]interface{}

Links is a map of link objects.

type ListBranchesArgs

type ListBranchesArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
	Query     string `json:"query,omitempty" jsonschema:"Filter query"`
	Sort      string `json:"sort,omitempty" jsonschema:"Sort field"`
}

type ListCommitsArgs

type ListCommitsArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Revision  string `json:"revision,omitempty" jsonschema:"Branch name or commit hash to list commits for"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
	Include   string `json:"include,omitempty" jsonschema:"Include commits reachable from this ref"`
	Exclude   string `json:"exclude,omitempty" jsonschema:"Exclude commits reachable from this ref"`
	Path      string `json:"path,omitempty" jsonschema:"Filter commits that touch this file path"`
}

type ListDirectoryArgs

type ListDirectoryArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Path      string `json:"path,omitempty" jsonschema:"Path to the directory"`
	Ref       string `json:"ref,omitempty" jsonschema:"Commit hash, branch, or tag (default: HEAD)"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page (default: 100)"`
	MaxDepth  int    `json:"max_depth,omitempty" jsonschema:"Maximum depth of recursion (default: 1)"`
}

type ListIssuesArgs

type ListIssuesArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	State     string `json:"state,omitempty" jsonschema:"Filter by state (new, open, resolved, on hold, invalid, duplicate, wontfix, closed)"`
	Kind      string `json:"kind,omitempty" jsonschema:"Filter by kind (bug, enhancement, proposal, task)"`
	Priority  string `json:"priority,omitempty" jsonschema:"Filter by priority (trivial, minor, major, critical, blocker)"`
	Search    string `json:"search,omitempty" jsonschema:"Search query"`
	Sort      string `json:"sort,omitempty" jsonschema:"Sort field"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
}

type ListPRCommentsArgs

type ListPRCommentsArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page (default 50)"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
}

type ListPipelineStepsArgs

type ListPipelineStepsArgs struct {
	Workspace    string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug     string `json:"repo_slug" jsonschema:"Repository slug"`
	PipelineUUID string `json:"pipeline_uuid" jsonschema:"Pipeline UUID"`
}

type ListPipelinesArgs

type ListPipelinesArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
	Sort      string `json:"sort,omitempty" jsonschema:"Sort field (default -created_on)"`
	Status    string `json:"status,omitempty" jsonschema:"Filter by status"`
}

type ListPullRequestsArgs

type ListPullRequestsArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	State     string `json:"state,omitempty" jsonschema:"Filter by state (MERGED, SUPERSEDED, OPEN, DECLINED, default OPEN)"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
	Query     string `json:"query,omitempty" jsonschema:"Filter query"`
}

type ListRepositoriesArgs

type ListRepositoriesArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page (default 25)"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
	Query     string `json:"query,omitempty" jsonschema:"Bitbucket query filter (e.g. name~'myrepo')"`
	Role      string `json:"role,omitempty" jsonschema:"Filter by role: owner, admin, contributor, member"`
	Sort      string `json:"sort,omitempty" jsonschema:"Sort field (e.g. -updated_on)"`
}

type ListTagsArgs

type ListTagsArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Pagelen   int    `json:"pagelen,omitempty" jsonschema:"Results per page"`
	Page      int    `json:"page,omitempty" jsonschema:"Page number"`
}

type ListWorkspacesArgs

type ListWorkspacesArgs struct {
	Pagelen int `json:"pagelen,omitempty" jsonschema:"Number of results per page (default 25, max 100)"`
	Page    int `json:"page,omitempty" jsonschema:"Page number (1-based)"`
}

type MergePRRequest

type MergePRRequest struct {
	Type              string `json:"type,omitempty"`
	Message           string `json:"message,omitempty"`
	CloseSourceBranch bool   `json:"close_source_branch,omitempty"`
	MergeStrategy     string `json:"merge_strategy,omitempty"`
}

MergePRRequest is the body for merging a pull request.

type MergePullRequestArgs

type MergePullRequestArgs struct {
	Workspace         string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug          string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID              int    `json:"pr_id" jsonschema:"Pull request ID"`
	CloseSourceBranch bool   `json:"close_source_branch,omitempty" jsonschema:"Close source branch"`
	MergeStrategy     string `json:"merge_strategy,omitempty" jsonschema:"Merge strategy (e.g. merge_commit, squash, fast_forward, default: merge_commit)"`
	Message           string `json:"message,omitempty" jsonschema:"Commit message"`
}

type MinRepo

type MinRepo struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	FullName string `json:"full_name"`
	Type     string `json:"type"`
}

MinRepo is a minimal repository reference used in nested objects.

type PRComment

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

PRComment represents a comment on a PR.

type PREndpoint

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

PREndpoint represents a PR source or destination.

type Paginated

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

Paginated is the standard Bitbucket pagination envelope.

func GetPaginated

func GetPaginated[T any](c *Client, path string) (*Paginated[T], error)

GetPaginated performs a GET and unmarshals the paginated response.

type ParentRef

type ParentRef struct {
	ID int `json:"id"`
}

ParentRef points to a parent comment.

type Participant

type Participant struct {
	User     *User  `json:"user"`
	Role     string `json:"role"`
	Approved bool   `json:"approved"`
	State    string `json:"state"`
}

Participant represents a PR participant.

type PipeResult

type PipeResult struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

PipeResult is the pipeline result.

type PipeStage

type PipeStage struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

PipeStage is the pipeline stage.

type PipeState

type PipeState struct {
	Name   string      `json:"name"`
	Type   string      `json:"type"`
	Result *PipeResult `json:"result"`
	Stage  *PipeStage  `json:"stage"`
}

PipeState is the pipeline state.

type PipeTarget

type PipeTarget struct {
	Type    string `json:"type"`
	RefType string `json:"ref_type"`
	RefName string `json:"ref_name"`
}

PipeTarget is the pipeline target.

type PipeTriggerTarget

type PipeTriggerTarget struct {
	Type     string            `json:"type"`
	RefType  string            `json:"ref_type"`
	RefName  string            `json:"ref_name"`
	Selector *PipelineSelector `json:"selector,omitempty"`
}

PipeTriggerTarget specifies the pipeline trigger target.

type Pipeline

type Pipeline struct {
	UUID         string      `json:"uuid"`
	BuildNumber  int         `json:"build_number"`
	State        *PipeState  `json:"state"`
	Target       *PipeTarget `json:"target"`
	Creator      *User       `json:"creator"`
	CreatedOn    time.Time   `json:"created_on"`
	CompletedOn  *time.Time  `json:"completed_on"`
	DurationSecs int         `json:"duration_in_seconds"`
	TriggerName  string      `json:"trigger_name"`
	Links        Links       `json:"links"`
}

Pipeline represents a pipeline run.

type PipelineSelector

type PipelineSelector struct {
	Type    string `json:"type"`
	Pattern string `json:"pattern"`
}

PipelineSelector for custom pipelines.

type PipelineStep

type PipelineStep struct {
	UUID         string     `json:"uuid"`
	State        *PipeState `json:"state"`
	Name         string     `json:"name"`
	StartedOn    *time.Time `json:"started_on"`
	CompletedOn  *time.Time `json:"completed_on"`
	DurationSecs int        `json:"duration_in_seconds"`
	Links        Links      `json:"links"`
}

PipelineStep represents a single step in a pipeline.

type PipelineVariable

type PipelineVariable struct {
	Key     string `json:"key"`
	Value   string `json:"value"`
	Secured bool   `json:"secured"`
}

PipelineVariable represents a pipeline variable.

type ProfileStore

type ProfileStore struct {
	ActiveProfile string                  `json:"active_profile"`
	Profiles      map[string]*Credentials `json:"profiles"`
}

ProfileStore holds multiple authentication profiles

func LoadProfileStore

func LoadProfileStore() (*ProfileStore, error)

LoadProfileStore reads the persisted profile store from disk. It automatically migrates older single-credential files to the new ProfileStore format.

type Project

type Project struct {
	UUID string `json:"uuid"`
	Key  string `json:"key"`
	Name string `json:"name"`
	Type string `json:"type"`
}

Project represents a Bitbucket project.

type PullRequest

type PullRequest struct {
	ID                int           `json:"id"`
	Title             string        `json:"title"`
	Description       string        `json:"description"`
	State             string        `json:"state"`
	Source            PREndpoint    `json:"source"`
	Destination       PREndpoint    `json:"destination"`
	Author            *User         `json:"author"`
	Reviewers         []User        `json:"reviewers"`
	Participants      []Participant `json:"participants"`
	MergeCommit       *Commit       `json:"merge_commit"`
	CloseSourceBranch bool          `json:"close_source_branch"`
	CommentCount      int           `json:"comment_count"`
	TaskCount         int           `json:"task_count"`
	Draft             bool          `json:"draft"`
	CreatedOn         time.Time     `json:"created_on"`
	UpdatedOn         time.Time     `json:"updated_on"`
	Links             Links         `json:"links"`
}

PullRequest represents a pull request.

type PullRequestActionArgs

type PullRequestActionArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
}

type Repository

type Repository struct {
	UUID        string    `json:"uuid"`
	Name        string    `json:"name"`
	Slug        string    `json:"slug"`
	FullName    string    `json:"full_name"`
	Description string    `json:"description"`
	IsPrivate   bool      `json:"is_private"`
	Language    string    `json:"language"`
	SCM         string    `json:"scm"`
	Size        int64     `json:"size"`
	MainBranch  *Branch   `json:"mainbranch"`
	Owner       *User     `json:"owner"`
	Project     *Project  `json:"project"`
	CreatedOn   time.Time `json:"created_on"`
	UpdatedOn   time.Time `json:"updated_on"`
	Links       Links     `json:"links"`
}

Repository represents a Bitbucket repository.

type SearchCodeArgs

type SearchCodeArgs struct {
	Workspace   string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug    string `json:"repo_slug" jsonschema:"Repository slug"`
	SearchQuery string `json:"query" jsonschema:"Search query"`
	Pagelen     int    `json:"pagelen,omitempty" jsonschema:"Results per page (default: 25)"`
	Page        int    `json:"page,omitempty" jsonschema:"Page number"`
}

type StopPipelineArgs

type StopPipelineArgs struct {
	Workspace    string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug     string `json:"repo_slug" jsonschema:"Repository slug"`
	PipelineUUID string `json:"pipeline_uuid" jsonschema:"Pipeline UUID to stop"`
}

type Tag

type Tag struct {
	Name   string  `json:"name"`
	Target *Commit `json:"target"`
	Type   string  `json:"type"`
	Links  Links   `json:"links"`
}

Tag represents a tag ref.

type TreeEntry

type TreeEntry struct {
	Path       string   `json:"path"`
	Type       string   `json:"type"` // commit_file or commit_directory
	Size       int64    `json:"size"`
	Commit     *Commit  `json:"commit"`
	Attributes []string `json:"attributes"`
	Links      Links    `json:"links"`
}

TreeEntry is a file or directory in the source tree.

type TriggerPipelineArgs

type TriggerPipelineArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	RefName   string `json:"ref_name" jsonschema:"Branch or tag name to run pipeline on"`
	RefType   string `json:"ref_type,omitempty" jsonschema:"Reference type: branch or tag (default branch)"`
	Pattern   string `json:"pattern,omitempty" jsonschema:"Custom pipeline pattern name to trigger"`
}

type TriggerPipelineRequest

type TriggerPipelineRequest struct {
	Target    PipeTriggerTarget  `json:"target"`
	Variables []PipelineVariable `json:"variables,omitempty"`
}

TriggerPipelineRequest is the body for triggering a pipeline.

type UpdateIssueArgs

type UpdateIssueArgs struct {
	Workspace string  `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string  `json:"repo_slug" jsonschema:"Repository slug"`
	IssueID   int     `json:"issue_id" jsonschema:"Issue ID"`
	Title     *string `json:"title,omitempty" jsonschema:"New title"`
	Content   *string `json:"content,omitempty" jsonschema:"New description"`
	State     *string `json:"state,omitempty" jsonschema:"New state (new, open, resolved, on hold, invalid, duplicate, wontfix, closed)"`
	Kind      *string `json:"kind,omitempty" jsonschema:"New kind"`
	Priority  *string `json:"priority,omitempty" jsonschema:"New priority"`
	Assignee  *string `json:"assignee,omitempty" jsonschema:"New assignee account ID (or empty string to unassign)"`
}

type UpdatePRCommentArgs

type UpdatePRCommentArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	PRID      int    `json:"pr_id" jsonschema:"Pull request ID"`
	CommentID int    `json:"comment_id" jsonschema:"Comment ID to update"`
	Content   string `json:"content" jsonschema:"New markdown content"`
}

type UpdatePullRequestArgs

type UpdatePullRequestArgs struct {
	Workspace   string  `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug    string  `json:"repo_slug" jsonschema:"Repository slug"`
	PRID        int     `json:"pr_id" jsonschema:"Pull request ID"`
	Title       *string `json:"title,omitempty" jsonschema:"New title for the pull request"`
	Description *string `json:"description,omitempty" jsonschema:"New description for the pull request"`
}

type User

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

User represents a Bitbucket user.

type Workspace

type Workspace struct {
	UUID      string `json:"uuid"`
	Name      string `json:"name"`
	Slug      string `json:"slug"`
	IsPrivate bool   `json:"is_private"`
	Type      string `json:"type"`
	Links     Links  `json:"links"`
}

Workspace represents a Bitbucket workspace.

type WriteFileArgs

type WriteFileArgs struct {
	Workspace string `json:"workspace" jsonschema:"Workspace slug"`
	RepoSlug  string `json:"repo_slug" jsonschema:"Repository slug"`
	Path      string `json:"path" jsonschema:"Path to the file"`
	Content   string `json:"content" jsonschema:"Content to write to the file"`
	Message   string `json:"message" jsonschema:"Commit message"`
	Branch    string `json:"branch,omitempty" jsonschema:"Branch to commit to"`
	Author    string `json:"author,omitempty" jsonschema:"Commit author in 'Name <email>' format"`
}

Jump to

Keyboard shortcuts

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