bitbucket

package module
Version: v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-bitbucket

Bitbucket-API library for golang.

Support Bitbucket API v2.0.

And the response type is json format defined Bitbucket API.

Install

go get github.com/sciutand/go-bitbucket

Usage

package main

import (
        "fmt"

        "github.com/sciutand/go-bitbucket"
)

func main() {

        c := bitbucket.NewBasicAuth("username", "password")

        opt := &bitbucket.PullRequestsOptions{
                Owner:             "your-team",
                RepoSlug:          "awesome-project",
                SourceBranch:      "develop",
                DestinationBranch: "master",
                Title:             "fix bug. #9999",
                CloseSourceBranch: true,
        }

        res, err := c.Repositories.PullRequests.Create(opt)
        if err != nil {
                panic(err)
        }

        fmt.Println(res)
}

FAQ

Support Bitbucket API v1.0 ?

It does not correspond yet. Because there are many differences between v2.0 and v1.0.

It is officially recommended to use v2.0. But unfortunately Bitbucket Server (formerly: Stash) API is still v1.0. And The API v1.0 covers resources that the v2.0 API and API v2.0 is yet to cover.

Development

Get dependencies

It's using go mod.

How to testing

Set your available user account to Global Env.

export BITBUCKET_TEST_USERNAME=<your_username>
export BITBUCKET_TEST_PASSWORD=<your_password>
export BITBUCKET_TEST_OWNER=<your_repo_owner>
export BITBUCKET_TEST_REPOSLUG=<your_repo_name>

And just run;

make test

If you want to test individually;

go test -v ./tests/diff_test.go

License

Apache License 2.0

Author

ktrysmt

Documentation

Index

Constants

View Source
const DEFAULT_MAX_DEPTH = 1
View Source
const DEFAULT_PAGE_LENGTH = 10

Variables

This section is empty.

Functions

func DecodeError

func DecodeError(e map[string]interface{}) error

Types

type BitbucketError

type BitbucketError struct {
	Message string
	Fields  map[string][]string
}

type BranchModel added in v0.8.2

type BranchModel struct {
	Name           string
	Branch         RepositoryBranch
	Use_Mainbranch bool
}

type BranchRestrictions

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

func (*BranchRestrictions) Create

func (b *BranchRestrictions) Create(bo *BranchRestrictionsOptions) (interface{}, error)

func (*BranchRestrictions) Delete

func (b *BranchRestrictions) Delete(bo *BranchRestrictionsOptions) (interface{}, error)

func (*BranchRestrictions) Get

func (b *BranchRestrictions) Get(bo *BranchRestrictionsOptions) (interface{}, error)

func (*BranchRestrictions) Gets

func (b *BranchRestrictions) Gets(bo *BranchRestrictionsOptions) (interface{}, error)

func (*BranchRestrictions) Update

func (b *BranchRestrictions) Update(bo *BranchRestrictionsOptions) (interface{}, error)

type BranchRestrictionsOptions

type BranchRestrictionsOptions struct {
	Owner    string            `json:"owner"`
	RepoSlug string            `json:"repo_slug"`
	ID       string            `json:"id"`
	Groups   map[string]string `json:"groups"`
	Pattern  string            `json:"pattern"`
	Users    []string          `json:"users"`
	Kind     string            `json:"kind"`
	FullSlug string            `json:"full_slug"`
	Name     string            `json:"name"`
	Value    interface{}       `json:"value"`
}

type BranchType added in v0.8.2

type BranchType struct {
	Kind   string
	Prefix string
}

type BranchingModel added in v0.8.2

type BranchingModel struct {
	Type         string
	Branch_Types []BranchType
	Development  BranchModel
	Production   BranchModel
}

type Client

type Client struct {
	Auth         *auth
	Users        users
	User         user
	Teams        teams
	Repositories *Repositories
	Workspaces   *Workspace
	Pagelen      uint64
	MaxDepth     uint64

	HttpClient *http.Client
	// contains filtered or unexported fields
}

func NewBasicAuth

func NewBasicAuth(u, p string) *Client

func NewOAuth

func NewOAuth(i, s string) *Client

func NewOAuthClientCredentials added in v0.4.1

func NewOAuthClientCredentials(i, s string) *Client

Uses the Client Credentials Grant oauth2 flow to authenticate to Bitbucket

func NewOAuthWithCode added in v0.4.1

func NewOAuthWithCode(i, s, c string) (*Client, string)

NewOAuthWithCode finishes the OAuth handshake with a given code and returns a *Client

func NewOAuthbearerToken added in v0.4.1

func NewOAuthbearerToken(t string) *Client

func (*Client) Execute added in v0.8.3

func (c *Client) Execute(method string, urlStr string, text string) (interface{}, error)

Execute a request

func (*Client) Get

func (c *Client) Get(t string) (interface{}, error)

func (*Client) GetApiBaseURL added in v0.8.2

func (c *Client) GetApiBaseURL() string

func (*Client) SetApiBaseURL added in v0.8.2

func (c *Client) SetApiBaseURL(urlStr string)

type CommitStatusOptions added in v0.4.1

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

type Commits

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

func (*Commits) CreateCommitStatus added in v0.4.1

func (cm *Commits) CreateCommitStatus(cmo *CommitsOptions, cso *CommitStatusOptions) (interface{}, error)

func (*Commits) GetCommit

func (cm *Commits) GetCommit(cmo *CommitsOptions) (interface{}, error)

func (*Commits) GetCommitComment

func (cm *Commits) GetCommitComment(cmo *CommitsOptions) (interface{}, error)

func (*Commits) GetCommitComments

func (cm *Commits) GetCommitComments(cmo *CommitsOptions) (interface{}, error)

func (*Commits) GetCommitStatus

func (cm *Commits) GetCommitStatus(cmo *CommitsOptions, commitStatusKey string) (interface{}, error)

func (*Commits) GetCommitStatuses

func (cm *Commits) GetCommitStatuses(cmo *CommitsOptions) (interface{}, error)

func (*Commits) GetCommits

func (cm *Commits) GetCommits(cmo *CommitsOptions) (interface{}, error)

func (*Commits) GiveApprove

func (cm *Commits) GiveApprove(cmo *CommitsOptions) (interface{}, error)

func (*Commits) RemoveApprove

func (cm *Commits) RemoveApprove(cmo *CommitsOptions) (interface{}, error)

type CommitsOptions

type CommitsOptions struct {
	Owner       string `json:"owner"`
	RepoSlug    string `json:"repo_slug"`
	Revision    string `json:"revision"`
	Branchortag string `json:"branchortag"`
	Include     string `json:"include"`
	Exclude     string `json:"exclude"`
	CommentID   string `json:"comment_id"`
}

type Diff

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

func (*Diff) GetDiff

func (d *Diff) GetDiff(do *DiffOptions) (interface{}, error)

func (*Diff) GetPatch

func (d *Diff) GetPatch(do *DiffOptions) (interface{}, error)

type DiffOptions

type DiffOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Spec     string `json:"spec"`
}

type Downloads added in v0.4.1

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

func (*Downloads) Create added in v0.4.1

func (dl *Downloads) Create(do *DownloadsOptions) (interface{}, error)

func (*Downloads) List added in v0.4.1

func (dl *Downloads) List(do *DownloadsOptions) (interface{}, error)

type DownloadsOptions added in v0.4.1

type DownloadsOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	FilePath string `json:"filepath"`
	FileName string `json:"filename"`
}

type PageRes added in v0.8.2

type PageRes struct {
	Page     int32 `json:"page"`
	PageLen  int32 `json:"pagelen"`
	MaxDepth int32 `json:"max_depth"`
	Size     int32 `json:"size"`
}

type Permission added in v0.8.2

type Permission struct {
	Type string
	// contains filtered or unexported fields
}

func (*Permission) GetUserPermissions added in v0.8.2

func (t *Permission) GetUserPermissions(organization, member string) (*Permission, error)

type Pipeline added in v0.3.1

type Pipeline struct {
	Type       string
	Enabled    bool
	Repository Repository
}

type PipelineBuildNumber added in v0.8.2

type PipelineBuildNumber struct {
	Type string
	Next int
}

type PipelineKeyPair added in v0.3.1

type PipelineKeyPair struct {
	Type       string
	Uuid       string
	PublicKey  string
	PrivateKey string
}

type PipelineVariable added in v0.3.1

type PipelineVariable struct {
	Type    string
	Uuid    string
	Key     string
	Value   string
	Secured bool
}

type Project

type Project struct {
	Key  string
	Name string
}

type PullRequests

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

func (*PullRequests) Activities

func (p *PullRequests) Activities(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Activity

func (p *PullRequests) Activity(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Commits

func (p *PullRequests) Commits(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Create

func (p *PullRequests) Create(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Decline

func (p *PullRequests) Decline(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Diff

func (p *PullRequests) Diff(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Get

func (p *PullRequests) Get(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) GetComment

func (p *PullRequests) GetComment(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) GetComments

func (p *PullRequests) GetComments(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Gets

func (p *PullRequests) Gets(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Merge

func (p *PullRequests) Merge(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Patch

func (p *PullRequests) Patch(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Statuses added in v0.8.2

func (p *PullRequests) Statuses(po *PullRequestsOptions) (interface{}, error)

func (*PullRequests) Update

func (p *PullRequests) Update(po *PullRequestsOptions) (interface{}, error)

type PullRequestsOptions

type PullRequestsOptions struct {
	ID                string   `json:"id"`
	CommentID         string   `json:"comment_id"`
	Owner             string   `json:"owner"`
	RepoSlug          string   `json:"repo_slug"`
	Title             string   `json:"title"`
	Description       string   `json:"description"`
	CloseSourceBranch bool     `json:"close_source_branch"`
	SourceBranch      string   `json:"source_branch"`
	SourceRepository  string   `json:"source_repository"`
	DestinationBranch string   `json:"destination_branch"`
	DestinationCommit string   `json:"destination_repository"`
	Message           string   `json:"message"`
	Reviewers         []string `json:"reviewers"`
	States            []string `json:"states"`
	Query             string   `json:"query"`
	Sort              string   `json:"sort"`
}

type Repositories

type Repositories struct {
	PullRequests       *PullRequests
	Repository         *Repository
	Commits            *Commits
	Diff               *Diff
	BranchRestrictions *BranchRestrictions
	Webhooks           *Webhooks
	Downloads          *Downloads
	// contains filtered or unexported fields
}

func (*Repositories) ListForAccount

func (r *Repositories) ListForAccount(ro *RepositoriesOptions) (*RepositoriesRes, error)

func (*Repositories) ListForTeam

func (r *Repositories) ListForTeam(ro *RepositoriesOptions) (*RepositoriesRes, error)

func (*Repositories) ListPublic

func (r *Repositories) ListPublic() (interface{}, error)

type RepositoriesOptions

type RepositoriesOptions struct {
	Owner string `json:"owner"`
	Role  string `json:"role"` // role=[owner|admin|contributor|member]
}

type RepositoriesRes added in v0.8.2

type RepositoriesRes struct {
	Page     int32
	Pagelen  int32
	MaxDepth int32
	Size     int32
	Items    []Repository
}

type Repository

type Repository struct {
	Project     Project
	Uuid        string
	Name        string
	Slug        string
	Full_name   string
	Description string
	ForkPolicy  string
	Language    string
	Is_private  bool
	Has_issues  bool
	Mainbranch  RepositoryBranch
	Type        string
	Owner       map[string]interface{}
	Links       map[string]interface{}
	// contains filtered or unexported fields
}

func (*Repository) AddPipelineKeyPair added in v0.3.1

func (r *Repository) AddPipelineKeyPair(rpkpo *RepositoryPipelineKeyPairOptions) (*PipelineKeyPair, error)

func (*Repository) AddPipelineVariable added in v0.3.1

func (r *Repository) AddPipelineVariable(rpvo *RepositoryPipelineVariableOptions) (*PipelineVariable, error)

func (*Repository) BranchingModel added in v0.8.2

func (r *Repository) BranchingModel(rbmo *RepositoryBranchingModelOptions) (*BranchingModel, error)

func (*Repository) Create

func (r *Repository) Create(ro *RepositoryOptions) (*Repository, error)

func (*Repository) CreateTag added in v0.8.2

func (*Repository) Delete

func (r *Repository) Delete(ro *RepositoryOptions) (interface{}, error)

func (*Repository) Fork added in v0.8.2

func (*Repository) Get

func (r *Repository) Get(ro *RepositoryOptions) (*Repository, error)

func (*Repository) GetBranch added in v0.8.2

func (*Repository) GetFileBlob added in v0.8.2

func (r *Repository) GetFileBlob(ro *RepositoryBlobOptions) (*RepositoryBlob, error)

func (*Repository) ListBranches added in v0.8.2

func (r *Repository) ListBranches(rbo *RepositoryBranchOptions) (*RepositoryBranches, error)

func (*Repository) ListDefaultReviewers added in v0.8.2

func (r *Repository) ListDefaultReviewers(ro *RepositoryOptions) (interface{}, error)

func (*Repository) ListFiles added in v0.8.2

func (r *Repository) ListFiles(ro *RepositoryFilesOptions) ([]RepositoryFile, error)

func (*Repository) ListForks

func (r *Repository) ListForks(ro *RepositoryOptions) (interface{}, error)

func (*Repository) ListTags added in v0.8.2

func (r *Repository) ListTags(rbo *RepositoryTagOptions) (*RepositoryTags, error)

func (*Repository) ListWatchers

func (r *Repository) ListWatchers(ro *RepositoryOptions) (interface{}, error)

func (*Repository) UpdatePipelineBuildNumber added in v0.8.2

func (r *Repository) UpdatePipelineBuildNumber(rpbno *RepositoryPipelineBuildNumberOptions) (*PipelineBuildNumber, error)

func (*Repository) UpdatePipelineConfig added in v0.3.1

func (r *Repository) UpdatePipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error)

type RepositoryBlob added in v0.8.2

type RepositoryBlob struct {
	Content []byte
}

func (RepositoryBlob) String added in v0.8.2

func (rb RepositoryBlob) String() string

type RepositoryBlobOptions added in v0.8.2

type RepositoryBlobOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Ref      string `json:"ref"`
	Path     string `json:"path"`
}

type RepositoryBranch added in v0.8.2

type RepositoryBranch struct {
	Type                   string
	Name                   string
	Default_Merge_Strategy string
	Merge_Strategies       []string
	Links                  map[string]interface{}
	Target                 map[string]interface{}
	Heads                  []map[string]interface{}
}

type RepositoryBranchOptions added in v0.8.2

type RepositoryBranchOptions struct {
	Owner      string `json:"owner"`
	RepoSlug   string `json:"repo_slug"`
	Query      string `json:"query"`
	Sort       string `json:"sort"`
	PageNum    int    `json:"page"`
	Pagelen    int    `json:"pagelen"`
	MaxDepth   int    `json:"max_depth"`
	BranchName string `json:"branch_name"`
}

type RepositoryBranches added in v0.8.2

type RepositoryBranches struct {
	Page     int
	Pagelen  int
	MaxDepth int
	Size     int
	Next     string
	Branches []RepositoryBranch
}

type RepositoryBranchingModelOptions added in v0.8.2

type RepositoryBranchingModelOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
}

type RepositoryFile added in v0.8.2

type RepositoryFile struct {
	Mimetype   string
	Links      map[string]interface{}
	Path       string
	Commit     map[string]interface{}
	Attributes []string
	Type       string
	Size       int
}

func (RepositoryFile) String added in v0.8.2

func (rf RepositoryFile) String() string

type RepositoryFilesOptions added in v0.8.2

type RepositoryFilesOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Ref      string `json:"ref"`
	Path     string `json:"path"`
}

type RepositoryForkOptions added in v0.8.2

type RepositoryForkOptions struct {
	FromOwner string `json:"from_owner"`
	FromSlug  string `json:"from_slug"`
	Owner     string `json:"owner"`
	// TODO: does the API supports specifying  slug on forks?
	// see: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/forks#post
	Name        string `json:"name"`
	IsPrivate   string `json:"is_private"`
	Description string `json:"description"`
	ForkPolicy  string `json:"fork_policy"`
	Language    string `json:"language"`
	HasIssues   string `json:"has_issues"`
	HasWiki     string `json:"has_wiki"`
	Project     string `json:"project"`
}

type RepositoryOptions

type RepositoryOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Scm      string `json:"scm"`
	//	Name        string `json:"name"`
	IsPrivate   string `json:"is_private"`
	Description string `json:"description"`
	ForkPolicy  string `json:"fork_policy"`
	Language    string `json:"language"`
	HasIssues   string `json:"has_issues"`
	HasWiki     string `json:"has_wiki"`
	Project     string `json:"project"`
}

type RepositoryPipelineBuildNumberOptions added in v0.8.2

type RepositoryPipelineBuildNumberOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Next     int    `json:"next"`
}

type RepositoryPipelineKeyPairOptions added in v0.3.1

type RepositoryPipelineKeyPairOptions struct {
	Owner      string `json:"owner"`
	RepoSlug   string `json:"repo_slug"`
	PrivateKey string `json:"private_key"`
	PublicKey  string `json:"public_key"`
}

type RepositoryPipelineOptions added in v0.3.1

type RepositoryPipelineOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Enabled  bool   `json:"has_pipelines"`
}

type RepositoryPipelineVariableOptions added in v0.3.1

type RepositoryPipelineVariableOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Uuid     string `json:"uuid"`
	Key      string `json:"key"`
	Value    string `json:"value"`
	Secured  bool   `json:"secured"`
}

type RepositoryTag added in v0.8.2

type RepositoryTag struct {
	Type   string
	Name   string
	Links  map[string]interface{}
	Target map[string]interface{}
	Heads  []map[string]interface{}
}

type RepositoryTagCreationOptions added in v0.8.2

type RepositoryTagCreationOptions struct {
	Owner    string              `json:"owner"`
	RepoSlug string              `json:"repo_slug"`
	Name     string              `json:"name"`
	Target   RepositoryTagTarget `json:"target"`
}

type RepositoryTagOptions added in v0.8.2

type RepositoryTagOptions struct {
	Owner    string `json:"owner"`
	RepoSlug string `json:"repo_slug"`
	Query    string `json:"q"`
	Sort     string `json:"sort"`
	PageNum  int    `json:"page"`
	Pagelen  int    `json:"pagelen"`
	MaxDepth int    `json:"max_depth"`
}

type RepositoryTagTarget added in v0.8.2

type RepositoryTagTarget struct {
	Hash string `json:"hash"`
}

type RepositoryTags added in v0.8.2

type RepositoryTags struct {
	Page     int
	Pagelen  int
	MaxDepth int
	Size     int
	Next     string
	Tags     []RepositoryTag
}

type Teams

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

func (*Teams) Followers

func (t *Teams) Followers(teamname string) (interface{}, error)

func (*Teams) Following

func (t *Teams) Following(teamname string) (interface{}, error)

func (*Teams) List

func (t *Teams) List(role string) (interface{}, error)

func (*Teams) Members

func (t *Teams) Members(teamname string) (interface{}, error)

func (*Teams) Profile

func (t *Teams) Profile(teamname string) (interface{}, error)

func (*Teams) Projects added in v0.4.1

func (t *Teams) Projects(teamname string) (interface{}, error)

func (*Teams) Repositories

func (t *Teams) Repositories(teamname string) (interface{}, error)

type User

type User struct {
	Uuid          string
	Username      string
	Nickname      string
	Website       string
	AccountStatus string `mapstructure:"account_status"`
	DisplayName   string `mapstructure:"display_name"`
	CreatedOn     string `mapstructure:"created_on"`
	Has2faEnabled bool   `mapstructure:"has_2fa_enabled"`
	Links         map[string]interface{}
	// contains filtered or unexported fields
}

User is the sub struct of Client Reference: https://developer.atlassian.com/bitbucket/api/2/reference/resource/user

func (*User) Emails

func (u *User) Emails() (interface{}, error)

Emails is getting user's emails

func (*User) Profile

func (u *User) Profile() (*User, error)

Profile is getting the user data

type Users

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

func (*Users) Followers

func (u *Users) Followers(t string) (interface{}, error)

func (*Users) Following

func (u *Users) Following(t string) (interface{}, error)

func (*Users) Get

func (u *Users) Get(t string) (interface{}, error)

func (*Users) Repositories

func (u *Users) Repositories(t string) (interface{}, error)

type Webhooks

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

func (*Webhooks) Create

func (r *Webhooks) Create(ro *WebhooksOptions) (interface{}, error)

func (*Webhooks) Delete

func (r *Webhooks) Delete(ro *WebhooksOptions) (interface{}, error)

func (*Webhooks) Get

func (r *Webhooks) Get(ro *WebhooksOptions) (interface{}, error)

func (*Webhooks) Gets

func (r *Webhooks) Gets(ro *WebhooksOptions) (interface{}, error)

func (*Webhooks) Update

func (r *Webhooks) Update(ro *WebhooksOptions) (interface{}, error)

type WebhooksOptions

type WebhooksOptions struct {
	Owner       string   `json:"owner"`
	RepoSlug    string   `json:"repo_slug"`
	Uuid        string   `json:"uuid"`
	Description string   `json:"description"`
	Url         string   `json:"url"`
	Active      bool     `json:"active"`
	Events      []string `json:"events"` // EX) {'repo:push','issue:created',..} REF) https://goo.gl/VTj93b
}

type Workspace added in v0.8.2

type Workspace struct {
	Repositories *Repositories
	Permissions  *Permission

	UUID       string
	Type       string
	Slug       string
	Is_Private bool
	Name       string
	// contains filtered or unexported fields
}

func (*Workspace) Get added in v0.8.2

func (t *Workspace) Get(workspace string) (*Workspace, error)

func (*Workspace) List added in v0.8.2

func (t *Workspace) List() (*WorkspaceList, error)

type WorkspaceList added in v0.8.2

type WorkspaceList struct {
	Page       int
	Pagelen    int
	MaxDepth   int
	Size       int
	Next       string
	Workspaces []Workspace
}

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