bitbucket

package
v0.0.0-...-e70da7b Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PullRequestReviewStatusNeedsWork is the status for a pull request review
	// when the pull request needs more work before it can be merged.
	PullRequestReviewStatusNeedsWork = "NEEDS_WORK"

	// PullRequestReviewStatusApproved is the status for an approved pull request review
	PullRequestReviewStatusApproved = "APPROVED"

	// PullRequestReviewStatusUnapproved is the status for an unapproved pull request review
	PullRequestReviewStatusUnapproved = "UNAPPROVED"

	PullRequestUserRoleAuthor   = "AUTHOR"
	PullRequestUserRoleReviewer = "REVIEWER"
)
View Source
const (
	// StatusSuccess represents the success status
	StatusSuccess = "SUCCESSFUL"
	// StatusFailed represents the failed status
	StatusFailed = "FAILED"
	// StatusRunning represents the running status
	StatusInProgress = "INPROGRESS"
	// StatusUnknown represents the unknown status
	StatusUnknown = "UNKNOWN"
)

Variables

View Source
var APIPaths = map[string]string{
	"base":         "https://%s/rest/api/1.0/%s",
	"repo":         "projects/%s/repos/%s",
	"repoCommits":  "projects/%s/repos/%s/commits",
	"browse":       "projects/%s/repos/%s/browse/%s",
	"pullRequests": "projects/%s/repos/%s/pull-requests",
	"pullRequest":  "projects/%s/repos/%s/pull-requests/%s",
}
View Source
var StatusPaths = map[string]string{
	"base":   "https://%s/rest/build-status/1.0/%s",
	"status": "commits/%s",
}

Functions

This section is empty.

Types

type Author

type Author struct {
	User        User   `json:"user"`
	Role        string `json:"role"`
	HasApproved bool   `json:"approved"`
	Status      string `json:"status"`
}

Author is the creator of a Pull Request

type Client

type Client struct {
	Server string
	PAT    string
	// contains filtered or unexported fields
}

Client is a Bitbucket client that is used for storing server configuration, authentiation and to run the actual Bitbucket requests.

func (Client) Commits

func (c Client) Commits(project string, repo string, co CommitOptions) (CommitList, error)

Commits returns a list of Commits for a given repo in a given project

func (Client) PullRequest

func (c Client) PullRequest(project string, repo string, id int) (PullRequest, error)

PullRequest returns a single PullRequest in a given repo in a given project.

func (Client) PullRequests

func (c Client) PullRequests(project string, repo string) (PullRequests, error)

PullRequests returns a list of PullRequests for a given repo in a given project. @TODO add support for pagination when there are lots of pull requests? @TODO add support for ofset when there are lots of pull requests

func (Client) RawRequest

func (c Client) RawRequest(url string) ([]byte, int, error)

RawRequest does a API request and returns content as a string. This is just a helper method used by other Client functions. https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (Client) Repository

func (c Client) Repository(project string, repo string) (Repository, error)

Repository returns a single Repo in a given project.

func (Client) Status

func (c Client) Status(sha string) (StatusList, error)

Status returns a status for a given commit

func (Client) Timeout

func (c Client) Timeout() int

Timeout returns the configured connection timeout for the HTTP client.

func (Client) Useragent

func (c Client) Useragent() string

Useragent returns the configured client useragnt or a default one.

type Commit

type Commit struct {
	ID                 string `json:"id"`
	DisplayID          string `json:"displayId"`
	Author             User   `json:"author"`
	AuthorTimestamp    int64  `json:"authorTimestamp"`
	Committer          User   `json:"committer"`
	CommitterTimestamp int64  `json:"committerTimestamp"`
	Message            string `json:"message"`
	Parents            []struct {
		ID        string `json:"id"`
		DisplayID string `json:"displayId"`
	} `json:"parents"`
	Properties struct {
		JIRAIssueKeys []string `json:"jira-key"`
	} `json:"properties"`
}

Commit is a commit in a branch

func (Commit) JIRAIssueKeys

func (c Commit) JIRAIssueKeys() []string

JIRAIssueKeys returns the JIRA issue key from the commit

func (Commit) String

func (c Commit) String() string

String returns the Commit as a string

func (Commit) TimeAgo

func (c Commit) TimeAgo() string

TimeAgo returns the time since the commit was made in human readable format

type CommitList

type CommitList struct {
	Size          int      `json:"size"`
	IsLastPage    bool     `json:"isLastPage"`
	Start         int      `json:"start"`
	Limit         int      `json:"limit"`
	NextPageStart int      `json:"nextPageStart"`
	Values        []Commit `json:"values"`
}

CommitList is a list of commits

type CommitOptions

type CommitOptions struct {
	FollowRenames bool `url:"followRenames,omitempty"`
	IngoreMissing bool `url:"ignoreMissing,omitempty"`

	// if present, controls how merge commits should be filtered. Can be either exclude,
	// to exclude merge commits, include, to include both merge commits and non-merge
	// commits or only, to only return merge commits.
	Merges string `url:"merges,omitempty"`

	Path       string `url:"path,omitempty"`
	Since      string `url:"since,omitempty"`
	Until      string `url:"until,omitempty"`
	WithCounts bool   `url:"withCounts,omitempty"`

	Limit int `url:"limit,omitempty"`
	Start int `url:"start,omitempty"`
}

CommitOptions is the options for a commit

func (CommitOptions) ToQueryString

func (co CommitOptions) ToQueryString() string

ToQueryString returns the CommitOptions as a query string

type GitRef

type GitRef struct {
	ID           string     `json:"id"`
	DisplayID    string     `json:"displayId"`
	LatestCommit string     `json:"latestCommit"`
	Repository   Repository `json:"repository"`
}

GitRef is the git reference of a Pull Request

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

Link is a link to a resource

type Links struct {
	Self []struct {
		Href string `json:"href"`
	} `json:"self"`
}

type Project

type Project struct {
	Key         string `json:"key"`
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

Project is the project reference of a Pull Request

type PullRequest

type PullRequest struct {
	ID          int      `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	State       string   `json:"state"`
	IsOpen      bool     `json:"open"`
	IsClosed    bool     `json:"closed"`
	CreatedDate int64    `json:"createdDate"`
	UpdatedDate int64    `json:"updatedDate"`
	FromRef     GitRef   `json:"fromRef"`
	ToRef       GitRef   `json:"toRef"`
	Author      Author   `json:"author"`
	Reviewers   []Author `json:"reviewers"`
	Links       struct {
		Self []struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"links"`
}

PullRequest is a single Pull Request

func (PullRequest) ApprovalStatus

func (pr PullRequest) ApprovalStatus(showEmojis bool) string

ApprovalStatus returns a human readable approval status

func (PullRequest) IsApproved

func (pr PullRequest) IsApproved() bool

IsApproved return if the pull request is approved by reviewers

func (PullRequest) IsWorkInProgress

func (pr PullRequest) IsWorkInProgress() bool

IsWorkInProgress returns true if the Pull Request is Work In Progress

func (PullRequest) OpenSince

func (pr PullRequest) OpenSince() string

OpenSince returns how long the Pull Request has been open in human readable format.

func (PullRequest) RepoSlug

func (pr PullRequest) RepoSlug() string

RepoSlug returns the combind string of repo and project

func (PullRequest) ReviewedBy

func (pr PullRequest) ReviewedBy() string

ReviewedBy returns a list of reviewers as a string

func (PullRequest) String

func (pr PullRequest) String() string

String returns the Pull Request as a string

type PullRequests

type PullRequests struct {
	Size       int           `json:"size"`
	Limit      int           `json:"limit"`
	IsLastPage bool          `json:"isLastPage"`
	List       []PullRequest `json:"values"`
}

PullRequests is a list of Pull Requests

type Repository

type Repository struct {
	Slug        string          `json:"slug"`
	ID          int             `json:"id"`
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Project     Project         `json:"project"`
	Links       RepositoryLinks `json:"links"`
}

Repository is the repository reference of a Pull Request

type RepositoryLinks struct {
	Self  []Link `json:"self"`
	Clone []Link `json:"clone"`
}

RepositoryLinks are links to the repository

type Status

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

Status represents a Bitbucket commit status

type StatusList

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

StatusList is a list of Status

func (StatusList) State

func (s StatusList) State() string

State returns the aggregated state of all statuses in the list

type User

type User struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	Email       string `json:"emailAddress"`
	Links       struct {
		Self []struct {
			Href string `json:"href"`
		} `json:"self"`
	} `json:"links"`
}

User is the user object for an Author

Jump to

Keyboard shortcuts

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