git

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Censor

type Censor func(content []byte) []byte

Censor censors content to remove secrets

type ClientFactory

type ClientFactory interface {
	// ClientFromDir creates a client that operates on a repo that has already
	// been cloned to the given directory.
	ClientFromDir(org, repo, dir string) (RepoClient, error)
	// ClientFor creates a client that operates on a new clone of the repo.
	ClientFor(org, repo string, sparseCheckoutPatterns []string) (RepoClient, error)

	// Clean removes the caches used to generate clients
	Clean() error
}

ClientFactory knows how to create clientFactory for repos

func NewClientFactory

func NewClientFactory(opts ...ClientFactoryOpt) (ClientFactory, error)

NewClientFactory allows for the creation of repository clients. It uses github.com without authentication by default.

func NewLocalClientFactory

func NewLocalClientFactory(baseDir string, gitUser UserGetter, censor Censor) (ClientFactory, error)

NewLocalClientFactory allows for the creation of repository clients based on a local filepath remote for testing

func NewNoMirrorClientFactory added in v1.1.34

func NewNoMirrorClientFactory(opts ...ClientFactoryOpt) (ClientFactory, error)

NewNoMirrorClientFactory creates a client factory which does not use mirroring

type ClientFactoryOpt

type ClientFactoryOpt func(*ClientFactoryOpts)

ClientFactoryOpt allows to manipulate the options for a ClientFactory

type ClientFactoryOpts

type ClientFactoryOpts struct {
	// Scheme, defaults to "https" if unset
	Scheme string
	// Host, defaults to "github.com" if unset
	Host string
	// UseSSH, defaults to false
	UseSSH *bool
	// The directory in which the cache should be
	// created. Defaults to the "/var/tmp" on
	// Linux and os.TempDir otherwise
	CacheDirBase *string
	// If unset, publishing action will error
	Username LoginGetter
	// If unset, publishing action will error
	Token TokenGetter
	// The git user to use.
	GitUser UserGetter
	// The censor to use. Not needed for anonymous
	// actions.
	Censor Censor
	// UseUserInURL should we enable the user name and password in the git URLs
	UseUserInURL bool
}

ClientFactoryOpts provides options for configuring the factory

func (*ClientFactoryOpts) Apply

func (cfo *ClientFactoryOpts) Apply(target *ClientFactoryOpts)

Apply allows to use a ClientFactoryOpts as Opt

type Executor

type Executor interface {
	Run(args ...string) ([]byte, error)
}

Executor knows how to execute Git commands

func NewCensoringExecutor

func NewCensoringExecutor(dir string, censor Censor, logger *logrus.Entry) (Executor, error)

NewCensoringExecutor creates a new Executor

type Interactor

type Interactor interface {
	// Directory exposes the directory in which the repository has been cloned
	Directory() string
	// Clean removes the repository. It is up to the user to call this once they are done
	Clean() error
	// Checkout runs `git checkout`
	Checkout(commitlike string) error
	// RevParse runs `git rev-parse`
	RevParse(commitlike string) (string, error)
	// BranchExists determines if a branch with the name exists
	BranchExists(branch string) bool
	// CheckoutNewBranch creates a new branch from HEAD and checks it out
	CheckoutNewBranch(branch string) error
	// Merge merges the commitlike into the current HEAD
	Merge(commitlike string) (bool, error)
	// MergeWithStrategy merges the commitlike into the current HEAD with the strategy
	MergeWithStrategy(commitlike, mergeStrategy string, opts ...MergeOpt) (bool, error)
	// MergeAndCheckout merges all commitlikes into the current HEAD with the appropriate strategy
	MergeAndCheckout(baseSHA string, mergeStrategy string, headSHAs ...string) error
	// Am calls `git am`
	Am(path string) error
	// Fetch calls `git fetch`
	Fetch() error
	// FetchRef fetches the refspec
	FetchRef(refspec string) error
	// FetchFromRemote fetches the branch of the given remote
	FetchFromRemote(remote RemoteResolver, branch string) error
	// CheckoutPullRequest fetches and checks out the synthetic refspec from GitHub for a pull request HEAD
	CheckoutPullRequest(number int) error
	// Config runs `git config`
	Config(key, value string) error
	// Diff runs `git diff`
	Diff(head, sha string) (changes []string, err error)
	// MergeCommitsExistBetween determines if merge commits exist between target and HEAD
	MergeCommitsExistBetween(target, head string) (bool, error)
	// ShowRef returns the commit for a commitlike. Unlike rev-parse it does not require a checkout.
	ShowRef(commitlike string) (string, error)
	// HasSHA checks if a ref is a sha we have fetched locally
	HasSHA(ref string) (string, error)
	// Pull pulls any changes into a branch from the remote
	Pull() error
	// SetSparseCheckoutPatterns initialises att set patterns for sparse checkout
	SetSparseCheckoutPatterns(sparseCheckoutPatterns []string) error
}

Interactor knows how to operate on a git repository cloned from GitHub using a local cache.

type LoginGetter

type LoginGetter func() (login string, err error)

LoginGetter fetches a GitHub login on-demand

type MergeOpt

type MergeOpt struct {
	CommitMessage string
}

MergeOpt holds options for git merge operations. Currently only commit message option is supported.

type Publisher

type Publisher interface {
	// Commit stages all changes and commits them with the message
	Commit(title, body string) error
	// PushToFork pushes the local state to the fork remote
	PushToFork(branch string, force bool) error
	// PushToCentral pushes the local state to the central remote
	PushToCentral(branch string, force bool) error
}

Publisher knows how to publish local work to a remote

type RemoteResolver

type RemoteResolver func() (string, error)

RemoteResolver knows how to construct a remote URL for git calls

func HTTPResolver

func HTTPResolver(remote func() (*url.URL, error), username LoginGetter, token TokenGetter) RemoteResolver

HTTPResolver builds http URLs that may optionally contain simple auth credentials, resolved dynamically.

type RemoteResolverFactory

type RemoteResolverFactory interface {
	// CentralRemote returns a resolver for a remote server with an
	// authoritative version of the repository. This type of remote
	// is useful for fetching refs and cloning.
	CentralRemote(org, repo string) RemoteResolver
	// PublishRemote returns a resolver for a remote server with a
	// personal fork of the repository. This type of remote is most
	// useful for publishing local changes.
	PublishRemote(org, repo string) RemoteResolver
}

RemoteResolverFactory knows how to construct remote resolvers for authoritative central remotes (to pull from) and publish remotes (to push to) for a repository. These resolvers are called at run-time to determine remotes for git commands.

type RepoClient

type RepoClient interface {
	Publisher
	Interactor
}

RepoClient exposes interactions with a git repo

type TokenGetter

type TokenGetter func() []byte

TokenGetter fetches a GitHub OAuth token on-demand

type UserGetter

type UserGetter func() (name, email string, err error)

UserGetter fetches a name and email for us in git commits on-demand

Jump to

Keyboard shortcuts

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