bitbucket

package module
v0.0.0-...-e9dc2b3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

README

Preface

Golang implementation for the BitBucket API.

Please see v1 API and v2 API sections for API coverage, PR are very welcome.

Add dependency

Use Dep to add this library to your project:

dep ensure -add github.com/crossid/bitbucket-golang-api

Insantiate a v1 or v2 api

v2 := bitbucket.NewV2BasicAuth(user, password)
v1 := bitbucket.NewV1BasicAuth(user, password)

Work with the API:

v2.Teams.List(bitbucket.ListTeamsOpts{Role: bitbucket.AdminRole})

Please check unit tests as they cover all supported features.

v2 API

Teams

  • Get a team
  • List Teams (with support for pagination)
  • List Team's members

Repositories

  • List Public Repos (with support for pagination, filtering and sorting)
  • List Repos by Owner (with support for pagination, filtering and sorting)

Users

  • Get current user
  • Get public user

v1 API

Groups

  • List groups matching one or more filters.
  • List of an account's (team / user) groups

Privileges

  • List privileges of an account (team / user)
  • List privileges of an account (team / user) for a specific repo

Group Privileges

  • List group privileges of an account (team / user)
  • List group privileges of an account (team / user) for a specific repo

Running tests

In order to run tests you should simply:

  1. Clone the project
  2. Set two env vars: BITBUCKET_USER & BITBUCKET_PASSWORD with your Bitbucket username and password respectively
  3. dep ensure
  4. export BITBUCKET_USER=<user> ; export BITBUCKET_PASSWORD="<password>"; go test

Note: Unit tests assume that your user have at least:

  • 2 teams
  • 1 member per team
  • 2 repositories

Other projects

License

APACHE 2

Documentation

Index

Constants

View Source
const (
	AdminLevel permissionLevel = "admin"
	WriteLevel permissionLevel = "write"
	ReadLevel  permissionLevel = "read"
)
View Source
const (
	AdminRole       role = "admin"
	ContributorRole role = "contributor"
	MemberRole      role = "member"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitbucketError

type BitbucketError struct {
	Type string `json:"type"`
	Err  Error  `json:"error"`
}

func (BitbucketError) Error

func (err BitbucketError) Error() string

type Error

type Error struct {
	Message string `json:"message"`
}

type ListGroupsOpts

type ListGroupsOpts struct {
	// filter by group (e.g., "foo/bar" where foo = user or team and bar = group slug)
	Group string `url:"group,omitempty"`
}

type ListPrivilegesOfAccountOpts

type ListPrivilegesOfAccountOpts struct {
	// filter=read|write|admin
	// If you filter for the read permission, you also get the higher levels of permission such as write and
	// admin as they also include the ability to read.
	Filter permissionLevel `url:"group,omitempty"`
	// private=true query parameter to filter for private repositories
	Private bool `url:"private,omitempty"`
}

type ListReposByOwnerOpts

type ListReposByOwnerOpts struct {
	// Filters the result based on the authenticated user's role on each repository.
	// - member: returns repositories to which the user has explicit read access
	// - contributor: returns repositories to which the user has explicit write access
	// - admin: returns repositories to which the user has explicit administrator access
	// - owner: returns all repositories owned by the current user
	Role role `url:"role,omitempty"`
	// The amount of entries to return per page, default to 10.
	Pagelen int `url:"pagelen,omitempty"`
	// query according to:https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
	Query string `url:"q,omitempty"`
	// sorting according to:https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
	Sort string `url:"sort,omitempty"`
}

type ListReposOpts

type ListReposOpts struct {
	// Filter the results to include only repositories create on or after this ISO-8601 timestamp. Example: YYYY-MM-DDTHH:mm:ss.sssZ
	After string `url:"after,omitempty"`
	// The amount of entries to return per page, default to 10.
	Pagelen int `url:"pagelen,omitempty"`
	// query according to:https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
	Query string `url:"q,omitempty"`
	// sorting according to:https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
	Sort string `url:"sort,omitempty"`
}

List repositories options

type ListResult

type ListResult struct {
	Pagelen int    `json:"pagelen"`
	Size    int    `json:"size"`
	Page    int    `json:"page"`
	Next    string `json:"next"`
	Values  []map[string]interface{}
}

type ListTeamMembersOpts

type ListTeamMembersOpts struct {
	// The amount of entries to return per page, default to 10.
	Pagelen int `url:"pagelen,omitempty"`
}

List team members options

type ListTeamsOpts

type ListTeamsOpts struct {
	// Role filters the teams based on the authenticated user's role on each team.
	//  - member: returns a list of all the teams which the caller is a member of at least one team group or repository owned by the team
	//  - contributor: returns a list of teams which the caller has write access to at least one repository owned by the team
	//  - admin: returns a list teams which the caller has team administrator access
	Role role `url:"role,omitempty"`
	// The amount of entries to return per page, default to 10.
	Pagelen int `url:"pagelen,omitempty"`
}

List teams options

type V1Impl

type V1Impl struct {
	Groups          v1Groups
	Privileges      v1Privilege
	GroupPrivileges v1GroupPrivilege
	// contains filtered or unexported fields
}

func NewV1

func NewV1() *V1Impl

anonymous v1 api

func NewV1BasicAuth

func NewV1BasicAuth(user, pass string) *V1Impl

func NewV1Of

func NewV1Of(client *http.Client) *V1Impl

func (*V1Impl) Do

func (impl *V1Impl) Do(req *http.Request) (map[string]interface{}, error)

func (*V1Impl) DoCustom

func (impl *V1Impl) DoCustom(req *http.Request, successV interface{}) (*http.Response, error)

func (*V1Impl) DoList

func (impl *V1Impl) DoList(req *http.Request) ([]map[string]interface{}, error)

type V2Impl

type V2Impl struct {
	Teams        v2Teams
	Repositories v2Repositories
	Users        v2Users
	// contains filtered or unexported fields
}

func NewV2

func NewV2() *V2Impl

anonymous v2 api

func NewV2BasicAuth

func NewV2BasicAuth(user, pass string) *V2Impl

func NewV2Of

func NewV2Of(client *http.Client) *V2Impl

func (*V2Impl) Do

func (impl *V2Impl) Do(req *http.Request) (map[string]interface{}, error)

func (*V2Impl) DoCustom

func (impl *V2Impl) DoCustom(req *http.Request, successV, failureV interface{}) (*http.Response, error)

func (*V2Impl) DoList

func (impl *V2Impl) DoList(req *http.Request) (*ListResult, error)

func (*V2Impl) Next

func (impl *V2Impl) Next(next string) (*ListResult, error)

Jump to

Keyboard shortcuts

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