bitbucket

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuildStatusInProgress = "INPROGRESS"
	BuildStatusSuccessful = "SUCCESSFUL"
	BuildStatusFailed     = "FAILED"
)
View Source
const (
	InsightReportPass = "PASS"
	InsightReportFail = "FAIL"
)

Variables

This section is empty.

Functions

func BuildStatusKey added in v0.15.0

func BuildStatusKey(preferredName, name string) string

BuildStatusKey returns the key to use for the Bitbucket build status.

Types

type Branch

type Branch struct {
	ID              string `json:"id"`
	DisplayID       string `json:"displayId"`
	Type            string `json:"type"`
	LatestCommit    string `json:"latestCommit"`
	LatestChangeset string `json:"latestChangeset"`
	IsDefault       bool   `json:"isDefault"`
}

type BranchClientInterface

type BranchClientInterface interface {
	BranchList(projectKey string, repositorySlug string, params BranchListParams) (*BranchPage, error)
}

type BranchListParams

type BranchListParams struct {
	// Base is the base branch or tag to compare each branch to (for the
	// metadata providers that uses that information).
	Base string `json:"base"`
	// Details controls whether to retrieve plugin-provided metadata about each branch.
	Details bool `json:"details"`
	// FilterText is the the text to match on. The match seems to be a prefix match.
	FilterText string `json:"filterText"`
	// OrderBy determines ordering of refs.
	// Either ALPHABETICAL (by name) or MODIFICATION (last updated).
	OrderBy string `json:"orderBy"`
	// BoostMatches controls whether exact and prefix matches will be boosted to the top
	BoostMatches bool `json:"boostMatches"`
}

type BranchPage

type BranchPage struct {
	Size       int      `json:"size"`
	Limit      int      `json:"limit"`
	IsLastPage bool     `json:"isLastPage"`
	Values     []Branch `json:"values"`
	Start      int      `json:"start"`
}

type BuildStatus

type BuildStatus struct {
	State       string `json:"state"`
	Key         string `json:"key"`
	Name        string `json:"name"`
	URL         string `json:"url"`
	Description string `json:"description"`
	DateAdded   int64  `json:"dateAdded"`
}

type BuildStatusCreatePayload

type BuildStatusCreatePayload struct {
	State       string `json:"state"`
	Key         string `json:"key"`
	Name        string `json:"name"`
	URL         string `json:"url"`
	Description string `json:"description"`
}

type BuildStatusPage

type BuildStatusPage struct {
	Size       int           `json:"size"`
	Limit      int           `json:"limit"`
	IsLastPage bool          `json:"isLastPage"`
	Values     []BuildStatus `json:"values"` // newest build status appears first
	Start      int           `json:"start"`
}

type Client

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

Loosely based on https://github.com/brandur/wanikaniapi.

func NewClient

func NewClient(clientConfig *ClientConfig) (*Client, error)

func (*Client) BranchList

func (c *Client) BranchList(projectKey string, repositorySlug string, params BranchListParams) (*BranchPage, error)

BranchList retrieves the branches matching the supplied filterText param. The authenticated user must have REPO_READ permission for the specified repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.14.0/bitbucket-rest.html#idp211

func (*Client) BuildStatusCreate

func (c *Client) BuildStatusCreate(gitCommit string, payload BuildStatusCreatePayload) error

BuildStatusCreate associates a build status with a commit. The state, the key and the url are mandatory. The name and description fields are optional. All fields (mandatory or optional) are limited to 255 characters, except for the url, which is limited to 450 characters. Supported values for the state are SUCCESSFUL, FAILED and INPROGRESS. The authenticated user must have LICENSED permission or higher to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-build-rest.html#idp6

func (*Client) BuildStatusList

func (c *Client) BuildStatusList(gitCommit string) (*BuildStatusPage, error)

BuildStatusList gets the build statuses associated with a commit. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-build-rest.html#idp8

func (*Client) CommitGet

func (c *Client) CommitGet(projectKey, repositorySlug, commitID string) (*Commit, error)

CommitGet etrieves a single commit identified by its ID. In general, that ID is a SHA1. From 2.11, ref names like "refs/heads/master" are no longer accepted by this resource. The authenticated user must have REPO_READ permission for the specified repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp224

func (*Client) CommitList

func (c *Client) CommitList(projectKey string, repositorySlug string, params CommitListParams) (*CommitPage, error)

CommitList retrieves a page of commits from a given starting commit or "between" two commits. If no explicit commit is specified, the tip of the repository's default branch is assumed. commits may be identified by branch or tag name or by ID. A path may be supplied to restrict the returned commits to only those which affect that path. The authenticated user must have REPO_READ permission for the specified repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp222

func (*Client) CommitPullRequestList

func (c *Client) CommitPullRequestList(projectKey, repositorySlug, commitID string) (*PullRequestPage, error)

CommitPullRequestList retrieves a page of pull requests in the current repository that contain the given commit. The user must be authenticated and have access to the specified repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp243

func (*Client) InsightReportCreate

func (c *Client) InsightReportCreate(projectKey, repositorySlug, commitID, key string, payload InsightReportCreatePayload) (*InsightReport, error)

InsightReportCreate creates a new insight report, or replace the existing one if a report already exists for the given repository, commit, and report key. A request to replace an existing report will be rejected if the authenticated user was not the creator of the specified report. The report key should be a unique string chosen by the reporter and should be unique enough not to potentially clash with report keys from other reporters. We recommend using reverse DNS namespacing or a similar standard to ensure that collision is avoided.

https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-code-insights-rest.html#idp9

func (*Client) ProjectCreate

func (c *Client) ProjectCreate(payload ProjectCreatePayload) (*Project, error)

ProjectCreate creates a new project. To include a custom avatar for the project, the project definition should contain an additional attribute with the key avatar and the value a data URI containing Base64-encoded image data. The URI should be in the following format:

data:(content type, e.g. image/png);base64,(data)

If the data is not Base64-encoded, or if a character set is defined in the URI, or the URI is otherwise invalid, project creation will fail. The authenticated user must have PROJECT_CREATE permission to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp148

func (*Client) RawGet

func (c *Client) RawGet(project, repository, filename, gitFullRef string) ([]byte, error)

RawGet retrieves the raw content for a file path at a specified revision. The authenticated user must have REPO_READ permission for the specified repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp359

func (*Client) RepoCreate

func (c *Client) RepoCreate(projectKey string, payload RepoCreatePayload) (*Repo, error)

RepoCreate creates a new repository. Requires an existing project in which this repository will be created. The only parameters which will be used are name and scmId. The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp174

func (*Client) RepoList

func (c *Client) RepoList(projectKey string) (*RepoPage, error)

RepoList retrieves repositories from the project corresponding to the supplied projectKey. The authenticated user must have REPO_READ permission for the context repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp175

func (*Client) TagCreate

func (c *Client) TagCreate(projectKey string, repositorySlug string, payload TagCreatePayload) (*Tag, error)

TagCreate creates a tag in the specified repository. The authenticated user must have an effective REPO_WRITE permission to call this resource.

'LIGHTWEIGHT' and 'ANNOTATED' are the two type of tags that can be created. The 'startPoint' can either be a ref or a 'commit'.

https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp395

func (*Client) TagGet

func (c *Client) TagGet(projectKey string, repositorySlug string, name string) (*Tag, error)

TagGet retrieves a tag in the specified repository.. The authenticated user must have REPO_READ permission for the context repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp398

func (*Client) TagList

func (c *Client) TagList(projectKey string, repositorySlug string, params TagListParams) (*TagPage, error)

TagList retrieves the tags matching the supplied filterText param. The authenticated user must have REPO_READ permission for the context repository to call this resource. https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp396

func (*Client) WebhookCreate

func (c *Client) WebhookCreate(projectKey, repositorySlug string, payload WebhookCreatePayload) (*Webhook, error)

type ClientConfig

type ClientConfig struct {
	Timeout    time.Duration
	APIToken   string
	HTTPClient *http.Client
	MaxRetries int
	BaseURL    string
	// Logger is the logger to send logging messages to.
	Logger logging.LeveledLoggerInterface
}

type Commit

type Commit struct {
	ID        string `json:"id"`
	DisplayID string `json:"displayId"`
	Author    struct {
		Name         string `json:"name"`
		EmailAddress string `json:"emailAddress"`
	} `json:"author"`
	AuthorTimestamp int64 `json:"authorTimestamp"`
	Committer       struct {
		Name         string `json:"name"`
		EmailAddress string `json:"emailAddress"`
	} `json:"committer"`
	CommitterTimestamp int64  `json:"committerTimestamp"`
	Message            string `json:"message"`
	Parents            []struct {
		ID        string `json:"id"`
		DisplayID string `json:"displayId"`
	} `json:"parents"`
}

type CommitClientInterface

type CommitClientInterface interface {
	CommitList(projectKey string, repositorySlug string, params CommitListParams) (*CommitPage, error)
	CommitGet(projectKey, repositorySlug, commitID string) (*Commit, error)
	CommitPullRequestList(projectKey, repositorySlug, commitID string) (*PullRequestPage, error)
}

type CommitListParams

type CommitListParams struct {
	Since string `json:"since"`
	Until string `json:"until"`
}

type CommitPage

type CommitPage struct {
	Size        int      `json:"size"`
	Limit       int      `json:"limit"`
	IsLastPage  bool     `json:"isLastPage"`
	Values      []Commit `json:"values"`
	Start       int      `json:"start"`
	AuthorCount int      `json:"authorCount"`
	TotalCount  int      `json:"totalCount"`
}

type InsightReport

type InsightReport struct {
	Data        []InsightReportData `json:"data"`
	CreatedDate int                 `json:"createdDate"`
	Details     string              `json:"details"`
	Key         string              `json:"key"`
	Link        string              `json:"link"`
	LogoURL     string              `json:"logoUrl"`
	Result      string              `json:"result"`
	Title       string              `json:"title"`
	Reporter    string              `json:"reporter"`
}

type InsightReportCreatePayload

type InsightReportCreatePayload struct {
	Data        []InsightReportData `json:"data"`
	Details     string              `json:"details,omitempty"`
	Title       string              `json:"title"`
	Reporter    string              `json:"reporter,omitempty"`
	CreatedDate int64               `json:"createdDate"`
	Link        string              `json:"link,omitempty"`
	LogoURL     string              `json:"logoUrl,omitempty"`
	Result      string              `json:"result,omitempty"`
}

type InsightReportData

type InsightReportData struct {
	Title string      `json:"title"`
	Value interface{} `json:"value"`
	Type  string      `json:"type"`
}

type Project

type Project struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	ID          int    `json:"id"`
	Description string `json:"description"`
	Public      bool   `json:"public"`
	Type        string `json:"type"`
	Links       struct {
		Self []struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"links"`
}

type ProjectCreatePayload

type ProjectCreatePayload struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Avatar      string `json:"avatar"`
}

type PullRequest

type PullRequest struct {
	ID          int    `json:"id"`
	Version     int    `json:"version"`
	Title       string `json:"title"`
	Description string `json:"description"`
	State       string `json:"state"`
	Open        bool   `json:"open"`
	Closed      bool   `json:"closed"`
	CreatedDate int    `json:"createdDate"`
	UpdatedDate int    `json:"updatedDate"`
	FromRef     Ref    `json:"fromRef"`
	ToRef       Ref    `json:"toRef"`
	Locked      bool   `json:"locked"`
	Author      struct {
		User     User   `json:"user"`
		Role     string `json:"role"`
		Approved bool   `json:"approved"`
		Status   string `json:"status"`
	} `json:"author"`
	Reviewers []struct {
		User               User   `json:"user"`
		LastReviewedCommit string `json:"lastReviewedCommit"`
		Role               string `json:"role"`
		Approved           bool   `json:"approved"`
		Status             string `json:"status"`
	} `json:"reviewers"`
	Participants []struct {
		User     User   `json:"user"`
		Role     string `json:"role"`
		Approved bool   `json:"approved"`
		Status   string `json:"status"`
	} `json:"participants"`
	Links struct {
		Self []struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"links"`
}

type PullRequestPage

type PullRequestPage struct {
	Size       int  `json:"size"`
	Limit      int  `json:"limit"`
	IsLastPage bool `json:"isLastPage"`
	Values     []PullRequest
	Start      int `json:"start"`
}

type RawClientInterface

type RawClientInterface interface {
	RawGet(project, repository, filename, gitFullRef string) ([]byte, error)
}

type Ref

type Ref struct {
	ID         string `json:"id"`
	Repository struct {
		Slug    string      `json:"slug"`
		Name    interface{} `json:"name"`
		Project struct {
			Key string `json:"key"`
		} `json:"project"`
	} `json:"repository"`
}

type Repo

type Repo struct {
	Slug          string  `json:"slug"`
	ID            int     `json:"id"`
	Name          string  `json:"name"`
	Description   string  `json:"description"`
	Hierarchyid   string  `json:"hierarchyId"`
	SCMID         string  `json:"scmId"`
	State         string  `json:"state"`
	StatusMessage string  `json:"statusMessage"`
	Forkable      bool    `json:"forkable"`
	Project       Project `json:"project"`
	Public        bool    `json:"public"`
	Links         struct {
		Clone []struct {
			Href string `json:"href"`
			Name string `json:"name"`
		} `json:"clone"`
		Self []struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"links"`
}

type RepoClientInterface

type RepoClientInterface interface {
	RepoList(projectKey string) (*RepoPage, error)
	RepoCreate(projectKey string, payload RepoCreatePayload) (*Repo, error)
}

type RepoCreatePayload

type RepoCreatePayload struct {
	SCMID         string `json:"scmId"`
	Name          string `json:"name"`
	Forkable      bool   `json:"forkable"`
	DefaultBranch string `json:"defaultBranch"`
}

type RepoPage

type RepoPage struct {
	Size       int    `json:"size"`
	Limit      int    `json:"limit"`
	IsLastPage bool   `json:"isLastPage"`
	Values     []Repo `json:"values"`
	Start      int    `json:"start"`
}

type Tag

type Tag struct {
	ID              string `json:"id"`
	DisplayID       string `json:"displayId"`
	Type            string `json:"type"`
	LatestCommit    string `json:"latestCommit"`
	LatestChangeset string `json:"latestChangeset"`
	Hash            string `json:"hash"`
}

type TagClientInterface

type TagClientInterface interface {
	TagList(projectKey string, repositorySlug string, params TagListParams) (*TagPage, error)
	TagGet(projectKey string, repositorySlug string, name string) (*Tag, error)
	TagCreate(projectKey string, repositorySlug string, payload TagCreatePayload) (*Tag, error)
}

type TagCreatePayload

type TagCreatePayload struct {
	Message    string `json:"message"`
	Name       string `json:"name"`
	Force      bool   `json:"force"`
	StartPoint string `json:"startPoint"`
	Type       string `json:"type"`
}

type TagListParams

type TagListParams struct {
	// FilterText is the the text to match on. The match seems to be a prefix match.
	FilterText string `json:"filterText"`
	// OrderBy determines ordering of refs.
	// Either ALPHABETICAL (by name) or MODIFICATION (last updated).
	OrderBy string `json:"orderBy"`
}

type TagPage

type TagPage struct {
	Size       int   `json:"size"`
	Limit      int   `json:"limit"`
	IsLastPage bool  `json:"isLastPage"`
	Values     []Tag `json:"values"`
	Start      int   `json:"start"`
}

type TestClient

type TestClient struct {
	Branches     []Branch
	Tags         []Tag
	Repos        []Repo
	Commits      []Commit
	PullRequests []PullRequest
	// Files contains byte slices for filenames
	Files map[string][]byte
}

TestClient returns mocked branches and tags.

func (*TestClient) BranchList

func (c *TestClient) BranchList(projectKey string, repositorySlug string, params BranchListParams) (*BranchPage, error)

func (*TestClient) CommitGet

func (c *TestClient) CommitGet(projectKey, repositorySlug, commitID string) (*Commit, error)

func (*TestClient) CommitList

func (c *TestClient) CommitList(projectKey string, repositorySlug string, params CommitListParams) (*CommitPage, error)

func (*TestClient) CommitPullRequestList

func (c *TestClient) CommitPullRequestList(projectKey, repositorySlug, commitID string) (*PullRequestPage, error)

func (*TestClient) RawGet

func (c *TestClient) RawGet(project, repository, filename, gitFullRef string) ([]byte, error)

func (*TestClient) RepoCreate

func (c *TestClient) RepoCreate(projectKey string, payload RepoCreatePayload) (*Repo, error)

func (*TestClient) RepoList

func (c *TestClient) RepoList(projectKey string) (*RepoPage, error)

func (*TestClient) TagCreate

func (c *TestClient) TagCreate(projectKey string, repositorySlug string, payload TagCreatePayload) (*Tag, error)

func (*TestClient) TagGet

func (c *TestClient) TagGet(projectKey string, repositorySlug string, name string) (*Tag, error)

func (*TestClient) TagList

func (c *TestClient) TagList(projectKey string, repositorySlug string, params TagListParams) (*TagPage, error)

type User

type User struct {
	Name         string `json:"name"`
	EmailAddress string `json:"emailAddress"`
	ID           int    `json:"id"`
	DisplayName  string `json:"displayName"`
	Active       bool   `json:"active"`
	Slug         string `json:"slug"`
	Type         string `json:"type"`
}

type Webhook

type Webhook struct {
	ID            int                  `json:"id"`
	Name          string               `json:"name"`
	CreatedDate   int64                `json:"createdDate"`
	UpdatedDate   int64                `json:"updatedDate"`
	Events        []string             `json:"events"`
	Configuration WebhookConfiguration `json:"configuration"`
	URL           string               `json:"url"`
	Active        bool                 `json:"active"`
}

type WebhookConfiguration

type WebhookConfiguration struct {
	Secret string `json:"secret"`
}

type WebhookCreatePayload

type WebhookCreatePayload struct {
	Name          string               `json:"name"`
	Events        []string             `json:"events"`
	Configuration WebhookConfiguration `json:"configuration"`
	URL           string               `json:"url"`
	Active        bool                 `json:"active"`
}

Jump to

Keyboard shortcuts

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