stash

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 32 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// ProviderID is the provider ID for BitBucket Server a.k.a Stash.
	ProviderID = gitprovider.ProviderID("stash")
)

ProviderID is the provider ID for BitBucket Server a.k.a Stash.

View Source
const (
	// RepositoriesURI is the URI for the repositories endpoint
	RepositoriesURI = "repos"
)

Variables

View Source
var (
	// ErrorGetRepositoryMultipleItems is returned when the response contains more than one item.
	ErrorGetRepositoryMultipleItems = errors.New("multiple items returned for repo name")
	// ErrAlreadyExists is returned when the repository already exists.
	ErrAlreadyExists = errors.New("resource already exists, cannot create object")
)
View Source
var (
	// ErrBadRequest is returned when a request is malformed.
	ErrBadRequest = fmt.Errorf("Bad request")
)
View Source
var (
	// ErrNotFound is returned when a resource is not found.
	ErrNotFound = fmt.Errorf("the requested resource was not found")
)
View Source
var (
	// ErrorUnexpectedStatusCode is used when an unexpected status code is returned.
	// The expected status code are
	// - 200 for a successful request
	// - 201 for a successful creation
	// - 202 for a successful request that is in progress
	// - 204 for a successful request that returns no content
	// - 400 for a request that is malformed
	// - 404 for a request that fails due to not found
	ErrorUnexpectedStatusCode = errors.New("unexpected status code")
)

Functions

This section is empty.

Types

type Branch

type Branch struct {
	// Session is the session object for the branch.
	Session `json:"sessionInfo,omitempty"`
	// DisplayID is the branch name e.g. main.
	DisplayID string `json:"displayId,omitempty"`
	// ID is the branch reference e.g. refs/heads/main.
	ID string `json:"id,omitempty"`
	// IsDefault is true if this is the default branch.
	IsDefault bool `json:"isDefault,omitempty"`
	// LatestChangeset is the latest changeset on this branch.
	LatestChangeset string `json:"latestChangeset,omitempty"`
	// LatestCommit is the latest commit on this branch.
	LatestCommit string `json:"latestCommit,omitempty"`
	// Type is the type of branch.
	Type string `json:"type,omitempty"`
}

Branch represents a branch of a repository.

type BranchClient

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

BranchClient operates on the branch for a specific repository.

func (*BranchClient) Create

func (c *BranchClient) Create(ctx context.Context, branch, sha string) error

Create creates a branch with the given specifications.

type BranchList

type BranchList struct {
	// Paging is the paging information.
	Paging
	// Branches is the list of branches.
	Branches []*Branch `json:"values,omitempty"`
}

BranchList is a list of branches.

func (*BranchList) GetBranches

func (b *BranchList) GetBranches() []*Branch

GetBranches returns the list of branches.

type Brancher

type Brancher interface {
	CreateBranch(branchName string, r *git.Repository, commitID string) error
}

Brancher interface defines the methods that can be used to create a new branch

type Branches

type Branches interface {
	List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*BranchList, error)
	Get(ctx context.Context, projectKey, repositorySlug, branchID string) (*Branch, error)
	Create(ctx context.Context, projectKey, repositorySlug, branchID, startPoint string) (*Branch, error)
	Default(ctx context.Context, projectKey, repositorySlug string) (*Branch, error)
	SetDefault(ctx context.Context, projectKey, repositorySlug, branchID string) error
}

Branches interface defines the methods that can be used to retrieve branches of a repository.

type BranchesService

type BranchesService service

BranchesService is a client for communicating with stash branches endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*BranchesService) Create added in v0.3.1

func (s *BranchesService) Create(ctx context.Context, projectKey, repositorySlug, branchID, startPoint string) (*Branch, error)

Create creates a branch for a repository. It uses the branchID as the name of the branch and startPoint as the commit to start from. Create uses the endpoint "POST /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*BranchesService) Default

func (s *BranchesService) Default(ctx context.Context, projectKey, repositorySlug string) (*Branch, error)

Default retrieves the default branch of a repository. Default uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches/default". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*BranchesService) Get

func (s *BranchesService) Get(ctx context.Context, projectKey, repositorySlug, branchID string) (*Branch, error)

Get retrieves a stash branch given it's ID i.e a git reference. Get uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches?base&details&filterText&orderBy". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*BranchesService) List

func (s *BranchesService) List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*BranchList, error)

List returns the list of branches. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a BranchList struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*BranchesService) SetDefault added in v0.3.1

func (s *BranchesService) SetDefault(ctx context.Context, projectKey, repositorySlug, branchID string) error

SetDefault updates the default branch of a repository. SetDefault uses the endpoint "PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches/default". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

type CleanCloner

type CleanCloner interface {
	CloneRepository(ctx context.Context, URL string) (r *git.Repository, dir string, err error)
	Cleaner
}

CleanCloner interface defines the methods that can be used to Clone a repository and clean it up afterwards.

type CleanIniter

type CleanIniter interface {
	InitRepository(c *CreateCommit, createRemote bool) (r *git.Repository, dir string, err error)
	Cleaner
}

CleanIniter interface defines the methods that can be used to initialize a repository and clean it up afterwards.

type Cleaner

type Cleaner interface {
	Cleanup(dir string) error
}

Cleaner interface defines the methods that can be used to clean up a directory

type Client

type Client struct {
	// Client is retryable http Client.
	Client *retryablehttp.Client
	// DisableRetries is used to disable the default retry logic.
	DisableRetries bool

	// BaseURL is the base URL for API requests.
	BaseURL *url.URL
	//HeaderFields is the header fields for all requests.
	HeaderFields *http.Header
	// Logger is the logger used to log the request and response.
	Logger logr.Logger

	// Services are used to communicate with the different stash endpoints.
	Users        Users
	Groups       Groups
	Projects     Projects
	Git          Git
	Repositories Repositories
	Branches     Branches
	Commits      Commits
	PullRequests PullRequests
	DeployKeys   DeployKeys
	// contains filtered or unexported fields
}

A Client is a retryable HTTP Client. The Client will automatically retry when it encounters recoverable errors. The Client will also retry when it encounters a 429 Too Many Requests status. The retry logic can be disabled by setting the DisableRetries option to true. This Client is safe to use across multiple goroutines. The Client will rate limit the number of requests per second.

func NewClient

func NewClient(httpClient *http.Client, host string, header *http.Header, logger logr.Logger, opts ...ClientOptionsFunc) (*Client, error)

NewClient returns a new Client given a host name an optional http.Client, a logger, http.Header and ClientOptionsFunc. If the http.Client is nil, a default http.Client is used. If the http.Header is nil, a default http.Header is used. ClientOptionsFunc is an optional function and can be used to configure the client. Example:

c, err := NewClient(
	&http.Client {
		Transport: defaultTransport,
		Timeout:   defaultTimeout,
		}, "https://github.com",
		&http.Header {
			"Content-Type": []string{"application/json"},
		},
		logr.Logger{},
		func(c *Client) {
			c.DisableRetries = true
	})

func (*Client) Do

func (c *Client) Do(request *http.Request) ([]byte, *http.Response, error)

Do performs a request, and returns an http.Response and an error given an http.Request. For an outgoing Client request, the context controls the entire lifetime of a reques: obtaining a connection, sending the request, checking errors and retrying. The response body is closed.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method string, path string, opts ...RequestOptionFunc) (*http.Request, error)

NewRequest creates a request, and returns an http.Request and an error, given a path and optional query, body, and header. Use the currying functions provided to pass in the request options A relative URL path can be provided in path, in which case it is resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Raw

func (c *Client) Raw() *Client

Raw returns the raw http client.

type ClientOptionsFunc

type ClientOptionsFunc func(Client *Client) error

ClientOptionsFunc are options for the Client. It can be used for example to setup a custom http Client.

func WithAuth

func WithAuth(username string, token string) ClientOptionsFunc

WithAuth is used to setup the client authentication.

func WithCABundle added in v0.4.0

func WithCABundle(caBundle []byte) ClientOptionsFunc

WithCABundle is used to setup the client authentication.

type Clone

type Clone struct {
	// Href is the hyperlink to the resource.
	Href string `json:"href,omitempty"`
	// Name is the name of the resource.
	Name string `json:"name,omitempty"`
}

Clone is a hyperlink to another REST resource.

type Commit

type Commit struct {
	// SHA of the commit.
	SHA string `json:"sha,omitempty"`
	// Author is the author of the commit.
	Author *CommitAuthor `json:"author,omitempty"`
	// Committer is the committer of the commit.
	Committer *CommitAuthor `json:"committer,omitempty"`
	// Message is the commit message.
	Message string `json:"message,omitempty"`
	// Tree is the three of git objects that this commit points to.
	Tree string `json:"tree,omitempty"`
	// Parents is the list of parents commit.
	Parents []string `json:"parents,omitempty"`
	// PGPSignature is the PGP signature of the commit.
	PGPSignature string `json:"pgp_signature,omitempty"`
}

Commit is a version of the repository

type CommitAuthor

type CommitAuthor struct {
	// Date is the date of the commit
	Date int64 `json:"date,omitempty"`
	// Name is the name of the author
	Name string `json:"name,omitempty"`
	// Email is the email of the author
	Email string `json:"email,omitempty"`
}

CommitAuthor represents the author or committer of a commit. The commit author may not correspond to a GitHub User.

type CommitClient

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

CommitClient operates on the commits for a specific repository.

func (*CommitClient) Create

func (c *CommitClient) Create(ctx context.Context, branch string, message string, files []gitprovider.CommitFile) (gitprovider.Commit, error)

Create creates a commit with the given specifications.

func (*CommitClient) ListPage

func (c *CommitClient) ListPage(ctx context.Context, branch string, perPage, page int) ([]gitprovider.Commit, error)

ListPage lists repository commits of the given page and page size.

type CommitFile

type CommitFile struct {
	// The path of the file relative to the repository root.
	Path *string `json:"path"`
	// The contents of the file.
	Content *string `json:"content"`
}

CommitFile is a file to commit

type CommitList

type CommitList struct {
	// Paging is the paging information.
	Paging
	// Commits is the list of commits.
	Commits []*CommitObject `json:"values,omitempty"`
}

CommitList represents a list of commits in stash

func (*CommitList) GetCommits

func (c *CommitList) GetCommits() []*CommitObject

GetCommits returns the list of commits

type CommitObject

type CommitObject struct {
	// Session is the session object for the branch.
	Session `json:"sessionInfo,omitempty"`
	// Author is the author of the commit.
	Author User `json:"author,omitempty"`
	// AuthorTimestamp is the timestamp of the author of the commit.
	AuthorTimestamp int64 `json:"authorTimestamp,omitempty"`
	// Committer is the committer of the commit.
	Committer User `json:"committer,omitempty"`
	// CommitterTimestamp is the timestamp of the committer of the commit.
	CommitterTimestamp int64 `json:"committerTimestamp,omitempty"`
	// DisplayID is the display ID of the commit.
	DisplayID string `json:"displayId,omitempty"`
	// ID is the ID of the commit i.e the SHA1.
	ID string `json:"id,omitempty"`
	// Message is the message of the commit.
	Message string `json:"message,omitempty"`
	// Parents is the list of parents of the commit.
	Parents []*Parent `json:"parents,omitempty"`
}

CommitObject represents a commit in stash

type Commits

type Commits interface {
	List(ctx context.Context, projectKey, repositorySlug, branch string, opts *PagingOptions) (*CommitList, error)
	ListPage(ctx context.Context, projectKey, repositorySlug, branch string, perPage, page int) ([]*CommitObject, error)
	Get(ctx context.Context, projectKey, repositorySlug, commitID string) (*CommitObject, error)
}

Commits interface defines the methods that can be used to retrieve commits of a repository.

type CommitsService

type CommitsService service

CommitsService is a client for communicating with stash commits endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*CommitsService) Get

func (s *CommitsService) Get(ctx context.Context, projectKey, repositorySlug, commitID string) (*CommitObject, error)

Get retrieves a stash commit given it's ID i.e a SHA1. Get uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitID}". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*CommitsService) List

func (s *CommitsService) List(ctx context.Context, projectKey, repositorySlug, branch string, opts *PagingOptions) (*CommitList, error)

List returns the list of commits. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a CommitList struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*CommitsService) ListPage

func (s *CommitsService) ListPage(ctx context.Context, projectKey, repositorySlug, branch string, perPage, page int) ([]*CommitObject, error)

ListPage retrieves all commits for a given page. This function handles pagination, HTTP error wrapping, and validates the server result.

type Committer

type Committer interface {
	CreateCommit(rPath string, r *git.Repository, branchName string, c *CreateCommit) (*Commit, error)
}

Committer interface defines the methods that can be used to commit to a repository

type CreateCommit

type CreateCommit struct {
	// Author is the author of the commit.
	Author *CommitAuthor `json:"author,omitempty"`
	// Committer is the committer of the commit.
	Committer *CommitAuthor `json:"committer,omitempty"`
	// Message is the commit message.
	Message string `json:"message,omitempty"`
	// Parents is the list of parents commit.
	Parents []string `json:"parents,omitempty"`
	// URL is the URL of the commit.
	URL string `json:"url,omitempty"`
	// Files is the list of files to commit.
	Files []CommitFile `json:"files,omitempty"`
	// SigningKey denotes a key to sign the commit with. If not nil this key will
	// be used to sign the commit. The private key must be present and already
	// decrypted.
	SignKey *openpgp.Entity `json:"-"`
}

CreateCommit creates a new commit in the repository.

func NewCommit

func NewCommit(opts ...GitCommitOptionsFunc) (*CreateCommit, error)

NewCommit is a helper function to create a CreateCommit object Use the currying functions provided to pass in the commit options

type CreatePullRequest

type CreatePullRequest struct {
	// Closed indicates if the pull request is closed
	Closed bool `json:"closed,omitempty"`
	// Description is the description of the pull request
	Description string `json:"description,omitempty"`
	// FromRef is the source branch or tag
	FromRef Ref `json:"fromRef,omitempty"`
	// Locked indicates if the pull request is locked
	Locked bool `json:"locked,omitempty"`
	// Open indicates if the pull request is open
	Open bool `json:"open,omitempty"`
	// State is the state of the pull request
	State string `json:"state,omitempty"`
	// Title is the title of the pull request
	Title string `json:"title,omitempty"`
	// ToRef is the target branch
	ToRef Ref `json:"toRef,omitempty"`
	// Reviewers is the list of reviewers
	Reviewers []User `json:"reviewers,omitempty"`
}

CreatePullRequest creates a pull request from a source branch or tag to a target branch.

type DeployKey

type DeployKey struct {
	// Session is the session object
	Session `json:"sessionInfo,omitempty"`
	// Key is the key object
	Key `json:"key,omitempty"`
	// Permissions is the key permission
	// Available repository permissions are:
	// REPO_READ
	// REPO_WRITE
	// REPO_ADMIN
	Permission string `json:"permission,omitempty"`
	// Repository is the repository object
	Repository `json:"repository,omitempty"`
}

DeployKey is an access key for a repository

type DeployKeyClient

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

DeployKeyClient operates on the access deploy key list for a specific repository.

func (*DeployKeyClient) Create

Create creates a deploy key with the given specifications.

ErrAlreadyExists will be returned if the resource already exists.

func (*DeployKeyClient) Get

Get returns the key with the given name. name is internally converted to a label. ErrNotFound is returned if the resource does not exist.

func (*DeployKeyClient) List

List lists all repository deploy keys. List returns all available repository deploy keys for the given type, using multiple paginated requests if needed.

func (*DeployKeyClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider. If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type DeployKeyList

type DeployKeyList struct {
	Paging
	DeployKeys []*DeployKey `json:"values,omitempty"`
}

DeployKeyList is a list of access keys

func (*DeployKeyList) GetDeployKeys

func (d *DeployKeyList) GetDeployKeys() []*DeployKey

GetDeployKeys returns the list of deploy keys

type DeployKeys

type DeployKeys interface {
	List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*DeployKeyList, error)
	All(ctx context.Context, projectKey, repositorySlug string) ([]*DeployKey, error)
	Get(ctx context.Context, projectKey, repositorySlug string, keyID int) (*DeployKey, error)
	Create(ctx context.Context, deployKey *DeployKey) (*DeployKey, error)
	Delete(ctx context.Context, projectKey, repositorySlug string, keyID int) error
	UpdateKeyPermission(ctx context.Context, projectKey, repositorySlug string, keyID int, permission string) (*DeployKey, error)
}

DeployKeys interface defines the methods for working with repository access keys

type DeployKeysService

type DeployKeysService service

DeployKeysService is a client for communicating with stash ssh keys endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-ssh-rest.html

func (*DeployKeysService) All

func (s *DeployKeysService) All(ctx context.Context, projectKey, repositorySlug string) ([]*DeployKey, error)

All retrieves all repository keys. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*DeployKeysService) Create

func (s *DeployKeysService) Create(ctx context.Context, deployKey *DeployKey) (*DeployKey, error)

Create creates an access key. Create uses the endpoint "POST /rest/keys/1.0/projects/{projectKey}/repos/{repositorySlug}/ssh". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-ssh-rest.html

func (*DeployKeysService) Delete

func (s *DeployKeysService) Delete(ctx context.Context, projectKey, repositorySlug string, keyID int) error

Delete deletes the access key with the given ID Delete uses the endpoint "Delete /rest/keys/1.0/projects/{projectKey}/repos/{repositorySlug}/ssh/{keyId}". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-ssh-rest.html

func (*DeployKeysService) Get

func (s *DeployKeysService) Get(ctx context.Context, projectKey, repositorySlug string, keyID int) (*DeployKey, error)

Get retrieves an access key given it's ID. Get uses the endpoint "GET /rest/keys/1.0/projects/{projectKey}/repos/{repositorySlug}/ssh/{keyId}". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-ssh-rest.html

func (*DeployKeysService) List

func (s *DeployKeysService) List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*DeployKeyList, error)

List returns the list of access keys for the repository. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a DeployKeyList struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/keys/1.0/projects/{projectKey}/repos/{repositorySlug}/ssh". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-ssh-rest.html

func (*DeployKeysService) UpdateKeyPermission

func (s *DeployKeysService) UpdateKeyPermission(ctx context.Context, projectKey, repositorySlug string, keyID int, permission string) (*DeployKey, error)

UpdateKeyPermission updates the given access key permission UpdateKeyPermission uses the endpoint "PUT /rest/keys/1.0/projects/{projectKey}/ssh/{keyId}/permission/{permission}".

type Doer

type Doer interface {
	Do(req *http.Request) ([]byte, *http.Response, error)
}

Doer is the interface that wraps the basic Do method.

Do makes an http request for req. It returns the response body as a byte slice and any error encountered. It also return a pointer to the response object. Do must not modify the request object.

type FileClient added in v0.5.3

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

FileClient operates on the branch for a specific repository.

func (*FileClient) Get added in v0.5.3

func (c *FileClient) Get(_ context.Context, path, branch string, optFns ...gitprovider.FilesGetOption) ([]*gitprovider.CommitFile, error)

Get fetches and returns the contents of a file from a given branch and path

type Git

Git interface defines the methods that can be used to communicate with the git protocol.

type GitCommitOptionsFunc

type GitCommitOptionsFunc func(c *CreateCommit) error

GitCommitOptionsFunc is a function that returns an error if the commit options are invalid

func WithAuthor

func WithAuthor(author *CommitAuthor) GitCommitOptionsFunc

WithAuthor is a currying function for the Author field

func WithCommitter

func WithCommitter(committer *CommitAuthor) GitCommitOptionsFunc

WithCommitter is a currying function for the Committer field

func WithFiles

func WithFiles(files []CommitFile) GitCommitOptionsFunc

WithFiles is a currying function for the files field

func WithMessage

func WithMessage(message string) GitCommitOptionsFunc

WithMessage is a currying function for the message field

func WithSignature

func WithSignature(signKey *openpgp.Entity) GitCommitOptionsFunc

WithSignature is a currying function for the signKey field

func WithURL

func WithURL(url string) GitCommitOptionsFunc

WithURL is a currying function for the URL field

type GitService

type GitService service

GitService is a client for communicating with stash users endpoint

func (*GitService) Cleanup

func (s *GitService) Cleanup(dir string) error

Cleanup removes the temporary directory created for the repository.

func (*GitService) CloneRepository

func (s *GitService) CloneRepository(ctx context.Context, URL string) (r *git.Repository, dir string, err error)

CloneRepository clones the repository at the given URL to the given path. The repository will be cloned into a temporary directory which shall be clean up by the caller.

func (*GitService) CreateBranch

func (s *GitService) CreateBranch(branchName string, r *git.Repository, commitID string) error

CreateBranch creates a new branch with the given name and checkout the branch. An optional commit id can be provided to checkout the branch at the given commit.

func (*GitService) CreateCommit

func (s *GitService) CreateCommit(rPath string, r *git.Repository, branchName string, c *CreateCommit) (*Commit, error)

CreateCommit creates a commit for the given CommitFiles. The commit is not pushed. The commit is signed with the given SignKey when provided. When committer is nil, author is used as the committer. An optional branch name can be provided to checkout the branch before committing.

func (*GitService) InitRepository

func (s *GitService) InitRepository(c *CreateCommit, createRemote bool) (r *git.Repository, dir string, err error)

InitRepository is a function to create a new repository. The caller must clean up the directory after the function returns.

func (*GitService) Push

func (s *GitService) Push(ctx context.Context, r *git.Repository) error

Push commits the current changes to the remote repository.

type Group

type Group struct {
	// Session is the session object for the group.
	Session Session `json:"sessionInfo,omitempty"`
	// Name is the name of the group.
	Name string `json:"name,omitempty"`
	// Delete is the delete flag for the group.
	Deleteable bool `json:"deletable,omitempty"`
}

Group represents a stash group.

type GroupList

type GroupList struct {
	// Paging is the paging information.
	Paging
	// Groups is the list of stash groups.
	Groups []*Group `json:"values,omitempty"`
}

GroupList represents a list of stash groups.

func (*GroupList) GetGroups

func (g *GroupList) GetGroups() []*Group

GetGroups returns a slice of groups.

type GroupMembers

type GroupMembers struct {
	// Paging is the paging information.
	Paging
	// GroupName is the name of the group.
	GroupName string `json:"-"`
	// Users is the list of stash groups members.
	Users []*User `json:"values,omitempty"`
}

GroupMembers is a list of stash groups members.

func (*GroupMembers) GetGroupMembers

func (m *GroupMembers) GetGroupMembers() []*User

GetGroupMembers retrieves a list of stash groups members.

type Groups

type Groups interface {
	List(ctx context.Context, opts *PagingOptions) (*GroupList, error)
	Get(ctx context.Context, groupName string) (*Group, error)
	ListGroupMembers(ctx context.Context, groupName string, opts *PagingOptions) (*GroupMembers, error)
	AllGroupMembers(ctx context.Context, groupName string) ([]*User, error)
}

Groups interface defines the methods that can be used to retrieve groups and members of a group.

type GroupsService

type GroupsService service

GroupsService is a client for communicating with stash groups endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*GroupsService) AllGroupMembers

func (s *GroupsService) AllGroupMembers(ctx context.Context, groupName string) ([]*User, error)

AllGroupMembers retrieves all group members. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*GroupsService) Get

func (s *GroupsService) Get(ctx context.Context, groupName string) (*Group, error)

Get retrieves a stash group given it's name. Get uses the endpoint "GET /rest/api/1.0/admin/groups". The authenticated user must have the LICENSED_USER permission to call this resource. https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*GroupsService) List

func (s *GroupsService) List(ctx context.Context, opts *PagingOptions) (*GroupList, error)

List retrieves a list of stash groups. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a paging struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/admin/groups". The authenticated user must have the LICENSED_USER permission to call this resource. https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*GroupsService) ListGroupMembers

func (s *GroupsService) ListGroupMembers(ctx context.Context, groupName string, opts *PagingOptions) (*GroupMembers, error)

ListGroupMembers retrieves a list of stash groups members. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a paging struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/admin/groups/more-members". The authenticated user must have the LICENSED_USER permission to call this resource. https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

type IDVersion

type IDVersion struct {
	// ID is the id of the pull request
	ID int `json:"id"`
	// Version is the version of the pull request
	Version int `json:"version"`
}

IDVersion is a pull request id and version

type Key

type Key struct {
	// ID is the key id
	ID int `json:"id,omitempty"`
	// Label is the key label
	Label string `json:"label,omitempty"`
	// Text is the key text
	// For example "text": "ssh-rsa AAAAB3... me@127.0.0.1"
	Text string `json:"text,omitempty"`
}

Key is a ssh key

type Links struct {
	// Self is the hyperlink to the resource.
	Self []Self `json:"self,omitempty"`
	// Clone is a set of hyperlinks to other REST resources.
	Clone []Clone `json:"clone,omitempty"`
}

Links is a set of hyperlinks that link to other related resources.

type MergeResult

type MergeResult struct {
	// Current is the current merge result
	Current bool `json:"current,omitempty"`
	// Outcome is the outcome of the merge
	Outcome string `json:"outcome,omitempty"`
}

MergeResult is the merge result of a pull request

type OrgRepositoriesClient

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

OrgRepositoriesClient operates on repositories the user has access to.

func (*OrgRepositoriesClient) Create

Create creates a repository for the given organization, with the data and options. ErrAlreadyExists will be returned if the resource already exists.

func (*OrgRepositoriesClient) Get

Get returns the repository at the given path. ErrNotFound is returned if the resource does not exist.

func (*OrgRepositoriesClient) List

List all repositories in the given organization. List returns all available repositories, using multiple paginated requests if needed.

func (*OrgRepositoriesClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider. If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type Organization

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

Organization represents a project in the Stash provider.

func (*Organization) APIObject

func (o *Organization) APIObject() interface{}

APIObject returns the underlying value that was returned from the server.

func (*Organization) Get

Get returns the organization's information, Name and description.

func (*Organization) Organization

func (o *Organization) Organization() gitprovider.OrganizationRef

Organization returns the organization reference.

func (*Organization) Teams

Teams gives access to the TeamsClient for this specific organization

type OrganizationsClient

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

OrganizationsClient operates on the projects the user has access to.

func (*OrganizationsClient) Children

Children returns the immediate child-organizations for the specific OrganizationRef o. The OrganizationRef may point to any existing sub-organization. Children returns all available organizations, using multiple paginated requests if needed.

func (*OrganizationsClient) Get

Get a specific organization the user has access to. ErrNotFound is returned if the resource does not exist.

func (*OrganizationsClient) List

List all the organizations the specific user has access to. List returns all available organizations, using multiple paginated requests if needed.

type Paging

type Paging struct {
	// IsLastPage indicates whether another page of items exists.
	IsLastPage bool `json:"isLastPage,omitempty"`
	// Limit indicates how many results to return per page.
	Limit int64 `json:"limit,omitempty"`
	// Size indicates the total number of results..
	Size int64 `json:"size,omitempty"`
	// Start indicates which item should be used as the first item in the page of results.
	Start int64 `json:"start,omitempty"`
	// NexPageStart must be used by the client as the start parameter on the next request.
	// Identifiers of adjacent objects in a page may not be contiguous,
	// so the start of the next page is not necessarily the start of the last page plus the last page's size.
	// Always use nextPageStart to avoid unexpected results from a paged API.
	NextPageStart int64 `json:"nextPageStart,omitempty"`
}

Paging is the paging information.

func (*Paging) IsLast

func (p *Paging) IsLast() bool

IsLast returns true if the paging information indicates that there are no more pages.

type PagingOptions

type PagingOptions struct {
	// Start indicates which item should be used as the first item in the page of results.
	Start int64
	// Limit indicates how many results to return per page.
	Limit int64
}

PagingOptions is the options for paging.

type Parent

type Parent struct {
	// DisplayID is the display ID of the commit.
	DisplayID string `json:"displayId,omitempty"`
	// ID is the ID of the commit i.e the SHA1.
	ID string `json:"id,omitempty"`
}

Parent represents a parent of a commit.

type Participant

type Participant struct {
	// Approved indicates if the participant has approved the pull request
	Approved bool `json:"approved,omitempty"`
	// Role indicates the role of the participant
	Role string `json:"role,omitempty"`
	// Status indicates the status of the participant
	Status string `json:"status,omitempty"`
	// User is the participant
	User `json:"user,omitempty"`
}

Participant is a participant of a pull request

type Project

type Project struct {
	// Session is the http.Response of the last request made to the Stash API.
	Session `json:"sessionInfo,omitempty"`
	// Description is the project description.
	Description string `json:"description,omitempty"`
	// ID is the project ID.
	ID int64 `json:"id,omitempty"`
	// Key is the project key.
	Key string `json:"key,omitempty"`
	// Links is the project hyperlinks.
	Links `json:"links,omitempty"`
	// User is the the authenticated user.
	User `json:"owner,omitempty"`
	// Name is the project name.
	Name string `json:"name,omitempty"`
	// Public is the project public flag.
	Public bool `json:"public,omitempty"`
	// Type is the project type.
	Type string `json:"type,omitempty"`
}

Project represents a Stash project which is a way for teams to group, manage, and organize their repositories.

type ProjectGroupPermission

type ProjectGroupPermission struct {
	// Session is the http.Response of the last request made to the Stash API.
	Session Session `json:"sessionInfo,omitempty"`
	// Group is the group that the permission is for.
	Group struct {
		Name string `json:"name,omitempty"`
	} `json:"group,omitempty"`
	// Permission denotes a group's permission level. Available project permissions are:
	// PROJECT_READ
	// PROJECT_WRITE
	// PROJECT_ADMIN
	Permission string `json:"permission,omitempty"`
}

ProjectGroupPermission is a permission for a given group. The permission is tied to a project. The permission can be either read, write, or admin.

type ProjectGroups

type ProjectGroups struct {
	// Paging is the paging information.
	Paging
	// ProjectKey is the Key of the project.
	ProjectKey string `json:"-"`
	// Groups is the list of groups permissions.
	Groups []*ProjectGroupPermission `json:"values,omitempty"`
}

ProjectGroups represents a list of groups for a given project.

func (*ProjectGroups) GetGroups

func (p *ProjectGroups) GetGroups() []*ProjectGroupPermission

GetGroups returns a slice of ProjectGroupPermission.

type ProjectUserPermission

type ProjectUserPermission struct {
	// Session is the http.Response of the last request made to the Stash API.
	Session Session `json:"sessionInfo,omitempty"`
	// User is the user that the permission is for.
	User User `json:"user,omitempty"`
	// Permission denotes a group's permission level. Available project permissions are:
	// PROJECT_READ
	// PROJECT_WRITE
	// PROJECT_ADMIN
	Permission string `json:"permission,omitempty"`
}

ProjectUserPermission is a permission for a given User. The permission is tied to a project. The permission can be either read, write, or admin.

type ProjectUsers

type ProjectUsers struct {
	// Paging is the paging information.
	Paging
	// ProjectKey is the key of the project.
	ProjectKey string `json:"-"`
	// Users is the list of users permissions.
	Users []*ProjectUserPermission `json:"values,omitempty"`
}

ProjectUsers represents a list of users for a given project.

func (*ProjectUsers) GetUsers

func (p *ProjectUsers) GetUsers() []*ProjectUserPermission

GetUsers returns a slice of ProjectUserPermission.

type Projects

type Projects interface {
	List(ctx context.Context, opts *PagingOptions) (*ProjectsList, error)
	Get(ctx context.Context, projectName string) (*Project, error)
	All(ctx context.Context) ([]*Project, error)
	GetProjectGroupPermission(ctx context.Context, projectKey, groupName string) (*ProjectGroupPermission, error)
	ListProjectGroupsPermission(ctx context.Context, projectKey string, opts *PagingOptions) (*ProjectGroups, error)
	AllGroupsPermission(ctx context.Context, projectKey string) ([]*ProjectGroupPermission, error)
	ListProjectUsersPermission(ctx context.Context, projectKey string, opts *PagingOptions) (*ProjectUsers, error)
}

Projects interface defines the methods that can be used to retrieve projects and related permissions.

type ProjectsList

type ProjectsList struct {
	// Paging is the paging information.
	Paging
	// Projects is the list of projects.
	Projects []*Project `json:"values,omitempty"`
}

ProjectsList is a list of projects

func (*ProjectsList) GetProjects

func (p *ProjectsList) GetProjects() []*Project

GetProjects returns a slice of Project.

type ProjectsService

type ProjectsService service

ProjectsService is a client for communicating with stash projects endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*ProjectsService) All

func (s *ProjectsService) All(ctx context.Context) ([]*Project, error)

All retrieves all projects. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*ProjectsService) AllGroupsPermission

func (s *ProjectsService) AllGroupsPermission(ctx context.Context, projectKey string) ([]*ProjectGroupPermission, error)

AllGroupsPermission retrieves all projects groups permission. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*ProjectsService) Get

func (s *ProjectsService) Get(ctx context.Context, projectName string) (*Project, error)

Get retrieves a project by Name. Get uses the endpoint "GET /rest/api/1.0/projects/?name&permission". The authenticated user must have PROJECT_VIEW permission for the specified project to call this resource. bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*ProjectsService) GetProjectGroupPermission

func (s *ProjectsService) GetProjectGroupPermission(ctx context.Context, projectKey, groupName string) (*ProjectGroupPermission, error)

GetProjectGroupPermission retrieve a group that have been granted at least one permission for the specified project. GetRepositoryGroupPermission uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/permissions/groups?filter". The authenticated user must have PROJECT_ADMIN permission for the specified project

func (*ProjectsService) List

List retrieves a list of projects. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a ProjectsList struct is returned. It contains paging information to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects". bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*ProjectsService) ListProjectGroupsPermission

func (s *ProjectsService) ListProjectGroupsPermission(ctx context.Context, projectKey string, opts *PagingOptions) (*ProjectGroups, error)

ListProjectGroupsPermission retrieves a list of groups and their permissions for a given project. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a ProjectGroups struct is returned. It contains paging information to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/permissions/groups". The authenticated user must have PROJECT_ADMIN permission for the specified project or a higher global permission to call this resource. bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*ProjectsService) ListProjectUsersPermission

func (s *ProjectsService) ListProjectUsersPermission(ctx context.Context, projectKey string, opts *PagingOptions) (*ProjectUsers, error)

ListProjectUsersPermission retrieves a list of users and their permissions for a given project. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a ProjectUsers struct is returned. It contains paging information to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/permissions/users". The authenticated user must have PROJECT_ADMIN permission for the specified project or a higher global permission to call this resource. bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

type Properties

type Properties struct {
	// MergeResult is the merge result of the pull request
	MergeResult MergeResult `json:"mergeResult,omitempty"`
	// OpenTaskCount is the number of open tasks
	OpenTaskCount float64 `json:"openTaskCount,omitempty"`
	// ResolvedTaskCount is the number of resolved tasks
	ResolvedTaskCount float64 `json:"resolvedTaskCount,omitempty"`
}

Properties are the properties of a pull request

type ProviderClient

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

ProviderClient is an interface that allows talking to a Git provider.

func NewStashClient

func NewStashClient(username, token string, optFns ...gitprovider.ClientOption) (*ProviderClient, error)

NewStashClient creates a new Client instance for Stash API endpoints. The client accepts a username+token as an argument, which is used to authenticate. The host name is used to construct the base URL for the Stash API. Variadic parameters gitprovider.ClientOption are used to pass additional options to the gitprovider.Client.

func (*ProviderClient) HasTokenPermission

func (p *ProviderClient) HasTokenPermission(_ context.Context, _ gitprovider.TokenPermission) (bool, error)

HasTokenPermission returns a boolean indicating whether the supplied token has the requested permission.

func (*ProviderClient) OrgRepositories

func (p *ProviderClient) OrgRepositories() gitprovider.OrgRepositoriesClient

OrgRepositories returns the OrgRepositoriesClient handling sets of repositories in an organization.

func (*ProviderClient) Organizations

func (p *ProviderClient) Organizations() gitprovider.OrganizationsClient

Organizations returns the OrganizationsClient handling sets of organizations.

func (*ProviderClient) ProviderID

func (p *ProviderClient) ProviderID() gitprovider.ProviderID

ProviderID returns the provider ID "gostash.. This field cannot be changed.

func (*ProviderClient) Raw

func (p *ProviderClient) Raw() interface{}

Raw returns the Go Stash client http.Client used under the hood for accessing Stash.

func (*ProviderClient) SupportedDomain

func (p *ProviderClient) SupportedDomain() string

SupportedDomain returns the host endpoint for this client, e.g. "mystash.com:7990" This allows a higher-level user to know what Client to use for what endpoints. This field is set at client creation time, and can't be changed.

func (*ProviderClient) UserRepositories

func (p *ProviderClient) UserRepositories() gitprovider.UserRepositoriesClient

UserRepositories returns the UserRepositoriesClient handling sets of repositories for a user.

type PullRequest

type PullRequest struct {
	// Session is the session of the pull request
	Session `json:"sessionInfo,omitempty"`
	// Author is the author of the pull request
	Author *Participant `json:"author,omitempty"`
	// Closed indicates if the pull request is closed
	Closed bool `json:"closed,omitempty"`
	// CreatedDate is the creation date of the pull request
	CreatedDate int64 `json:"createdDate,omitempty"`
	// Description is the description of the pull request
	Description string `json:"description,omitempty"`
	// FromRef is the source branch or tag
	FromRef Ref `json:"fromRef,omitempty"`
	IDVersion
	// Links is a set of hyperlinks that link to other related resources.
	Links `json:"links,omitempty"`
	// Locked indicates if the pull request is locked
	Locked bool `json:"locked,omitempty"`
	// Open indicates if the pull request is open
	Open bool `json:"open,omitempty"`
	// Participants are the participants of the pull request
	Participants []Participant `json:"participants,omitempty"`
	// Properties are the properties of the pull request
	Properties Properties `json:"properties,omitempty"`
	// Reviewers are the reviewers of the pull request
	Reviewers []Participant `json:"reviewers,omitempty"`
	// State is the state of the pull request
	State string `json:"state,omitempty"`
	// Title is the title of the pull request
	Title string `json:"title,omitempty"`
	// ToRef is the target branch
	ToRef Ref `json:"toRef,omitempty"`
	// UpdatedDate is the update date of the pull request
	UpdatedDate int64 `json:"updatedDate,omitempty"`
}

PullRequest is a pull request

type PullRequestClient

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

PullRequestClient operates on the pull requests for a specific repository.

func (*PullRequestClient) Create

func (c *PullRequestClient) Create(ctx context.Context, title, branch, baseBranch, description string) (gitprovider.PullRequest, error)

Create creates a pull request with the given specifications.

func (*PullRequestClient) Edit added in v0.10.0

Edit modifies an existing PR. Please refer to "EditOptions" for details on which data can be edited.

func (*PullRequestClient) Get

Get returns the pull request with the given number.

func (*PullRequestClient) List

List returns all pull requests for the given repository.

func (*PullRequestClient) Merge

Merge merges the pull request. Stash does not support message and merge strategy options for pull requests automatic merges.

type PullRequestList

type PullRequestList struct {
	// Paging is the paging information
	Paging
	// PullRequests are the pull requests
	PullRequests []*PullRequest `json:"values,omitempty"`
}

PullRequestList is a list of pull requests

func (*PullRequestList) GetPullRequests

func (p *PullRequestList) GetPullRequests() []*PullRequest

GetPullRequests returns a list of pull requests

type PullRequests

type PullRequests interface {
	Get(ctx context.Context, projectKey, repositorySlug string, prID int) (*PullRequest, error)
	List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*PullRequestList, error)
	All(ctx context.Context, projectKey, repositorySlug string) ([]*PullRequest, error)
	Create(ctx context.Context, projectKey, repositorySlug string, pr *CreatePullRequest) (*PullRequest, error)
	Update(ctx context.Context, projectKey, repositorySlug string, pr *PullRequest) (*PullRequest, error)
	Merge(ctx context.Context, projectKey, repositorySlug string, prID int, version int) (*PullRequest, error)
	Delete(ctx context.Context, projectKey, repositorySlug string, IDVersion IDVersion) error
}

PullRequests interface defines the methods that can be used to retrieve pull requests of a repository.

type PullRequestsService

type PullRequestsService service

PullRequestsService is a client for communicating with stash pull requests endpoint bitbucket-server API docs: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*PullRequestsService) All

func (s *PullRequestsService) All(ctx context.Context, projectKey, repositorySlug string) ([]*PullRequest, error)

All retrieves all pull requests for a given repository. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*PullRequestsService) Create

func (s *PullRequestsService) Create(ctx context.Context, projectKey, repositorySlug string, pr *CreatePullRequest) (*PullRequest, error)

Create creates a pull request. Create uses the endpoint "POST /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests".

func (*PullRequestsService) Delete

func (s *PullRequestsService) Delete(ctx context.Context, projectKey, repositorySlug string, IDVersion IDVersion) error

Delete deletes the pull request with the given ID Delete uses the endpoint "DELETE /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}". To call this resource, users must: - be the pull request author, if the system is configured to allow authors to delete their own pull requests (this is the default) OR - have repository administrator permission for the repository the pull request is targeting A body containing the ID and version of the pull request must be provided with this request.

{
  "id": 1,
  "version": 1
}

func (*PullRequestsService) Get

func (s *PullRequestsService) Get(ctx context.Context, projectKey, repositorySlug string, prID int) (*PullRequest, error)

Get retrieves a pull request given it's ID. Get uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*PullRequestsService) List

func (s *PullRequestsService) List(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*PullRequestList, error)

List returns the list of pull requests. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a PullRequestsList struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests". https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html

func (*PullRequestsService) Merge

func (s *PullRequestsService) Merge(ctx context.Context, projectKey, repositorySlug string, prID int, version int) (*PullRequest, error)

Merge the pull request with the given ID and version. Merge uses the endpoint "POST /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/merge?version".

func (*PullRequestsService) Update

func (s *PullRequestsService) Update(ctx context.Context, projectKey, repositorySlug string, pr *PullRequest) (*PullRequest, error)

Update updates the pull request with the given ID Update uses the endpoint "PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}".

type Pusher

type Pusher interface {
	Push(ctx context.Context, r *git.Repository) error
}

Pusher interface defines the methods that can be used to push to a repository

type RateLimiter

type RateLimiter interface {
	Wait(context.Context) error
}

RateLimiter is the interface that wraps the basic Wait method. All rate limiters must implement this interface.

type Ref

type Ref struct {
	// DisplayID is the reference name
	DisplayID string `json:"displayId,omitempty"`
	// ID is the reference id i.e a git reference
	ID string `json:"id,omitempty"`
	// LatestCommit is the latest commit of the reference
	LatestCommit string `json:"latestCommit,omitempty"`
	// Repository is the repository of the reference
	Repository `json:"repository,omitempty"`
	// Type is the type of the reference
	Type string `json:"type,omitempty"`
}

Ref represents a git reference

type Repositories

type Repositories interface {
	RepositoryManager
	RepositoryPermissionManager
}

Repositories interface defines the operations for working with repositories.

type RepositoriesService

type RepositoriesService service

RepositoriesService is a client for communicating with stash repositories endpoints Stash API docs: https://docs.atlassian.com/DAC/rest/stash/3.11.3/stash-rest.html

func (*RepositoriesService) All

func (s *RepositoriesService) All(ctx context.Context, projectKey string) ([]*Repository, error)

All retrieves all repositories for a given project. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*RepositoriesService) AllGroupsPermission

func (s *RepositoriesService) AllGroupsPermission(ctx context.Context, projectKey, repositorySlug string) ([]*RepositoryGroupPermission, error)

AllGroupsPermission retrieves all repository groups permission. This function handles pagination, HTTP error wrapping, and validates the server result.

func (*RepositoriesService) Create

func (s *RepositoriesService) Create(ctx context.Context, projectKey string, repository *Repository) (*Repository, error)

Create creates a new repository Create uses the endpoint "POST /rest/api/1.0/projects/{projectKey}/repos". The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource.

func (*RepositoriesService) Delete

func (s *RepositoriesService) Delete(ctx context.Context, projectKey, repoSlug string) error

Delete deletes the repository with the given slug Delete uses the endpoint "DELETE /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}".

func (*RepositoriesService) Get

func (s *RepositoriesService) Get(ctx context.Context, projectKey, repoSlug string) (*Repository, error)

Get returns the repository with the given slug Accessing personal repositories via REST is achieved through the normal project-centric REST URLs using the user's slug prefixed by tilde as the project key. example: http://example.com/rest/api/1.0/projects/~johnsmith/repos/{repositorySlug}

func (*RepositoriesService) GetRepositoryGroupPermission

func (s *RepositoriesService) GetRepositoryGroupPermission(ctx context.Context, projectKey, repositorySlug, groupName string) (*RepositoryGroupPermission, error)

GetRepositoryGroupPermission retrieve a group that have been granted at least one permission for the specified repository. GetRepositoryGroupPermission uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/groups?filter". The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.

func (*RepositoriesService) List

func (s *RepositoriesService) List(ctx context.Context, projectKey string, opts *PagingOptions) (*RepositoryList, error)

List lists all repositories in a project Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a RepositoryList struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos". Accessing personal repositories via REST is achieved through the normal project-centric REST URLs using the user's slug prefixed by tilde as the project key. example: http://example.com/rest/api/1.0/projects/~johnsmith/repos

func (*RepositoriesService) ListRepositoryGroupsPermission

func (s *RepositoriesService) ListRepositoryGroupsPermission(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*RepositoryGroups, error)

ListRepositoryGroupsPermission retrieve a page of groups that have been granted at least one permission for the specified repository. ListRepositoryGroupsPermission uses the endpoint "GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/groups?filter". The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.

func (*RepositoriesService) ListRepositoryUsersPermission

func (s *RepositoriesService) ListRepositoryUsersPermission(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*RepositoryUsers, error)

ListRepositoryUsersPermission retrieve a page of groups that have been granted at least one permission for the specified repository. ListRepositoryUsersPermission uses the endpoint "PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/users?filter". The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.

func (*RepositoriesService) Update

func (s *RepositoriesService) Update(ctx context.Context, projectKey, repositorySlug string, repository *Repository) (*Repository, error)

Update updates the repository with the given slug The repository's slug is derived from its name. If the name changes the slug may also change. Update uses the endpoint "PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}".

func (*RepositoriesService) UpdateRepositoryGroupPermission

func (s *RepositoriesService) UpdateRepositoryGroupPermission(ctx context.Context, projectKey, repositorySlug string, permission *RepositoryGroupPermission) error

UpdateRepositoryGroupPermission Promote or demote a group's permission level for the specified repository. UpdateRepositoryGroupPermission uses the endpoint "PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/groups?permission&name".

type Repository

type Repository struct {
	// Session is the session information for the request.
	Session `json:"sessionInfo,omitempty"`
	// Description is the repository description.
	Description string `json:"description,omitempty"`
	// Forkable is true if the repository is forkable.
	Forkable bool `json:"forkable,omitempty"`
	// HierarchyID is the unique ID of the repository's parent.
	HierarchyID string `json:"hierarchyId,omitempty"`
	// ID is the unique ID of the repository.
	ID float64 `json:"id,omitempty"`
	// Links is the links to other resources.
	Links `json:"links,omitempty"`
	// Name is the repository name.
	Name string `json:"name,omitempty"`
	// Project is the project the repository belongs to.
	Project Project `json:"project,omitempty"`
	// Public is true if the repository is public.
	Public bool `json:"public,omitempty"`
	// ScmID is the unique ID of the repository's SCM.
	ScmID string `json:"scmId,omitempty"`
	// Slug is the unique slug of the repository.
	Slug string `json:"slug,omitempty"`
	// State is the state of the repository.
	State string `json:"state,omitempty"`
	// StatusMessage is the status message of the repository.
	StatusMessage string `json:"statusMessage,omitempty"`
	// DefaultBranch is the default branch of the repository.
	DefaultBranch string `json:"defaultBranch,omitempty"`
}

Repository represents a stash repository

type RepositoryGroupPermission

type RepositoryGroupPermission struct {
	// Session is the session information for the request.
	Session `json:"sessionInfo,omitempty"`
	// Group is the group to which the permission applies.
	Group struct {
		Name string `json:"name,omitempty"`
	} `json:"group,omitempty"`
	// Permission denotes a group's permission level. Available repository permissions are:
	// REPO_READ
	// REPO_WRITE
	// REPO_ADMIN
	Permission string `json:"permission,omitempty"`
}

RepositoryGroupPermission is a permission for a given group. Repository permissions allow you to manage access to a repository beyond that already granted from project permissions. The permission is tied to a repository. The permission can be either read, write, or admin.

type RepositoryGroups

type RepositoryGroups struct {
	// Paging is the paging information.
	Paging
	// ProjectKey is the project key for the project.
	ProjectKey string `json:"-"`
	// RepositorySlug is the repository slug for the repository.
	RepositorySlug string `json:"-"`
	// Groups is the list of groups permissions.
	Groups []*RepositoryGroupPermission `json:"values,omitempty"`
}

RepositoryGroups represents a list of groups for a given repository.

func (*RepositoryGroups) GetGroups

func (p *RepositoryGroups) GetGroups() []*RepositoryGroupPermission

GetGroups returns the list of groups permissions for the repository.

type RepositoryList

type RepositoryList struct {
	// Paging is the paging information for the list of repositories.
	Paging
	// Repositories is the list of repositories.
	Repositories []*Repository `json:"values,omitempty"`
}

RepositoryList is a list of repositories

func (*RepositoryList) GetRepositories

func (p *RepositoryList) GetRepositories() []*Repository

GetRepositories returns the list of repositories permissions for the repository.

type RepositoryManager

type RepositoryManager interface {
	List(ctx context.Context, projectKey string, opts *PagingOptions) (*RepositoryList, error)
	All(ctx context.Context, projectKey string) ([]*Repository, error)
	Get(ctx context.Context, projectKey, repoSlug string) (*Repository, error)
	Create(ctx context.Context, projectKey string, repository *Repository) (*Repository, error)
	Update(ctx context.Context, projectKey, repositorySlug string, repository *Repository) (*Repository, error)
	Delete(ctx context.Context, projectKey, repoSlug string) error
}

RepositoryManager interface defines the CRUD operations for repositories.

type RepositoryPermissionManager

type RepositoryPermissionManager interface {
	GetRepositoryGroupPermission(ctx context.Context, projectKey, repositorySlug, groupName string) (*RepositoryGroupPermission, error)
	ListRepositoryGroupsPermission(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*RepositoryGroups, error)
	AllGroupsPermission(ctx context.Context, projectKey, repositorySlug string) ([]*RepositoryGroupPermission, error)
	UpdateRepositoryGroupPermission(ctx context.Context, projectKey, repositorySlug string, permission *RepositoryGroupPermission) error
	ListRepositoryUsersPermission(ctx context.Context, projectKey, repositorySlug string, opts *PagingOptions) (*RepositoryUsers, error)
}

RepositoryPermissionManager interface defines the operations for working with repository permissions.

type RepositoryUserPermission

type RepositoryUserPermission struct {
	// Session is the session information for the request.
	Session    `json:"sessionInfo,omitempty"`
	User       `json:"user,omitempty"`
	Permission string `json:"permission,omitempty"`
}

RepositoryUserPermission is a permission for a given user. Repository permissions allow you to manage access to a repository beyond that already granted from project permissions. The permission is tied to a repository. The permission can be either read, write, or admin.

type RepositoryUsers

type RepositoryUsers struct {
	Paging
	ProjectKey     string                      `json:"-"`
	RepositorySlug string                      `json:"-"`
	Users          []*RepositoryUserPermission `json:"values,omitempty"`
}

RepositoryUsers is a list of users that have been granted at least one permission for the specified repository.

func (*RepositoryUsers) GetUsers

func (p *RepositoryUsers) GetUsers() []*RepositoryUserPermission

GetUsers return a list of users permissions for the repository.

type RequestOptionFunc

type RequestOptionFunc func(*requestOptions)

RequestOptionFunc is a function that set request options.

func WithBody

func WithBody(body io.Reader) RequestOptionFunc

WithBody adds the body to the request.

func WithHeader

func WithHeader(header http.Header) RequestOptionFunc

WithHeader adds the headers to the request.

func WithQuery

func WithQuery(query url.Values) RequestOptionFunc

WithQuery adds the query parameters to the request.

type Self

type Self struct {
	Href string `json:"href,omitempty"`
}

Self indicates the hyperlink to a REST resource.

type Session

type Session struct {
	// UserID is the ID of the user making the request.
	UserID string `json:"userID,omitempty"`
	// UserName is the name of the user making the request.
	UserName string `json:"userName,omitempty"`
	// SessionID is the ID of the session.
	SessionID string `json:"sessionID,omitempty"`
	// RequestID is the ID of the request.
	RequestID string `json:"requestID,omitempty"`
}

Session keeps a record of a request for a given user.

type Team

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

Team represents a group in the Stash provider.

func (*Team) APIObject

func (t *Team) APIObject() interface{}

APIObject returns the Users that ware part of this team.

func (*Team) Get

func (t *Team) Get() gitprovider.TeamInfo

Get returns the team's information, Name and members.

func (*Team) Organization

func (t *Team) Organization() gitprovider.OrganizationRef

Organization returns the organization that this team belongs to.

type TeamAccessClient

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

TeamAccessClient operates on the teams list for a specific repository.

func (*TeamAccessClient) Create

Create adds a given team to the repo's team access control list. The team shall exist in Stash. ErrAlreadyExists will be returned if the resource already exists.

func (*TeamAccessClient) Get

Get a team's access permission for a given repository. Teams are groups in Stash. ErrNotFound is returned if the resource does not exist.

func (*TeamAccessClient) List

List lists the team access control list for this repository. List returns all available team access lists, using multiple paginated requests if needed.

func (*TeamAccessClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type TeamsClient

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

TeamsClient handles teams organization-wide.

func (*TeamsClient) Get

func (c *TeamsClient) Get(ctx context.Context, teamName string) (gitprovider.Team, error)

Get a team (stash group). teamName must not be an empty string. ErrNotFound is returned if the resource does not exist.

func (*TeamsClient) List

func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error)

List teams (stash groups). ErrNotFound is returned if the resource does not exist.

type TreeClient added in v0.9.0

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

TreeClient operates on the trees in a specific repository.

func (*TreeClient) Get added in v0.9.0

func (c *TreeClient) Get(ctx context.Context, sha string, recursive bool) (*gitprovider.TreeInfo, error)

Get returns a tree

func (*TreeClient) List added in v0.9.0

func (c *TreeClient) List(ctx context.Context, sha string, path string, recursive bool) ([]*gitprovider.TreeEntry, error)

List files (blob) in a tree

type User

type User struct {
	// Session is the session information for the user.
	Session Session `json:"sessionInfo,omitempty"`
	// Active is true if the user is active.
	Active bool `json:"active,omitempty"`
	// Deletable is true if the user is deletable.
	Deletable bool `json:"deletable,omitempty"`
	// DirectoryName is the directory name where the user is saved.
	DirectoryName string `json:"directoryName,omitempty"`
	// DisplayName is the display name of the user.
	DisplayName string `json:"displayName,omitempty"`
	// EmailAddress is the email address of the user.
	EmailAddress string `json:"emailAddress,omitempty"`
	// ID is the unique identifier of the user.
	ID int64 `json:"id,omitempty"`
	// LastAuthenticationTimestamp is the last authentication timestamp of the user.
	LastAuthenticationTimestamp int64 `json:"lastAuthenticationTimestamp,omitempty"`
	// Links is the links to other resources.
	Links `json:"links,omitempty"`
	// MutableDetails is true if the user is mutable.
	MutableDetails bool `json:"mutableDetails,omitempty"`
	// MutableGroups is true if the groups are mutable.
	MutableGroups bool `json:"mutableGroups,omitempty"`
	// Name is the name of the user.
	Name string `json:"name,omitempty"`
	// Slug is the slug of the user.
	Slug string `json:"slug,omitempty"`
	// Type is the type of the user.
	Type string `json:"type,omitempty"`
}

User represents a Stash user.

type UserList

type UserList struct {
	// Paging is the paging information.
	Paging
	// Users is the list of Stash Users.
	Users []*User `json:"values,omitempty"`
}

UserList is a list of users.

func (*UserList) GetUsers

func (u *UserList) GetUsers() []*User

GetUsers retrieves a list of users.

type UserRepositoriesClient

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

UserRepositoriesClient operates on repositories the user has access to.

func (*UserRepositoriesClient) Create

Create creates a repository for the given organization, with the data and options ErrAlreadyExists will be returned if the resource already exists.

func (*UserRepositoriesClient) Get

Get returns the repository at the given path. ErrNotFound is returned if the resource does not exist.

func (*UserRepositoriesClient) GetUserLogin added in v0.19.0

GetUserLogin returns the authenticated user.

Stash currently doesn't have an endpoint for this, so this is mostly to implement the interface.

func (*UserRepositoriesClient) List

List all repositories for the given user. List returns all available repositories, using multiple paginated requests if needed.

func (*UserRepositoriesClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type Users

type Users interface {
	List(ctx context.Context, opts *PagingOptions) (*UserList, error)
	Get(ctx context.Context, userName string) (*User, error)
}

Users interface defines the methods that can be used to retrieve users.

type UsersService

type UsersService service

UsersService is a client for communicating with stash users endpoint Stash API docs: https://docs.atlassian.com/DAC/rest/stash/3.11.3/stash-rest.html

func (*UsersService) Get

func (s *UsersService) Get(ctx context.Context, userSlug string) (*User, error)

Get retrieves a user by name. Get uses the endpoint "GET /rest/api/1.0/users/{userSlug}".

func (*UsersService) List

func (s *UsersService) List(ctx context.Context, opts *PagingOptions) (*UserList, error)

List retrieves a list of users. Paging is optional and is enabled by providing a PagingOptions struct. A pointer to a paging struct is returned to retrieve the next page of results. List uses the endpoint "GET /rest/api/1.0/users".

Jump to

Keyboard shortcuts

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