git_client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRepoNotExist       = errors.New("repository does not exist")
	ErrCredentialsInvalid = errors.New("provided credentials are invalid")
)

common errors

Functions

This section is empty.

Types

type BitBucketClient

type BitBucketClient struct {
	Config     *BitBucketClientConfig
	RestClient *http.Client
}

func NewBitBucketClient

func NewBitBucketClient(config *BitBucketClientConfig) BitBucketClient

func (*BitBucketClient) AddAdminRights added in v0.1.0

func (gitClient *BitBucketClient) AddAdminRights(userID string, gitRepoConfig GitRepoConfig) error

func (*BitBucketClient) CheckoutBranch added in v0.0.3

func (gitClient *BitBucketClient) CheckoutBranch(branchName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*BitBucketClient) CheckoutTag added in v0.0.3

func (gitClient *BitBucketClient) CheckoutTag(tagName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*BitBucketClient) CloneRepo

func (gitClient *BitBucketClient) CloneRepo(gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*BitBucketClient) CreateNewRemoteRepo

func (gitClient *BitBucketClient) CreateNewRemoteRepo(gitRepoConfig GitRepoConfig) (fullRepoUrl string, err error)

func (*BitBucketClient) CreateScmRepoUrl

func (gitClient *BitBucketClient) CreateScmRepoUrl(gitConfig GitRepoConfig) string

https://{user}@egbitbucket.dtvops.net/scm/{domain}/{repo_name}.git

func (*BitBucketClient) CreateWebhook

func (gitClient *BitBucketClient) CreateWebhook(url string, gitConfig GitRepoConfig) error

func (*BitBucketClient) GetFileFromRepo

func (gitClient *BitBucketClient) GetFileFromRepo(filename string, gitRepoConfig GitRepoConfig) (file *os.File, err error)

func (*BitBucketClient) InitRepo

func (gitClient *BitBucketClient) InitRepo(gitRepoConfig GitRepoConfig) (directory string, err error)

func (*BitBucketClient) InitialCommitProjectToRepo

func (gitClient *BitBucketClient) InitialCommitProjectToRepo(baseDirectory string, gitRepoConfig GitRepoConfig) error

func (*BitBucketClient) ListAllReposForProjectKey added in v0.0.4

func (gitClient *BitBucketClient) ListAllReposForProjectKey(projectKey string) ([]string, error)

https://{host}/rest/api/1.0/projects/{projectKey}/repos?limit=1000

func (*BitBucketClient) RepoExists

func (gitClient *BitBucketClient) RepoExists(gitRepoConfig GitRepoConfig) (exists bool, err error)

type BitBucketClientConfig

type BitBucketClientConfig struct {
	GitHost             string `yaml:"git_host" json:"git_host"`
	Username            string `yaml:"username" json:"username"`
	Password            string `yaml:"password" json:"password"`
	AccessToken         string `yaml:"access_token" json:"access_token"`
	Email               string `yaml:"email" json:"email"`
	RestTimeout         int    `yaml:"timeout" json:"timeout"`
	AuthenticationToken string
}

func NewBitBucketClientConfig

func NewBitBucketClientConfig(gitHost, username, password, email, accessToken string, timeout int) (BitBucketClientConfig, error)

type BitBucketProjectResponseItem added in v0.0.4

type BitBucketProjectResponseItem struct {
	Key         string `json:"key"`
	Id          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Public      bool   `json:"public"`
	Type        string `json:"type"`
}

type BitBucketRepoConfig

type BitBucketRepoConfig struct {
	ProjectKey       string
	RepositorySlug   string
	FunctionalDomain string
	ProjectName      string
	Tags             []string
}

REST API URL: clone URL: repo URL: BitBucket implementation of the GitClient interfaces

func NewBitBucketRepoConfig

func NewBitBucketRepoConfig(projectKey, repositorySlug, functionalDomain, projectName string, tags ...string) *BitBucketRepoConfig

func (*BitBucketRepoConfig) ConstructRepoUrl

func (config *BitBucketRepoConfig) ConstructRepoUrl(base string) string

https://{base}/projects/{PROJECT_KEY}/repos

func (*BitBucketRepoConfig) ConstructRestApiUrl

func (config *BitBucketRepoConfig) ConstructRestApiUrl(base string) string

https://{user}@{base}/rest/api/1.0/projects/{PROJECT_KEY}/repos

func (*BitBucketRepoConfig) GetRepoDomain

func (config *BitBucketRepoConfig) GetRepoDomain() string

func (*BitBucketRepoConfig) GetRepoName

func (config *BitBucketRepoConfig) GetRepoName() string

func (*BitBucketRepoConfig) SetRepoName

func (config *BitBucketRepoConfig) SetRepoName(name string)

func (*BitBucketRepoConfig) Validate

func (config *BitBucketRepoConfig) Validate() bool

type BitBucketRepoRequest

type BitBucketRepoRequest struct {
	Name     string `json:"name"`
	ScmId    string `json:"scmId"`
	Forkable bool   `json:"forkable"`
}

type BitBucketRepoResponse added in v0.0.4

type BitBucketRepoResponse struct {
	Size       int                         `json:"size"`
	Limit      int                         `json:"limit"`
	IsLastPage bool                        `json:"isLastPage"`
	Values     []BitBucketRepoResponseItem `json:"values"`
}

func (*BitBucketRepoResponse) GetRepositoryNames added in v0.0.4

func (b *BitBucketRepoResponse) GetRepositoryNames() []string

type BitBucketRepoResponseItem added in v0.0.4

type BitBucketRepoResponseItem struct {
	Slug          string                       `json:"slug"`
	Id            int                          `json:"id"`
	Name          string                       `json:"name"`
	ScmId         string                       `json:"scm_id"`
	State         string                       `json:"state"`
	StatusMessage string                       `json:"status_message"`
	Forkable      bool                         `json:"forkable"`
	Project       BitBucketProjectResponseItem `json:"project"`
}

type BitBucketWebHookRequest

type BitBucketWebHookRequest struct {
	Title              string `json:"title"`
	URL                string `json:"url"`
	CommittersToIgnore string `json:"committersToIgnore"`
	BranchesToIgnore   string `json:"branchesToIgnore"`
	Enabled            bool   `json:"enabled"`
	TagCreated         bool   `json:"tagCreated"`
}

type GitClient

type GitClient interface {
	// RepoExists Returns true if the repository exists, and false otherwise,
	// as well as any error encountered.
	RepoExists(gitRepoConfig GitRepoConfig) (exists bool, err error)
	// GetFileFromRepo Reads a single file from a git repository. Return a pointer to the file,
	// and any errors encountered.
	GetFileFromRepo(filename string, gitRepoConfig GitRepoConfig) (file *os.File, err error)
	// CloneRepo Clones a remote repository. Return the path to that repository, and
	// any errors encountered.
	CloneRepo(gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// CheckoutBranch Checks out a particular branch. Return any errors encountered
	CheckoutBranch(branchName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// CheckoutTag Checks out a particular tag. Return any errors encountered
	CheckoutTag(tagName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// CreateNewRemoteRepo Creates a new git repository. Return any errors encountered.
	CreateNewRemoteRepo(gitRepoConfig GitRepoConfig) (fullRepoUrl string, err error)
	// InitRepo Initializes a repository for the given config
	InitRepo(gitRepoConfig GitRepoConfig) (directory string, err error)
	// InitialCommitProjectToRepo Commits a project to new repo with an initialize commit message.
	InitialCommitProjectToRepo(baseDirectory string, gitRepoConfig GitRepoConfig) (err error)
	// CreateScmRepoUrl Constructs a URL suitable for pushing git commits to
	CreateScmRepoUrl(config GitRepoConfig) string
	// CreateWebhook Adds a webhook
	CreateWebhook(url string, gitConfig GitRepoConfig) error
	// ListAllReposForProjectKey queries the BitBucket REST API to retrieve a list of repository names, or an error
	ListAllReposForProjectKey(projectKey string) ([]string, error)
	// AddAdminRights adds the given userID to the list of admins for a repository
	AddAdminRights(userID string, gitRepoConfig GitRepoConfig) error
}

Interface defines behavior that a Git Client must expose

type GitHubClient

type GitHubClient struct {
	Config     *GitHubClientConfig
	RestClient *http.Client
}

func NewGitHubClient

func NewGitHubClient(config *GitHubClientConfig) GitHubClient

func (*GitHubClient) AddAdminRights added in v0.1.0

func (client *GitHubClient) AddAdminRights(userID string, gitRepoConfig GitRepoConfig) error

func (*GitHubClient) CheckoutBranch added in v0.0.3

func (client *GitHubClient) CheckoutBranch(branchName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*GitHubClient) CheckoutTag added in v0.0.3

func (client *GitHubClient) CheckoutTag(tagName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*GitHubClient) CloneRepo

func (client *GitHubClient) CloneRepo(gitRepoConfig GitRepoConfig) (directoryPath string, err error)

func (*GitHubClient) CreateNewRemoteRepo

func (client *GitHubClient) CreateNewRemoteRepo(gitRepoConfig GitRepoConfig) (fullRepoUrl string, err error)

CreateNewRemoteRepo creates a new empty remote repository with the parameters specified in the GitRepoConfig, and returns any errors encountered

func (*GitHubClient) CreateScmRepoUrl

func (client *GitHubClient) CreateScmRepoUrl(config GitRepoConfig) string

func (*GitHubClient) CreateWebhook

func (client *GitHubClient) CreateWebhook(url string, gitConfig GitRepoConfig) error

func (*GitHubClient) GetFileFromRepo

func (client *GitHubClient) GetFileFromRepo(filename string, gitRepoConfig GitRepoConfig) (file *os.File, err error)

func (*GitHubClient) InitRepo

func (client *GitHubClient) InitRepo(gitRepoConfig GitRepoConfig) (directory string, err error)

func (*GitHubClient) InitialCommitProjectToRepo

func (client *GitHubClient) InitialCommitProjectToRepo(baseDirectory string, gitRepoConfig GitRepoConfig) (err error)

func (*GitHubClient) ListAllReposForProjectKey added in v0.0.4

func (client *GitHubClient) ListAllReposForProjectKey(projectKey string) ([]string, error)

func (*GitHubClient) RepoExists

func (client *GitHubClient) RepoExists(gitRepoConfig GitRepoConfig) (exists bool, err error)

type GitHubClientConfig

type GitHubClientConfig struct {
	GitHost             string `yaml:"git_host" json:"git_host"`
	Username            string `yaml:"username" json:"username"`
	Password            string `yaml:"password" json:"password"`
	AccessToken         string `yaml:"access_token" json:"access_token"`
	AuthenticationToken string
}

func NewGitClientConfig

func NewGitClientConfig(gitHost, username, password, accessToken string) (GitHubClientConfig, error)

type GitRepoConfig

type GitRepoConfig interface {
	// Returns true if the repository configuration is valid, and false otherwise
	Validate() bool
	// construct the URL used to navigate a browser to the configured repository
	ConstructRepoUrl(base string) string
	// Returns the correct URL to use for a REST API Call
	ConstructRestApiUrl(base string) string
	// Returns the provider-specific domain value
	GetRepoDomain() string
	// Returns the repository name
	GetRepoName() string
	// Set the repository name
	SetRepoName(name string)
}

Defines behavior for a set of git repo configuration

type GithubRepoConfig

type GithubRepoConfig struct {
	Domain         string
	RepositoryName string
	Tags           []string
}

REST API URL: https://api.github.com/repos/{DOMAIN}/{REPO_NAME} clone URL: https://github.com/{DOMAIN}/{REPO_NAME}.git repo URL: https://github.com/{DOMAIN}/{REPO_NAME}

func NewGithubRepoConfig

func NewGithubRepoConfig(domain, reponame string) (*GithubRepoConfig, error)

func (*GithubRepoConfig) ConstructRepoUrl

func (g *GithubRepoConfig) ConstructRepoUrl(base string) string

func (*GithubRepoConfig) ConstructRestApiUrl

func (g *GithubRepoConfig) ConstructRestApiUrl(base string) string

func (*GithubRepoConfig) GetRepoDomain

func (g *GithubRepoConfig) GetRepoDomain() string

func (*GithubRepoConfig) GetRepoName

func (g *GithubRepoConfig) GetRepoName() string

func (*GithubRepoConfig) SetRepoName

func (g *GithubRepoConfig) SetRepoName(name string)

func (*GithubRepoConfig) Validate

func (g *GithubRepoConfig) Validate() bool

Jump to

Keyboard shortcuts

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