git

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoChange       = errors.New("no change")
	ErrBranchNotFresh = errors.New("some refs were not updated")
)

Functions

func AddSSHConfig

func AddSSHConfig(cfg config.PipedGit) error

func MakeCommitURL

func MakeCommitURL(repoURL, hash string) (string, error)

MakeCommitURL builds a link to the HTML page of the commit, using the given repoURL and hash.

func MakeDirURL

func MakeDirURL(repoURL, dir, branch string) (string, error)

MakeDirURL builds a link to the HTML page of the directory.

func MakeFileCreationURL

func MakeFileCreationURL(repoURL, dir, branch, filename, value string) (string, error)

MakeFileCreationURL builds a link to create a file under the given directory.

func NewRepo

func NewRepo(dir, gitPath, remote, clonedBranch string, gitEnvs []string) *repo

NewRepo creates a new Repo instance.

func ParseGitURL added in v0.27.0

func ParseGitURL(rawURL string) (u *url.URL, err error)

ParseGitURL parses git url into a URL structure.

Types

type Client

type Client interface {
	// Clone clones a specific git repository to the given destination.
	Clone(ctx context.Context, repoID, remote, branch, destination string) (Repo, error)
	// Clean removes all cache data.
	Clean() error
}

Client is a git client for cloning/fetching git repo. It keeps a local cache for faster future cloning.

func NewClient

func NewClient(opts ...Option) (Client, error)

NewClient creates a new CLient instance for cloning git repositories. After using Clean should be called to delete cache data.

type Commit

type Commit struct {
	Author          string
	Committer       string
	CreatedAt       int
	Hash            string
	AbbreviatedHash string
	Message         string
	Body            string
}

type Option

type Option func(*client)

func WithEmail

func WithEmail(e string) Option

func WithGitEnv

func WithGitEnv(env string) Option

func WithGitEnvForRepo

func WithGitEnvForRepo(remote string, env string) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithUserName

func WithUserName(n string) Option

type Repo

type Repo interface {
	GetPath() string
	GetClonedBranch() string
	Copy(dest string) (Repo, error)

	ListCommits(ctx context.Context, visionRange string) ([]Commit, error)
	GetLatestCommit(ctx context.Context) (Commit, error)
	GetCommitHashForRev(ctx context.Context, rev string) (string, error)
	ChangedFiles(ctx context.Context, from, to string) ([]string, error)
	Checkout(ctx context.Context, commitish string) error
	CheckoutPullRequest(ctx context.Context, number int, branch string) error
	Clean() error

	Pull(ctx context.Context, branch string) error
	MergeRemoteBranch(ctx context.Context, branch, commit, mergeCommitMessage string) error
	Push(ctx context.Context, branch string) error
	CommitChanges(ctx context.Context, branch, message string, newBranch bool, changes map[string][]byte) error
}

Repo provides functions to get and handle git data.

Directories

Path Synopsis
Package gittest is a generated GoMock package.
Package gittest is a generated GoMock package.

Jump to

Keyboard shortcuts

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