Documentation
¶
Index ¶
- type DefaultGitter
- func (dg DefaultGitter) CheckGitRepo(dir string) (repo string, err error)
- func (dg DefaultGitter) FetchTags(repo string) (err error)
- func (dg DefaultGitter) GetBranch(repo string) (branch string)
- func (dg DefaultGitter) GetBranchesFromTag(repo, tag string) (branches []string)
- func (dg DefaultGitter) GetBuild(repo string) string
- func (dg DefaultGitter) GetClosestTag(repo, commit string) (tag string)
- func (dg DefaultGitter) GetCommits(repo string) (commits []string)
- func (dg DefaultGitter) GetCurrentTreeHash(repo string) string
- func (dg DefaultGitter) GetTags(repo string) (tags []string)
- func (dg DefaultGitter) GetTreeHash(repo, tag string) string
- type Environment
- type Gitter
- type OsEnvironment
- type VersionInfo
- type VersionStringer
- func (vs *VersionStringer) GetBranch(repo string) (branchText, branchName string)
- func (vs *VersionStringer) GetBuild(repo string) (build string)
- func (vs *VersionStringer) GetTag(repo string) (string, bool)
- func (vs *VersionStringer) GetVersion(repo string) (vi VersionInfo, err error)
- func (vs *VersionStringer) IsEnvTrue(envvar string) bool
- func (vs *VersionStringer) IsReleaseBranch(branchName string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultGitter ¶
type DefaultGitter string
func (DefaultGitter) CheckGitRepo ¶ added in v2.2.0
func (dg DefaultGitter) CheckGitRepo(dir string) (repo string, err error)
CheckGitRepo checks that the given directory is part of a git repository, meaning that it or one of it's parent directories has a '.git' subdirectory. If it is, it returns the absolute path of the git repo and a nil error.
func (DefaultGitter) FetchTags ¶ added in v2.1.0
func (dg DefaultGitter) FetchTags(repo string) (err error)
func (DefaultGitter) GetBranch ¶
func (dg DefaultGitter) GetBranch(repo string) (branch string)
func (DefaultGitter) GetBranchesFromTag ¶
func (dg DefaultGitter) GetBranchesFromTag(repo, tag string) (branches []string)
func (DefaultGitter) GetBuild ¶
func (dg DefaultGitter) GetBuild(repo string) string
func (DefaultGitter) GetClosestTag ¶ added in v2.1.0
func (dg DefaultGitter) GetClosestTag(repo, commit string) (tag string)
GetClosestTag returns the closest semver tag for the given commit hash.
func (DefaultGitter) GetCommits ¶ added in v2.1.0
func (dg DefaultGitter) GetCommits(repo string) (commits []string)
GetCommits returns all commit hashes.
func (DefaultGitter) GetCurrentTreeHash ¶ added in v2.1.0
func (dg DefaultGitter) GetCurrentTreeHash(repo string) string
GetCurrentTreeHash returns the current tree hash.
func (DefaultGitter) GetTags ¶ added in v2.1.0
func (dg DefaultGitter) GetTags(repo string) (tags []string)
GetTags returns all tags, sorted by version descending. The latest tag is the first in the list.
func (DefaultGitter) GetTreeHash ¶ added in v2.1.0
func (dg DefaultGitter) GetTreeHash(repo, tag string) string
GetTagTreeHash returns the tree hash for the given tag or commit hash.
type Environment ¶
Environment allows us to mock the OS environment
type Gitter ¶
type Gitter interface { // CheckGitRepo checks that the given directory is part of a git repository. CheckGitRepo(dir string) (repo string, err error) // GetCommits returns all commit hashes. GetCommits(repo string) (commits []string) // GetTags returns all tags, sorted by version descending. GetTags(repo string) (tags []string) // GetCurrentTreeHash returns the current tree hash. GetCurrentTreeHash(repo string) string // GetTreeHash returns the tree hash for the given tag or commit. GetTreeHash(repo, tag string) string // GetClosestTag returns the closest tag for the given commit hash (or HEAD). GetClosestTag(repo, commit string) (tag string) // GetBranch returns the current branch in the repository or an empty string. GetBranch(repo string) string // GetBranchesFromTag returns the non-HEAD branches in the repository that have the tag, otherwise an empty string. GetBranchesFromTag(repo, tag string) []string // GetBuild returns the number of commits in the currently checked out branch as a string, or an empty string GetBuild(repo string) string // FetchTags calls "git fetch --tags" FetchTags(repo string) error }
Gitter is an interface exposing the required Git functionality
func NewDefaultGitter ¶
type OsEnvironment ¶
type OsEnvironment struct{}
OsEnvironment calls the OS functions.
func (OsEnvironment) Getenv ¶
func (OsEnvironment) Getenv(key string) string
type VersionInfo ¶
type VersionInfo struct { Tag string // git tag, e.g. "v1.2.3" Branch string // git branch, e.g. "mybranch" Build string // git or CI build number, e.g. "456" Version string // composite version, e.g. "v1.2.3-mybranch.456" }
func (*VersionInfo) Render ¶
func (vi *VersionInfo) Render(pkgName string) (string, error)
Render returns either the Version string followed by a newline, or, if the pkgName is not an empty string, a small piece of Go code defining global variables named "PkgName" and "PkgVersion" with the given pkgName and the contents of Version. If the pkgName is given but isn't a valid Go identifier, an error is returned.
type VersionStringer ¶
type VersionStringer struct { Git Gitter // Git Env Environment // environment }
func NewVersionStringer ¶
func NewVersionStringer(gitBin string) (vs *VersionStringer, err error)
NewVersionStringer returns a VersionStringer ready to examine the git repositories using the given Git binary.
func (*VersionStringer) GetBranch ¶
func (vs *VersionStringer) GetBranch(repo string) (branchText, branchName string)
GetBranch returns the current branch as a string suitable for inclusion in the semver text as well as the actual branch name in the build system or Git. If no branch name can be found, then "HEAD" is returned if we are running within a Git repo, or an empty string if we're not.
func (*VersionStringer) GetBuild ¶
func (vs *VersionStringer) GetBuild(repo string) (build string)
GetBuild returns the build counter. This is taken from the CI system if available, otherwise the Git commit count is used. Returns an empty string if no reasonable build counter can be found.
func (*VersionStringer) GetTag ¶
func (vs *VersionStringer) GetTag(repo string) (string, bool)
GetTag returns the semver git version tag matching the current tree, or the latest semver tag if none match.
func (*VersionStringer) GetVersion ¶
func (vs *VersionStringer) GetVersion(repo string) (vi VersionInfo, err error)
GetVersion returns a version string for the source code in the Git repository.
func (*VersionStringer) IsEnvTrue ¶
func (vs *VersionStringer) IsEnvTrue(envvar string) bool
IsEnvTrue returns true if the given environment variable exists and is set to the string "true" (not case sensitive).
func (*VersionStringer) IsReleaseBranch ¶
func (vs *VersionStringer) IsReleaseBranch(branchName string) bool
IsReleaseBranch returns true if the given branch name should be allowed to use 'release mode', where the version string doesn't contains build information suffix.