api

package
v1.77.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package api re-exports the HTTP middleware stack from api/internal/httpx so callers outside the api/ subtree (notably pkg/cmd/factory) can wrap their http.Client transports without needing access to the internal package.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetryPolicy = httpx.DefaultRetryPolicy

DefaultRetryPolicy is 3 attempts, 200 ms → 2 s, with jitter.

Functions

func WithRetry added in v1.34.0

func WithRetry(ctx context.Context, policy RetryPolicy) context.Context

WithRetry returns a new context carrying policy. Attach it to a request to enable retries through a transport produced by WrapTransport.

func WrapTransport added in v1.34.0

func WrapTransport(inner http.RoundTripper) http.RoundTripper

WrapTransport wraps inner with the httpx middleware stack (retry → ETag cache → rate limit). See api/internal/httpx for details.

Types

type AuthConfig

type AuthConfig struct {
	Token    string
	Username string
	Password string
}

AuthConfig holds credentials for one host.

type Client

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

Client wraps HTTPClient with auth injection and JSON helpers.

func NewClient

func NewClient(httpClient HTTPClient, baseURL string, auth AuthConfig) *Client

NewClient constructs a Client.

func (*Client) ApprovePR

func (c *Client) ApprovePR(project, slug string, id int) error

ApprovePR approves a PR on behalf of the authenticated user.

func (*Client) CreatePR

func (c *Client) CreatePR(project, slug string, input CreatePRInput) (PullRequest, error)

CreatePR creates a new pull request.

func (*Client) CreateRepo

func (c *Client) CreateRepo(project string, input CreateRepoInput) (Repository, error)

CreateRepo creates a new repository in project.

func (*Client) Delete

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

Delete sends a DELETE request to path.

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(project, slug, branch string) error

DeleteBranch deletes a branch in a repository.

func (*Client) DeleteRepo

func (c *Client) DeleteRepo(project, slug string) error

DeleteRepo deletes a repository.

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() (User, error)

GetCurrentUser fetches the authenticated user.

func (*Client) GetJSON

func (c *Client) GetJSON(path string, v any) error

GetJSON GETs path and decodes JSON into v.

func (*Client) GetPR

func (c *Client) GetPR(project, slug string, id int) (PullRequest, error)

GetPR fetches a single pull request.

func (*Client) GetPRDiff

func (c *Client) GetPRDiff(project, slug string, id int) (string, error)

GetPRDiff fetches the unified diff for a PR.

func (*Client) GetRepo

func (c *Client) GetRepo(project, slug string) (Repository, error)

GetRepo fetches a single repository.

func (*Client) GetText

func (c *Client) GetText(path string) (string, error)

GetText GETs path and returns the raw body as a string.

func (*Client) ListPRs

func (c *Client) ListPRs(project, slug, state string, limit int) ([]PullRequest, error)

ListPRs lists pull requests for a repository.

func (*Client) ListRepos

func (c *Client) ListRepos(limit int) ([]Repository, error)

ListRepos lists repositories accessible to the authenticated user.

func (*Client) MergePR

func (c *Client) MergePR(project, slug string, id int, input MergePRInput) (PullRequest, error)

MergePR merges a pull request.

func (*Client) PostJSON

func (c *Client) PostJSON(path string, body any, v any) error

PostJSON POSTs body as JSON to path and decodes response into v.

func (*Client) PutJSON

func (c *Client) PutJSON(path string, body any, v any) error

PutJSON PUTs body as JSON to path and decodes response into v.

type CloneLink struct {
	Href string `json:"href"`
	Name string `json:"name"`
}

CloneLink is one clone URL entry.

type CreatePRInput

type CreatePRInput struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Draft       bool   `json:"draft,omitempty"`
	FromRef     PRRef  `json:"fromRef"`
	ToRef       PRRef  `json:"toRef"`
}

CreatePRInput is the request body for PR creation.

type CreateRepoInput

type CreateRepoInput struct {
	Name        string `json:"name"`
	ScmID       string `json:"scmId"`
	Public      bool   `json:"public"`
	Description string `json:"description,omitempty"`
}

CreateRepoInput is the request body for repo creation.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface for making HTTP requests.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
	RequestURL string
}

HTTPError represents a Bitbucket API error response.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type MergePRInput

type MergePRInput struct {
	Version  int    `json:"version"`
	Message  string `json:"message,omitempty"`
	Strategy string `json:"strategy,omitempty"`
}

MergePRInput is the request body for PR merge.

type PRLinks struct {
	Self []SelfLink `json:"self"`
}

PRLinks holds the PR web URL.

type PRParticipant

type PRParticipant struct {
	User     User   `json:"user"`
	Role     string `json:"role"`
	Approved bool   `json:"approved"`
}

PRParticipant is a PR author or reviewer.

type PRRef

type PRRef struct {
	ID         string     `json:"id"`
	DisplayID  string     `json:"displayId"`
	Repository Repository `json:"repository"`
}

PRRef is a branch reference in a PR.

type PagedResponse

type PagedResponse[T any] struct {
	Values        []T  `json:"values"`
	Size          int  `json:"size"`
	IsLastPage    bool `json:"isLastPage"`
	NextPageStart *int `json:"nextPageStart"`
	Start         int  `json:"start"`
}

PagedResponse is the Bitbucket paged list envelope.

type Project

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

Project is a Bitbucket project key+name.

type PullRequest

type PullRequest struct {
	ID          int             `json:"id"`
	Title       string          `json:"title"`
	Description string          `json:"description"`
	State       string          `json:"state"`
	Draft       bool            `json:"draft"`
	Author      PRParticipant   `json:"author"`
	Reviewers   []PRParticipant `json:"reviewers"`
	FromRef     PRRef           `json:"fromRef"`
	ToRef       PRRef           `json:"toRef"`
	Links       PRLinks         `json:"links"`
}

PullRequest represents a Bitbucket pull request.

type RepoLinks struct {
	Clone []CloneLink `json:"clone"`
	Self  []SelfLink  `json:"self"`
}

RepoLinks holds clone and web links.

type Repository

type Repository struct {
	ID      int       `json:"id"`
	Slug    string    `json:"slug"`
	Name    string    `json:"name"`
	Project Project   `json:"project"`
	ScmID   string    `json:"scmId"`
	State   string    `json:"state"`
	Public  bool      `json:"public"`
	Links   RepoLinks `json:"links"`
}

Repository represents a Bitbucket repository.

type RetryPolicy added in v1.34.0

type RetryPolicy = httpx.RetryPolicy

RetryPolicy is re-exported from api/internal/httpx so callers under pkg/cmd (which cannot import internal packages) can opt in to retry behaviour on a per-request basis via WithRetry.

type SelfLink struct {
	Href string `json:"href"`
}

SelfLink is a web UI link.

type User

type User struct {
	Slug        string `json:"slug"`
	DisplayName string `json:"displayName"`
}

User is a Bitbucket user.

Directories

Path Synopsis
Package cloud does not implement AdminClient.
Package cloud does not implement AdminClient.
gen
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.
internal
httpx
Package httpx is the shared HTTP transport used by the Bitbucket Server/DC and Cloud API adapters.
Package httpx is the shared HTTP transport used by the Bitbucket Server/DC and Cloud API adapters.
paging
Package paging bounds typed pagination above httpx.Transport.GetAllJSON.
Package paging bounds typed pagination above httpx.Transport.GetAllJSON.
Package server is the Bitbucket Data Center (a.k.a.
Package server is the Bitbucket Data Center (a.k.a.
gen
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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