git_client

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 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) 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) 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 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 BitBucketWebHookRequest

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

type GitClient

type GitClient interface {
	// Returns true if the repository exists, and false otherwise,
	// as well as any error encountered.
	RepoExists(gitRepoConfig GitRepoConfig) (exists bool, err error)
	// Read 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)
	// Clone a remote repository. Return the path to that repository, and
	// any errors encountered.
	CloneRepo(gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// Checkout a particular branch. Return any errors encountered
	CheckoutBranch(branchName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// Checkout a particular tag. Return any errors encountered
	CheckoutTag(tagName string, gitRepoConfig GitRepoConfig) (directoryPath string, err error)
	// Create a new git repository. Return any errors encountered.
	CreateNewRemoteRepo(gitRepoConfig GitRepoConfig) (fullRepoUrl string, err error)
	// Initialize a repository for the given config
	InitRepo(gitRepoConfig GitRepoConfig) (directory string, err error)
	// Commit a project to new repo with an initialize commit message.
	InitialCommitProjectToRepo(baseDirectory string, gitRepoConfig GitRepoConfig) (err error)
	// Construct a URL suitable for pushing git commits to
	CreateScmRepoUrl(config GitRepoConfig) string
	// Add a webhook
	CreateWebhook(url string, gitConfig 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) 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) 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