git

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanURL

func CleanURL(inputURL string) (string, error)

CleanURL removes the .User part of the string (typically an access token)

func CopyService

func CopyService(serviceName string, source Source, dest Destination, sourceEnvironment, destinationEnvironment string) ([]string, error)

CopyService takes the name of a service to copy from a Source to a Destination. Source, Destination implement Walk() and are typically Repository objects.

Only files under /services/[serviceName]/base/config/* are copied to the destination

Returns the list of files that were copied, and possibly an error.

func CreateClient added in v0.2.1

func CreateClient(token, toURL, repoType string, tlsVerify bool) *scm.Client

CreateClient creates and returns a go-scm GitHub client, using the provided oauth2 token.

func GitError

func GitError(msg, url string) error

GitError returns an error whereby the user part of the url is removed (e.g. an access token) Accepts the message to use and the url to remove the user part from

func IsGitError

func IsGitError(err error) bool

IsGitError performs a cast to see if an error really is of type gitError

Types

type Author

type Author struct {
	Name  string
	Email string
	Token string
}

Author represents the details needed to commit and push to Git, including the auth-token to use when pushing upstream.

type Destination

type Destination interface {
	CopyFile(src, dst string) error
	WriteFile(src io.Reader, dst string) error
}

Destination is implemented by values that can have files written and stored permanently.

type Repo

type Repo interface {
	Destination
	Source
	Clone() error
	Checkout(branch string) error
	CheckoutAndCreate(branch string) error
	DirectoriesUnderPath(path string) ([]os.FileInfo, error)
	GetUniqueEnvironmentFolder() (string, error)
	GetCommitID() string
	StageFiles(filenames ...string) error
	Commit(msg string, author *Author) error
	Push(branch string) error
	DeleteCache() error
}

type Repository

type Repository struct {
	LocalPath string
	RepoURL   string
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(repoURL, localPath string, tlsVerify bool, debug bool) (*Repository, error)

NewRepository creates and returns a local cache of an upstream repository.

The repoURL should be of the form https://github.com/myorg/myrepo. The path should be a local directory where the contents are cloned to.

func (*Repository) Checkout

func (r *Repository) Checkout(branch string) error

func (*Repository) CheckoutAndCreate

func (r *Repository) CheckoutAndCreate(branch string) error

func (*Repository) Clone

func (r *Repository) Clone() error

func (*Repository) Commit

func (r *Repository) Commit(msg string, author *Author) error

Commit does the git commit -m with the msg & author after first running git config commands for the user.name and user.email these are intentionally *not* global settings because we don't want to touch a user's $HOME/.gitconfig This means the settings only apply inside of our local repository cache.

func (*Repository) CopyFile

func (r *Repository) CopyFile(src, dst string) error

func (*Repository) DeleteCache

func (r *Repository) DeleteCache() error

DeleteCache removes the local clones from the promotion cache.

func (*Repository) DirectoriesUnderPath added in v0.2.1

func (r *Repository) DirectoriesUnderPath(path string) ([]os.FileInfo, error)

Returns the directory names of those under a certain path (excluding sub-dirs) Returns an error if a directory list attempt errored

func (*Repository) DisablePush added in v0.2.2

func (r *Repository) DisablePush()

func (*Repository) GetCommitID

func (r *Repository) GetCommitID() string

func (*Repository) GetName

func (r *Repository) GetName() string

func (*Repository) GetUniqueEnvironmentFolder added in v0.2.1

func (r *Repository) GetUniqueEnvironmentFolder() (string, error)

Returns the single directory under the environments folder for a given repo Returns an error if there was a problem in doing so (including if more than one folder found) string return type for ease of mocking, callers would use .Name() anyway

func (*Repository) Push

func (r *Repository) Push(branchName string) error

Does a git push origin *branch name*

func (*Repository) StageFiles

func (r *Repository) StageFiles(filenames ...string) error

This does the git add command on file(s)

func (*Repository) Walk

func (r *Repository) Walk(base string, cb func(prefix, name string) error) error

func (*Repository) WriteFile

func (r *Repository) WriteFile(src io.Reader, dst string) error

type Source

type Source interface {
	// Walk walks the repository tree, calling the callback with the prefix and
	// filename.
	Walk(path string, cb func(prefix, name string) error) error
	GetName() string
}

Source is implemented by values that can provide a list of files for reading from.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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