vcs

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: BSD-3-Clause Imports: 25 Imported by: 10

README

crawlab-vcs

Version Control System (VCS) for Crawlab

Documentation

Index

Constants

View Source
const (
	GitRemoteNameOrigin   = "origin"
	GitRemoteNameUpstream = "upstream"
	GitRemoteNameCrawlab  = "crawlab"
)
View Source
const (
	GitBranchNameMaster  = "master"
	GitBranchNameMain    = "main"
	GitBranchNameRelease = "release"
	GitBranchNameTest    = "test"
	GitBranchNameDevelop = "develop"
)
View Source
const (
	GitRefTypeBranch = "branch"
	GitRefTypeTag    = "tag"
)
View Source
const GitDefaultBranchName = GitBranchNameMaster
View Source
const GitDefaultRemoteName = GitRemoteNameOrigin

Variables

View Source
var (
	ErrInvalidArgsLength               = errors.New("invalid arguments length")
	ErrUnsupportedType                 = errors.New("unsupported type")
	ErrInvalidAuthType                 = errors.New("invalid auth type")
	ErrInvalidOptions                  = errors.New("invalid options")
	ErrRepoAlreadyExists               = errors.New("repo already exists")
	ErrInvalidRepoPath                 = errors.New("invalid repo path")
	ErrUnableToGetCurrentBranch        = errors.New("unable to get current branch")
	ErrUnableToCloneWithEmptyRemoteUrl = errors.New("unable to clone with empty remote url")
	ErrInvalidHeadRef                  = errors.New("invalid head ref")
	ErrNoMatchedRemoteBranch           = errors.New("no matched remote branch")
)
View Source
var GitMemFileSystem = sync.Map{}
View Source
var GitMemStorages = sync.Map{}

Functions

func CreateBareGitRepo

func CreateBareGitRepo(path string) (err error)

func IsGitRepoExists

func IsGitRepoExists(repoPath string) (ok bool)

Types

type Client

type Client interface {
	Init() (err error)
	Dispose() (err error)
	Clone(opts ...GitCloneOption) (err error)
	Checkout(opts ...GitCheckoutOption) (err error)
	Commit(msg string, opts ...GitCommitOption) (err error)
	Pull(opts ...GitPullOption) (err error)
	Push(opts ...GitPushOption) (err error)
	Reset(opts ...GitResetOption) (err error)
}

type GitAuthType

type GitAuthType int
const (
	GitAuthTypeNone GitAuthType = iota
	GitAuthTypeHTTP
	GitAuthTypeSSH
)

type GitCheckoutOption

type GitCheckoutOption func(o *git.CheckoutOptions)

func WithBranch

func WithBranch(branch string) GitCheckoutOption

func WithHash

func WithHash(hash string) GitCheckoutOption

type GitClient

type GitClient struct {
	// contains filtered or unexported fields
}

func CloneGitRepo

func CloneGitRepo(path, url string, opts ...GitCloneOption) (c *GitClient, err error)

func NewGitClient

func NewGitClient(opts ...GitOption) (c *GitClient, err error)

func (*GitClient) Add added in v0.6.1

func (c *GitClient) Add(filePath string) (err error)

func (*GitClient) Checkout

func (c *GitClient) Checkout(opts ...GitCheckoutOption) (err error)

func (*GitClient) CheckoutBranch

func (c *GitClient) CheckoutBranch(branch string, opts ...GitCheckoutOption) (err error)

func (*GitClient) CheckoutBranchFromRef added in v0.6.1

func (c *GitClient) CheckoutBranchFromRef(branch string, ref *plumbing.Reference, opts ...GitCheckoutOption) (err error)

func (*GitClient) CheckoutBranchWithRemote added in v0.6.1

func (c *GitClient) CheckoutBranchWithRemote(branch, remote string, ref *plumbing.Reference, opts ...GitCheckoutOption) (err error)

func (*GitClient) CheckoutBranchWithRemoteFromRef added in v0.6.1

func (c *GitClient) CheckoutBranchWithRemoteFromRef(branch, remote string, ref *plumbing.Reference, opts ...GitCheckoutOption) (err error)

func (*GitClient) CheckoutHash

func (c *GitClient) CheckoutHash(hash string, opts ...GitCheckoutOption) (err error)

func (*GitClient) Commit

func (c *GitClient) Commit(msg string, opts ...GitCommitOption) (err error)

func (*GitClient) CommitAll

func (c *GitClient) CommitAll(msg string, opts ...GitCommitOption) (err error)

func (*GitClient) CreateBranch added in v0.6.1

func (c *GitClient) CreateBranch(branch, remote string, ref *plumbing.Reference) (err error)

func (*GitClient) CreateRemote added in v0.6.1

func (c *GitClient) CreateRemote(cfg *config.RemoteConfig) (r *git.Remote, err error)

func (*GitClient) DeleteRemote added in v0.6.1

func (c *GitClient) DeleteRemote(name string) (err error)

func (*GitClient) Dispose

func (c *GitClient) Dispose() (err error)

func (*GitClient) GetAuthType

func (c *GitClient) GetAuthType() (authType GitAuthType)

func (*GitClient) GetBranches added in v0.6.1

func (c *GitClient) GetBranches() (branches []GitRef, err error)

func (*GitClient) GetCurrentBranch

func (c *GitClient) GetCurrentBranch() (branch string, err error)

func (*GitClient) GetCurrentBranchRef added in v0.6.1

func (c *GitClient) GetCurrentBranchRef() (ref *GitRef, err error)

func (*GitClient) GetIsMem

func (c *GitClient) GetIsMem() (isMem bool)

func (*GitClient) GetLogs

func (c *GitClient) GetLogs() (logs []GitLog, err error)

func (*GitClient) GetLogsWithRefs added in v0.6.1

func (c *GitClient) GetLogsWithRefs() (logs []GitLog, err error)

func (*GitClient) GetPassword added in v0.6.1

func (c *GitClient) GetPassword() (password string)

func (*GitClient) GetPath

func (c *GitClient) GetPath() (path string)

func (*GitClient) GetPrivateKey added in v0.6.1

func (c *GitClient) GetPrivateKey() (key string)

func (*GitClient) GetPrivateKeyPath

func (c *GitClient) GetPrivateKeyPath() (path string)

func (*GitClient) GetRemote added in v0.6.1

func (c *GitClient) GetRemote(name string) (r *git.Remote, err error)

func (*GitClient) GetRemoteRefs added in v0.6.1

func (c *GitClient) GetRemoteRefs(remoteName string) (gitRefs []GitRef, err error)

func (*GitClient) GetRemoteUrl

func (c *GitClient) GetRemoteUrl() (path string)

func (*GitClient) GetRepository

func (c *GitClient) GetRepository() (r *git.Repository)

func (*GitClient) GetStatus added in v0.6.1

func (c *GitClient) GetStatus() (statusList []GitFileStatus, err error)

func (*GitClient) GetTags added in v0.6.1

func (c *GitClient) GetTags() (tags []GitRef, err error)

func (*GitClient) GetUsername

func (c *GitClient) GetUsername() (username string)

func (*GitClient) Init

func (c *GitClient) Init() (err error)

func (*GitClient) IsRemoteChanged added in v0.6.1

func (c *GitClient) IsRemoteChanged() (ok bool, err error)

func (*GitClient) MoveBranch added in v0.6.1

func (c *GitClient) MoveBranch(from, to string) (err error)

func (*GitClient) Pull

func (c *GitClient) Pull(opts ...GitPullOption) (err error)

func (*GitClient) Push

func (c *GitClient) Push(opts ...GitPushOption) (err error)

func (*GitClient) Reset

func (c *GitClient) Reset(opts ...GitResetOption) (err error)

func (*GitClient) SetAuthType added in v0.6.1

func (c *GitClient) SetAuthType(authType GitAuthType)

func (*GitClient) SetIsMem added in v0.6.1

func (c *GitClient) SetIsMem(isMem bool)

func (*GitClient) SetPassword added in v0.6.1

func (c *GitClient) SetPassword(password string)

func (*GitClient) SetPath added in v0.6.1

func (c *GitClient) SetPath(path string)

func (*GitClient) SetPrivateKey added in v0.6.1

func (c *GitClient) SetPrivateKey(key string)

func (*GitClient) SetPrivateKeyPath added in v0.6.1

func (c *GitClient) SetPrivateKeyPath(path string)

func (*GitClient) SetRemoteUrl added in v0.6.1

func (c *GitClient) SetRemoteUrl(url string)

func (*GitClient) SetUsername added in v0.6.1

func (c *GitClient) SetUsername(username string)

type GitCloneOption

type GitCloneOption func(o *git.CloneOptions)

func WithAuthClone

func WithAuthClone(auth transport.AuthMethod) GitCloneOption

func WithDepthClone

func WithDepthClone(depth int) GitCloneOption

func WithNoCheckout

func WithNoCheckout(noCheckout bool) GitCloneOption

func WithRecurseSubmodules

func WithRecurseSubmodules(recurseSubmodules git.SubmoduleRescursivity) GitCloneOption

func WithRemoteName

func WithRemoteName(name string) GitCloneOption

func WithSingleBranch

func WithSingleBranch(singleBranch bool) GitCloneOption

func WithTags

func WithTags(tags git.TagMode) GitCloneOption

func WithURL

func WithURL(url string) GitCloneOption

type GitCommitOption

type GitCommitOption func(o *git.CommitOptions)

func WithAll

func WithAll(all bool) GitCommitOption

func WithAuthor

func WithAuthor(author *object.Signature) GitCommitOption

func WithCommitter

func WithCommitter(committer *object.Signature) GitCommitOption

func WithParents

func WithParents(parents []plumbing.Hash) GitCommitOption

func WithSignKey

func WithSignKey(signKey *openpgp.Entity) GitCommitOption

type GitFileStatus added in v0.6.1

type GitFileStatus struct {
	Path     string          `json:"path"`
	Name     string          `json:"name"`
	IsDir    bool            `json:"is_dir"`
	Staging  string          `json:"staging"`
	Worktree string          `json:"worktree"`
	Extra    string          `json:"extra"`
	Children []GitFileStatus `json:"children"`
}

type GitInitType

type GitInitType int
const (
	GitInitTypeFs GitInitType = iota
	GitInitTypeMem
)

type GitLog

type GitLog struct {
	Hash        string    `json:"hash"`
	Msg         string    `json:"msg"`
	AuthorName  string    `json:"author_name"`
	AuthorEmail string    `json:"author_email"`
	Timestamp   time.Time `json:"timestamp"`
	Refs        []GitRef  `json:"refs"`
}

type GitOption

type GitOption func(c *GitClient)

func WithAuthType

func WithAuthType(authType GitAuthType) GitOption

func WithDefaultBranch added in v0.6.1

func WithDefaultBranch(branch string) GitOption

func WithIsMem

func WithIsMem() GitOption

func WithPassword

func WithPassword(password string) GitOption

func WithPath

func WithPath(path string) GitOption

func WithPrivateKey

func WithPrivateKey(key string) GitOption

func WithPrivateKeyPath

func WithPrivateKeyPath(path string) GitOption

func WithRemoteUrl

func WithRemoteUrl(url string) GitOption

func WithUsername

func WithUsername(username string) GitOption

type GitOptions

type GitOptions struct {
	// contains filtered or unexported fields
}

type GitPullOption

type GitPullOption func(o *git.PullOptions)

func WithAuthPull

func WithAuthPull(auth transport.AuthMethod) GitPullOption

func WithBranchNamePull added in v0.6.1

func WithBranchNamePull(branch string) GitPullOption

func WithDepthPull

func WithDepthPull(depth int) GitPullOption

func WithForcePull

func WithForcePull(force bool) GitPullOption

func WithRecurseSubmodulesPull

func WithRecurseSubmodulesPull(recurseSubmodules git.SubmoduleRescursivity) GitPullOption

func WithRemoteNamePull

func WithRemoteNamePull(name string) GitPullOption

type GitPushOption

type GitPushOption func(o *git.PushOptions)

func WithAuthPush

func WithAuthPush(auth transport.AuthMethod) GitPushOption

func WithForcePush

func WithForcePush(force bool) GitPushOption

func WithPrune

func WithPrune(prune bool) GitPushOption

func WithRefSpecs

func WithRefSpecs(specs []config.RefSpec) GitPushOption

func WithRemoteNamePush

func WithRemoteNamePush(name string) GitPushOption

type GitRef added in v0.6.1

type GitRef struct {
	Type      string    `json:"type"`
	Name      string    `json:"name"`
	FullName  string    `json:"full_name"`
	Hash      string    `json:"hash"`
	Timestamp time.Time `json:"timestamp"`
}

type GitResetOption

type GitResetOption func(o *git.ResetOptions)

func WithCommit

func WithCommit(commit plumbing.Hash) GitResetOption

func WithMode

func WithMode(mode git.ResetMode) GitResetOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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