stash

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 15 Imported by: 2

README

Stash tools

Go package of Stash tools.

This library uses glide for dependency management.

Installation

make

Usage

go get github.com/xoom/stash

import "github.com/xoom/stash"
Stash Rest API Documentation
NewClient
stashClient := stash.NewClient("stash_user", "stash_pwd", "http://stash-url.local:7990")
CreateRepository
repository, err := stashClient.CreateRepository("PROJ", "slug")
GetRepositories
repository, err := stashClient.GetRepository("PROJ", "slug")
GetBranches
branches, err := stashClient.GetBranches("PROJ", "slug")
GetRepository
repository, err := stashClient.GetRepository("PROJ", "slug")
CreateBranchRestriction
branchRestriction, err := stashClient.CreateBranchRestriction("PROJ", "slug", "develop", "user")
GetBranchRestrictions
branchRestrictions, err := stashClient.GetBranchRestrictions("PROJ", "slug")
DeleteBranchRestriction
err := stashClient.DeleteBranchRestriction("PROJ", "slug", branchRestriction.Id)
GetPullRequests
// get all pull requests
pullRequests, err := stashClient.GetPullRequests("PROJ", "slug", "")

// get pull request by state
state := "OPEN"
pullRequests, err := stashClient.GetPullRequests("PROJ", "slug", state)
GetPullRequest
// get pull request by id
pullRequest, err := stashClient.GetPullRequest("PROJ", "slug", 1)
CreatePullRequest
title     := "A Title"
des       := "A Description"
from      := "feature/file1"
to        := "develop"
reviewers := []string{"bob", "bill"}

pullRequest, err := stashClient.CreatePullRequest("PROJ", "slug", title, desc, from, to, reviewers)
CreateComment
comment, err := stashClient.CreateComment("PROJ", "slug", 1, "build passing")
UpdatePullRequest
title     := "New title"
desc      := "New description"
branch    := "master"

pullRequest, err := stashClient.UpdatePullRequest("PROJ", "slug", "1", 10, title, desc, branch, nil)
GetRawFile
filePath := "foo/bar"
branch   := "develop"

data, _ := stashClient.GetRawFile("PRJ", "slug", filePath, branch)

fmt.Println(string(data))
stash

Development

Local stash instance

Download and run a development instance of stash via a docker image.

# pick a directory where to save the data generated by the container
export STASH_DATA="${HOME}/stash/data"

# for a linux host
$ docker run -u root -v $STASH_DATA:/var/atlassian/application-data/stash atlassian/stash chown -R daemon  /var/atlassian/application-data/stash

$ docker run -v $STASH_DATA:/var/atlassian/application-data/stash --name="stash" -d -p 7990:7990 -p 7999:7999 atlassian/stash

# for a MacOs Host via 'boot2docker'
$ docker run -u root -v $STASH_DATA:/var/atlassian/application-data/stash --name=stash -d -p 7990:7990 -p 7999:7999 atlassian/stash

Open your browser to http://localhost:7990 and follow the setup instructions.

** If your are using boot2docker get your IP via boot2docker ip

Documentation

Overview

Atlassian Stash API package. Stash API Reference: https://developer.atlassian.com/static/rest/stash/3.0.1/stash-rest.html

Index

Constants

This section is empty.

Variables

Functions

func IsRepositoryExists

func IsRepositoryExists(err error) bool

func IsRepositoryNotFound

func IsRepositoryNotFound(err error) bool

Types

type Addon

type Addon struct {
	Links struct {
		Self          string `json:"self"`
		PluginSummary string `json:"plugin-summary"`
		Modify        string `json:"modify"`
		PluginIcon    string `json:"plugin-icon"`
		PluginLogo    string `json:"plugin-logo"`
		Manage        string `json:"manage"`
		Delete        string `json:"delete"`
	} `json:"links"`
	Key              string `json:"key"`
	Enabled          bool   `json:"enabled"`
	EnabledByDefault bool   `json:"enabledByDefault"`
	Version          string `json:"version"`
	Description      string `json:"description"`
	Name             string `json:"name"`
	Modules          []struct {
		Key         string `json:"key"`
		CompleteKey string `json:"completeKey"`
		Links       struct {
			Self   string `json:"self"`
			Plugin string `json:"plugin"`
		} `json:"links"`
		Enabled          bool   `json:"enabled"`
		Optional         bool   `json:"optional"`
		Name             string `json:"name,omitempty"`
		RecognisableType bool   `json:"recognisableType"`
		Broken           bool   `json:"broken"`
		Description      string `json:"description,omitempty"`
	} `json:"modules"`
	UserInstalled           bool `json:"userInstalled"`
	Optional                bool `json:"optional"`
	UnrecognisedModuleTypes bool `json:"unrecognisedModuleTypes"`
	Unloadable              bool `json:"unloadable"`
	Static                  bool `json:"static"`
	UsesLicensing           bool `json:"usesLicensing"`
	Remotable               bool `json:"remotable"`
	Vendor                  struct {
		Name            string `json:"name"`
		MarketplaceLink string `json:"marketplaceLink"`
		Link            string `json:"link"`
	} `json:"vendor"`
}

type Author

type Author struct {
	User User `json:"user"`
}

type Branch

type Branch struct {
	ID              string `json:"id"`
	DisplayID       string `json:"displayId"`
	LatestChangeSet string `json:"latestChangeset"`
	IsDefault       bool   `json:"isDefault"`
}

type BranchPermission

type BranchPermission struct {
	Type   string   `json:"type"`
	Branch string   `json:"value"`
	Users  []string `json:"users"`
	Groups []string `json:"groups"`
}

type BranchRestriction

type BranchRestriction struct {
	Id     int    `json:"id"`
	Branch Branch `json:"branch"`
}

type BranchRestrictions

type BranchRestrictions struct {
	BranchRestriction []BranchRestriction `json:"values"`
}

type Branches

type Branches struct {
	IsLastPage    bool     `json:"isLastPage"`
	Size          int      `json:"size"`
	Start         int      `json:"start"`
	NextPageStart int      `json:"nextPageStart"`
	Branch        []Branch `json:"values"`
}

type Client

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

func (Client) CreateBranchRestriction

func (client Client) CreateBranchRestriction(
	projectKey, repositorySlug, branch, user string,
) (BranchRestriction, error)

func (Client) CreateComment

func (client Client) CreateComment(
	projectKey, repositorySlug, pullRequest, text string,
) (Comment, error)

CreateComment creates a comment for a pull-request.

func (Client) CreateMeshNode added in v1.2.4

func (client Client) CreateMeshNode(
	address string,
) (MeshNode, error)

func (Client) CreateProject

func (client Client) CreateProject(
	projectKey string,
) (Project, error)

func (Client) CreatePullRequest

func (client Client) CreatePullRequest(
	title, description string,
	fromRef, toRef PullRequestRef,
	reviewers []string,
) (PullRequest, error)

CreatePullRequest creates a pull request between branches.

func (Client) CreateRepository

func (client Client) CreateRepository(
	projectKey, repositorySlug string,
) (Repository, error)

func (Client) CreateUser

func (client Client) CreateUser(
	name, password, displayName, email string,
) (User, error)

func (Client) DeleteBranch

func (client Client) DeleteBranch(
	projectKey, repositorySlug, branchName string,
) error

func (Client) DeleteBranchRestriction

func (client Client) DeleteBranchRestriction(
	projectKey, repositorySlug string, id int,
) error

GetRepository returns a repository representation for the given Stash Project key and repository slug.

func (Client) DisableAddon

func (client Client) DisableAddon(
	token string, addon Addon,
) error

func (Client) EnableAddon

func (client Client) EnableAddon(
	token string, addon Addon,
) error

func (Client) ForkRepository added in v1.2.0

func (client Client) ForkRepository(
	projectKey string,
	repositorySlug string,
	forkName string,
) (*Repository, error)

func (Client) GetAddon

func (client Client) GetAddon(upmToken, key string) (Addon, error)

func (Client) GetBranchRestrictions

func (client Client) GetBranchRestrictions(
	projectKey, repositorySlug string,
) (BranchRestrictions, error)

func (Client) GetBranches

func (client Client) GetBranches(
	projectKey, repositorySlug string,
) (map[string]Branch, error)

GetBranches returns a map of branches indexed by branch display name for the given repository.

func (Client) GetCluster added in v1.2.3

func (client Client) GetCluster() (Cluster, error)

func (Client) GetCommit

func (client Client) GetCommit(
	projectKey, repositorySlug, commitHash string,
) (Commit, error)

GetCommit returns a representation of the given commit hash.

func (Client) GetCommits

func (client Client) GetCommits(
	projectKey, repositorySlug, commitSinceHash, commitUntilHash string,
) (Commits, error)

GetCommits returns the commits between two hashes, inclusively.

func (Client) GetMeshNodes added in v1.2.4

func (client Client) GetMeshNodes() ([]MeshNode, error)

func (Client) GetProjectRepositories

func (client Client) GetProjectRepositories(
	projectKey string,
) (map[int]Repository, error)

func (Client) GetPullRequest

func (client Client) GetPullRequest(
	projectKey, repositorySlug, identifier string,
) (PullRequest, error)

GetPullRequest returns a pull request for a project/slug with specified identifier.

func (Client) GetPullRequests

func (client Client) GetPullRequests(
	projectKey, repositorySlug, state string,
) ([]PullRequest, error)

GetPullRequests returns a list of pull requests for a project / slug.

func (Client) GetRawFile

func (client Client) GetRawFile(
	repositoryProjectKey, repositorySlug, filePath, branch string,
) ([]byte, error)

func (Client) GetRepositories

func (client Client) GetRepositories() (map[int]Repository, error)

GetRepositories returns a map of repositories indexed by repository URL.

func (Client) GetRepository

func (client Client) GetRepository(
	projectKey, repositorySlug string,
) (Repository, error)

GetRepository returns a repository representation for the given Stash Project key and repository slug.

func (Client) GetTags

func (client Client) GetTags(
	projectKey, repositorySlug string,
) (map[string]Tag, error)

GetTags returns a map of tags indexed by tag display name for the given repository.

func (Client) GetUPMToken

func (client Client) GetUPMToken() (string, error)

func (Client) GrantRepositoryUserPermission

func (client Client) GrantRepositoryUserPermission(
	projectKey, repositorySlug, user, permission string,
) error

func (Client) InstallAddon

func (client Client) InstallAddon(
	token, path string,
) (string, error)

func (Client) MergePullRequest

func (client Client) MergePullRequest(
	projectKey string,
	repositorySlug string,
	identifier string,
	version int,
) (*MergeResult, error)

func (Client) MoveRepository

func (client Client) MoveRepository(
	projectKey, repositorySlug, newProjectKey string,
) error

func (Client) RemoveRepository

func (client Client) RemoveRepository(projectKey, repositorySlug string) error

func (Client) RenameRepository

func (client Client) RenameRepository(
	projectKey, repositorySlug, newSlug string,
) error

func (Client) RevokeRepositoryUserPermission

func (client Client) RevokeRepositoryUserPermission(
	projectKey, repositorySlug, user string,
) error

func (Client) SetAddonLicense

func (client Client) SetAddonLicense(addon, license string) error

func (Client) UninstallAddon

func (client Client) UninstallAddon(
	token, key string,
) error

func (Client) UpdateGitMeshSettings added in v1.2.4

func (client Client) UpdateGitMeshSettings(settings GitMeshSettings) error

func (Client) UpdatePullRequest

func (client Client) UpdatePullRequest(
	projectKey, repositorySlug, identifier string,
	version int,
	title, description, toRef string,
	reviewers []string,
) (PullRequest, error)

UpdatePullRequest update a pull request.

type Clone

type Clone struct {
	HREF string `json:"href"`
	Name string `json:"name"`
}

type Cluster added in v1.2.3

type Cluster struct {
	LocalNode ClusterNode   `json:"localNode"`
	Running   bool          `json:"running"`
	Nodes     []ClusterNode `json:"nodes"`
}

type ClusterNode added in v1.2.3

type ClusterNode struct {
	Name         string `json:"name"`
	ID           string `json:"id"`
	BuildVersion string `json:"buildVersion"`
	Local        bool   `json:"local"`
}

type Comment

type Comment struct {
	ID int `json:"id"`
}

type CommentResource

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

type Commit

type Commit struct {
	ID        string `json:"id"`
	DisplayID string `json:"displayId"`
	Author    struct {
		Name         string `json:"name"`
		EmailAddress string `json:"emailAddress"`
	} `json:"author"`
	AuthorTimestamp int64 `json:"authorTimestamp"` // in milliseconds since the epoch
	Attributes      struct {
		JiraKeys []string `json:"jira-key"`
	} `json:"attributes"`
}

type Commits

type Commits struct {
	Commits []Commit `json:"values"`
}

type GitMeshSettings added in v1.2.4

type GitMeshSettings struct {
	IsRefreshing              bool `json:"isRefreshing"`
	RepositoryCreationEnabled bool `json:"repositoryCreationEnabled"`
}
type Links struct {
	Clones []Clone `json:"clone"`
}

type MergeResult

type MergeResult struct {
	PullRequest

	Errors []struct {
		Conflicted    bool
		ExceptionName string
		Message       string
		Vetoes        []struct {
			DetailedMessage string
			SummaryMessage  string
		}
	}
}

type MeshNode added in v1.2.4

type MeshNode struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	RPCURL  string `json:"rpcUrl"`
	Offline bool   `json:"offline"`
}

type Page

type Page struct {
	IsLastPage    bool `json:"isLastPage"`
	Size          int  `json:"size"`
	Start         int  `json:"start"`
	NextPageStart int  `json:"nextPageStart"`
}

type Project

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

type PullRequest

type PullRequest struct {
	ID          int        `id:"closed"`
	Version     int        `            json:"version"`
	Closed      bool       `            json:"closed"`
	Open        bool       `            json:"open"`
	State       string     `            json:"state"`
	Title       string     `            json:"title"`
	Description string     `            json:"description"`
	FromRef     Ref        `            json:"fromRef"`
	ToRef       Ref        `            json:"toRef"`
	CreatedDate int64      `            json:"createdDate"`
	UpdatedDate int64      `            json:"updatedDate"`
	Reviewers   []Reviewer `            json:"reviewers"`
	Author      Author     `            json:"author"`
}

type PullRequestProject

type PullRequestProject struct {
	Key string `json:"key"`
}

type PullRequestRef

type PullRequestRef struct {
	Id         string                `json:"id"`
	Repository PullRequestRepository `json:"repository"`
}

type PullRequestRepository

type PullRequestRepository struct {
	Slug    string             `json:"slug"`
	Name    string             `json:"name,omitempty"`
	Project PullRequestProject `json:"project"`
}

type PullRequestResource

type PullRequestResource struct {
	Version     int    `json:"version,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	// FromRef and ToRef should be PullRequestRef but there is interface{}
	// for omitting empty values. encoding/json can't handle empty structs
	// and omit them.
	FromRef   interface{} `json:"fromRef,omitempty"`
	ToRef     interface{} `json:"toRef,omitempty"`
	Reviewers []Reviewer  `json:"reviewers,omitempty"`
}

type PullRequests

type PullRequests struct {
	Page
	PullRequests []PullRequest `json:"values"`
}

type Ref

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

type Repositories

type Repositories struct {
	IsLastPage    bool         `json:"isLastPage"`
	Size          int          `json:"size"`
	Start         int          `json:"start"`
	NextPageStart int          `json:"nextPageStart"`
	Repository    []Repository `json:"values"`
}

type Repository

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

func HasRepository

func HasRepository(
	repositories map[int]Repository,
	url string,
) (Repository, bool)

func (Repository) SshUrl

func (repo Repository) SshUrl() string

SshUrl extracts the SSH-based URL from the repository metadata.

type Reviewer

type Reviewer struct {
	User User `json:"user"`
}

type Stash

type Stash interface {
	CreateProject(projectKey string) (Project, error)
	CreateRepository(projectKey, slug string) (Repository, error)
	RenameRepository(projectKey, slug, newslug string) error
	MoveRepository(projectKey, slug, newslug string) error
	RemoveRepository(projectKey, slug string) error
	ForkRepository(projectKey, slug, forkSlug string) (*Repository, error)
	GetRepositories() (map[int]Repository, error)
	GetProjectRepositories(projectKey string) (map[int]Repository, error)
	GetBranches(
		projectKey, repositorySlug string,
	) (map[string]Branch, error)
	GetTags(projectKey, repositorySlug string) (map[string]Tag, error)
	CreateBranchRestriction(
		projectKey, repositorySlug, branch, user string,
	) (BranchRestriction, error)
	GetBranchRestrictions(
		projectKey, repositorySlug string,
	) (BranchRestrictions, error)
	DeleteBranchRestriction(projectKey, repositorySlug string, id int) error
	GetRepository(projectKey, repositorySlug string) (Repository, error)
	GetPullRequests(
		projectKey, repositorySlug, state string,
	) ([]PullRequest, error)
	GetPullRequest(
		projectKey, repositorySlug, identifier string,
	) (PullRequest, error)
	GetRawFile(
		projectKey, repositorySlug, branch, filePath string,
	) ([]byte, error)
	CreatePullRequest(
		title, description string,
		fromRef, toRef PullRequestRef,
		reviewers []string,
	) (PullRequest, error)
	UpdatePullRequest(
		projectKey, repositorySlug, identifier string,
		version int,
		title, description, toRef string,
		reviewers []string,
	) (PullRequest, error)
	MergePullRequest(
		projectKey, repositorySlug, identifier string,
		version int,
	) (*MergeResult, error)
	DeleteBranch(projectKey, repositorySlug, branchName string) error
	GetCommit(projectKey, repositorySlug, commitHash string) (Commit, error)
	GetCommits(
		projectKey, repositorySlug, commitSinceHash, commitUntilHash string,
	) (Commits, error)
	CreateComment(
		projectKey, repositorySlug, pullRequest, text string,
	) (Comment, error)
	GetUPMToken() (string, error)
	GetAddon(upmToken, addon string) (Addon, error)
	InstallAddon(upmToken, path string) (string, error)
	UninstallAddon(upmToken, addon string) error
	EnableAddon(upmToken string, addon Addon) error
	DisableAddon(upmToken string, addon Addon) error
	SetAddonLicense(addon, license string) error
	CreateUser(name, password, displayName, email string) (User, error)
	UpdateGitMeshSettings(settings GitMeshSettings) error
	CreateMeshNode(address string) (MeshNode, error)
	GetMeshNodes() ([]MeshNode, error)
	GetCluster() (Cluster, error)
	GrantRepositoryUserPermission(
		projectKey, repositorySlug, user, permission string,
	) error
	RevokeRepositoryUserPermission(
		projectKey, repositorySlug, user string,
	) error
}

func NewClient

func NewClient(userName, password string, baseURL *url.URL) Stash

type Tag

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

type Tags

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

type User

type User struct {
	Name        string `json:"name"`
	Email       string `json:"emailAddress"`
	Password    string `json:"password,omitempty"`
	DisplayName string `json:"displayName"`
}

Jump to

Keyboard shortcuts

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