server

package
Version: v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RepoAdmin represents admin permission in repo.
	RepoAdmin = "REPO_ADMIN"
	// ProjectRead represents reading permission in project.
	ProjectRead = "PROJECT_READ"
)
View Source
const (
	// RefsChanged is the event key about refs changed
	RefsChanged = "repo:refs_changed"
	// PrOpened is the event key about pull request opened.
	PrOpened = "pr:opened"
	// PrModified means a pull request's description, title, or target branch is changed.
	// It be supported after the version is 5.10. Ref to: https://confluence.atlassian.com/bitbucketserver/bitbucket-server-5-10-release-notes-948214779.html
	PrModified = "pr:modified"
	// PrFromRefUpdated means a pull request's source branch has been updated.
	PrFromRefUpdated = "pr:from_ref_updated"
	// PrCommentAdded is the event key about a comment added on the pull request.
	PrCommentAdded = "pr:comment:added"
)

Ref to: https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html

View Source
const (
	// SupportAccessTokenVersion represents the lowest version
	// that support personal access token.
	SupportAccessTokenVersion = "5.5.0"

	// SupportPrModifiedEvent represents the lowest version
	// that support event key named pr:modified.
	SupportPrModifiedEvent = "5.10.0"

	// SupportPrFromRefUpdatedEvent represents the lowest version
	// that support pr:from_ref_updated event.
	SupportPrFromRefUpdatedEvent = "7.0.0"
)

Variables

This section is empty.

Functions

func GetBitbucketVersion

func GetBitbucketVersion(client *http.Client, base *url.URL) (string, error)

GetBitbucketVersion returns the version of the BitBucket Server

func IsHigherVersion

func IsHigherVersion(version string, refVersion string) (bool, error)

IsHigherVersion compare the version with refVersion. If the version is lower than the refVersion, it will return false.

func ParseEvent

func ParseEvent(request *http.Request) *scm.EventData

ParseEvent parses data from Bitbucket Server events.

Types

type AuthType

type AuthType int

AuthType represents an authentication type within BitBucket Server.

const (
	// BasicAuth represents basic authentication type.
	BasicAuth AuthType = iota
	// PersonalAccessToken represents personal access token type.
	PersonalAccessToken
)

List of available authentication types.

type AuthorizationsService

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

AuthorizationsService handles communication with the authorization related methods of the BitBucket Server API. docs: https://docs.atlassian.com/bitbucket-server/rest/6.2.0/bitbucket-access-tokens-rest.html .

func (*AuthorizationsService) CreateAccessToken

func (server *AuthorizationsService) CreateAccessToken(ctx context.Context, user string, permissionReq PermissionReq) (string, *http.Response, error)

CreateAccessToken create a new access token in BitBucket Server.

type BitbucketServer

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

BitbucketServer represents the SCM provider of BitBucket Server.

func NewBitbucketServer

func NewBitbucketServer(scmCfg *v1alpha1.SCMSource, v1Client *V1Client) *BitbucketServer

NewBitbucketServer new a SCM provider of BitBucket Server.

func (*BitbucketServer) CheckToken

func (b *BitbucketServer) CheckToken() error

CheckToken checks whether the token has the authority of repo by trying ListRepos with the token.

func (*BitbucketServer) CreateStatus

func (b *BitbucketServer) CreateStatus(status c_v1alpha1.StatusPhase, targetURL, repoURL, commitSha string) error

CreateStatus generate a new status for repository.

func (*BitbucketServer) CreateWebhook

func (b *BitbucketServer) CreateWebhook(repo string, webhook *scm.Webhook) error

CreateWebhook creates webhook for specified repo.

func (*BitbucketServer) DeleteWebhook

func (b *BitbucketServer) DeleteWebhook(repo string, webhookURL string) error

DeleteWebhook deletes webhook from specified repo.

func (*BitbucketServer) GetPullRequestSHA

func (b *BitbucketServer) GetPullRequestSHA(repoURL string, number int) (string, error)

GetPullRequestSHA gets latest commit SHA of pull request.

func (*BitbucketServer) GetToken

func (b *BitbucketServer) GetToken() (string, error)

GetToken gets the token by the username and password of SCM config.

func (*BitbucketServer) GetWebhook

func (b *BitbucketServer) GetWebhook(repo string, webhookURL string) (*Webhook, error)

GetWebhook gets webhook from specified repo.

func (*BitbucketServer) ListBranches

func (b *BitbucketServer) ListBranches(repo string) ([]string, error)

ListBranches lists the branches for specified repo.

func (*BitbucketServer) ListDockerfiles

func (b *BitbucketServer) ListDockerfiles(repo string) ([]string, error)

ListDockerfiles lists the Dockerfiles for specified repo.

func (*BitbucketServer) ListPullRequests added in v0.9.7

func (b *BitbucketServer) ListPullRequests(repo, state string) ([]scm.PullRequest, error)

ListPullRequests lists the pull requests for specified repo.

func (*BitbucketServer) ListRepos

func (b *BitbucketServer) ListRepos() ([]scm.Repository, error)

ListRepos lists the repos by the SCM config.

func (*BitbucketServer) ListTags

func (b *BitbucketServer) ListTags(repo string) ([]string, error)

ListTags lists the tags for specified repo.

type Branch

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

Branch contains git Branch information.

type Branches

type Branches struct {
	Pagination
	Values []Branch `json:"values"`
}

Branches is a set of branches.

type Change

type Change struct {
	Ref struct {
		ID        string `json:"id"`
		Type      string `json:"type"`
		DisplayID string `json:"displayId"`
	} `json:"ref"`
	RefID    string `json:"refId"`
	FromHash string `json:"fromHash"`
	ToHash   string `json:"toHash"`
	Type     string `json:"type"`
}

Change represents the details of refs_changed.

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

CloneLink represents the link of the repo used to clone.

type Comment

type Comment struct {
	Text string `json:"text"`
}

Comment represents the comment in the pull request.

type Config

type Config struct {
	// Base URL for API requests. Defaults to the public BitBucket Server API, but can be
	// set to a domain endpoint to use with a self hosted BitBucket Server server. baseURL
	// should always be specified with a trailing slash.
	BaseURL string

	// Auth type used to make authenticated API calls.
	AuthType AuthType

	// Username used for basic authentication.
	Username string
	// Password used for basic authentication.
	Password string

	// Token used to make authenticated API calls.
	Token string
}

Config contains V1Client config information.

type EventPayload

type EventPayload struct {
	EventKey    string      `json:"eventKey"`
	Repository  Repository  `json:"repository"`
	Changes     []Change    `json:"changes"`
	PullRequest PullRequest `json:"pullRequest"`
	Comment     Comment     `json:"comment"`
}

EventPayload represents the event information.

type Files

type Files struct {
	Pagination
	Values []string `json:"values"`
}

Files is a set of files' name in a repo.

type ListOpts

type ListOpts struct {
	Start *int `url:"start,omitempty" json:"start,omitempty"`
	Limit *int `url:"limit,omitempty" json:"limit,omitempty"`
}

ListOpts specifies the optional parameters to various List methods that support pagination.

type Pagination

type Pagination struct {
	Start    *int  `json:"start"`
	Size     *int  `json:"size"`
	Limit    *int  `json:"limit"`
	LastPage *bool `json:"isLastPage"`
	NextPage *int  `json:"nextPageStart"`
}

Pagination represents BitBucket Server pagination properties embedded in list responses.

type PermissionReq

type PermissionReq struct {
	Name        string   `json:"name"`
	Permissions []string `json:"permissions"`
}

PermissionReq represents the options of creating access token.

type PermissionResp

type PermissionResp struct {
	ID    string `json:"id"`
	Token string `json:"token"`
}

PermissionResp represents the response body of creating access token.

type Project

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

Project contains data from a BitBucket Server Project.

type Property

type Property struct {
	Version string `json:"version"`
}

Property represents BitBucket Server property.

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 int64  `json:"createdDate"`
	UpdatedDate int64  `json:"updatedDate"`
	FromRef     struct {
		ID           string     `json:"id"`
		DisplayID    string     `json:"displayId"`
		LatestCommit string     `json:"latestCommit"`
		Repository   Repository `json:"repository"`
	} `json:"fromRef"`
	ToRef struct {
		ID           string     `json:"id"`
		DisplayID    string     `json:"displayId"`
		LatestCommit string     `json:"latestCommit"`
		Repository   Repository `json:"repository"`
	} `json:"toRef"`
	Locked bool `json:"locked"`
	Author struct {
		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"`
			Links        struct {
				Self []struct {
					Href string `json:"href"`
				} `json:"self"`
			} `json:"links"`
		} `json:"user"`
		Role     string `json:"role"`
		Approved bool   `json:"approved"`
		Status   string `json:"status"`
	} `json:"author"`
	Reviewers    []interface{} `json:"reviewers"`
	Participants []interface{} `json:"participants"`
	Links        struct {
		Self []SelfLink `json:"self"`
	} `json:"links"`
}

PullRequest represents a BitBucket Server pull request on a repository.

type PullRequestListOpts added in v0.9.7

type PullRequestListOpts struct {
	ListOpts
	State string `url:"state,omitempty" json:"state,omitempty"`
}

PullRequestListOpts ...

type PullRequests added in v0.9.7

type PullRequests struct {
	Pagination
	Values []scm.PullRequest `json:"values"`
}

PullRequests is a set of PullRequest.

type PullRequestsService

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

PullRequestsService handles communication with the pull request related

func (*PullRequestsService) GetPullRequest

func (server *PullRequestsService) GetPullRequest(ctx context.Context, project string, repo string, number int) (*PullRequest, *http.Response, error)

GetPullRequest get a specific pull request.

type Repositories

type Repositories struct {
	Pagination
	Values []Repository `json:"values"`
}

Repositories is a set of repositories.

type RepositoriesService

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

RepositoriesService handles communication with the repository related.

func (*RepositoriesService) CreateStatus

func (server *RepositoriesService) CreateStatus(ctx context.Context, commitID string, input *StatusReq) (*http.Response, error)

CreateStatus create a commit status.

func (*RepositoriesService) CreateWebhook

func (server *RepositoriesService) CreateWebhook(ctx context.Context, project string, repo string, webhookReq Webhook) (*Webhook, *http.Response, error)

CreateWebhook create a new webhook.

func (*RepositoriesService) DeleteWebhook

func (server *RepositoriesService) DeleteWebhook(ctx context.Context, project string, repo string, webhookID int) (*http.Response, error)

DeleteWebhook delete a webhook.

func (*RepositoriesService) ListBranches

func (server *RepositoriesService) ListBranches(ctx context.Context, project string, repo string, opt *ListOpts) (*Branches, *http.Response, error)

ListBranches list branches on the repository.

func (*RepositoriesService) ListFiles

func (server *RepositoriesService) ListFiles(ctx context.Context, project string, repo string, opt *ListOpts) (*Files, *http.Response, error)

ListFiles list files on the repository.

func (*RepositoriesService) ListPullRequests added in v0.9.7

func (server *RepositoriesService) ListPullRequests(ctx context.Context, project, repo string, opt *PullRequestListOpts) (*PullRequests, *http.Response, error)

ListPullRequests list pull requests on the repository.

func (*RepositoriesService) ListRepositories

func (server *RepositoriesService) ListRepositories(ctx context.Context, project string, opt *ListOpts) (*Repositories, *http.Response, error)

ListRepositories list repositories in the Bitbucket Server.

func (*RepositoriesService) ListTags

func (server *RepositoriesService) ListTags(ctx context.Context, project string, repo string, opt *ListOpts) (*Tags, *http.Response, error)

ListTags list tags on the repository.

func (*RepositoriesService) ListWebhook

func (server *RepositoriesService) ListWebhook(ctx context.Context, project string, repo string) (*Webhooks, *http.Response, error)

ListWebhook list webhooks on a repository.

type Repository

type Repository struct {
	Slug          string  `json:"slug"`
	ID            int     `json:"id"`
	Name          string  `json:"name"`
	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 []CloneLink `json:"clone"`
		Self  []SelfLink  `json:"self"`
	} `json:"links"`
}

Repository contains data from a BitBucket Server Repository.

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

SelfLink represents the link of the resource.

type StatusReq

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

StatusReq represents the options of creating commit status.

type Tag

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

Tag contains git Tag information.

type Tags

type Tags struct {
	Pagination
	Values []Tag `json:"values"`
}

Tags is a set of tags.

type V1Client

type V1Client struct {

	// User agent used when communicating with the BitBucket Server API.
	UserAgent string

	// Services used for talking to different parts of the BitBucket Server API.
	PullRequests   *PullRequestsService
	Repositories   *RepositoriesService
	Authorizations *AuthorizationsService
	// contains filtered or unexported fields
}

V1Client manages communication with the BitBucket Server API.

func NewClient

func NewClient(client *http.Client, config Config) (*V1Client, error)

NewClient returns a BitBucket Server client.

func (*V1Client) Do

func (c *V1Client) Do(request *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response.

func (*V1Client) NewRequest

func (c *V1Client) NewRequest(method, urlStr string, body interface{}, opt interface{}) (*http.Request, error)

NewRequest creates an API request.

type Webhook

type Webhook struct {
	ID     int      `json:"id,omitempty"`
	Name   string   `json:"name"`
	Events []string `json:"events,omitempty"`
	URL    string   `json:"url"`
	Active bool     `json:"active"`
}

Webhook contains webhook information.

type Webhooks

type Webhooks struct {
	Pagination
	Values []Webhook `json:"values"`
}

Webhooks is a set of webhooks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL