Documentation
¶
Index ¶
- Variables
- func LastName(s string) string
- 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) GetCurrentTreeHash(repo string) string
- func (dg DefaultGitter) GetTags(repo string) (tags []string)
- func (dg DefaultGitter) GetTreeHash(repo, tag string) string
- type Environment
- type GitSemVer
- func (vs *GitSemVer) GetBranch(repo string) (branchText, branchName string)
- func (vs *GitSemVer) GetBuild(repo string) (build string)
- func (vs *GitSemVer) GetTag(repo string) (string, bool)
- func (vs *GitSemVer) GetVersion(repo string) (vi VersionInfo, err error)
- func (vs *GitSemVer) IsEnvTrue(envvar string) (yes bool)
- func (vs *GitSemVer) IsReleaseBranch(branchName string) bool
- type Gitter
- type OsEnvironment
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
var ErrNotDirectory = errors.New("not a directory")
Functions ¶
Types ¶
type DefaultGitter ¶
type DefaultGitter string
func (DefaultGitter) CheckGitRepo ¶
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 ¶
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 ¶
func (dg DefaultGitter) GetClosestTag(repo, commit string) (tag string)
GetClosestTag returns the closest semver tag for the given commit hash.
func (DefaultGitter) GetCurrentTreeHash ¶
func (dg DefaultGitter) GetCurrentTreeHash(repo string) string
GetCurrentTreeHash returns the current tree hash.
func (DefaultGitter) GetTags ¶
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 ¶
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 GitSemVer ¶
type GitSemVer struct {
Git Gitter // Git
Env Environment // environment
}
func New ¶
New returns a GitSemVer ready to examine the git repositories using the given Git binary.
func (*GitSemVer) GetBranch ¶
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 (for example, in detached HEAD state), then an empty string is returned.
func (*GitSemVer) GetBuild ¶
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 (*GitSemVer) GetTag ¶
GetTag returns the semver git version tag matching the current tree, or the closest semver tag if none match.
func (*GitSemVer) GetVersion ¶
func (vs *GitSemVer) GetVersion(repo string) (vi VersionInfo, err error)
GetVersion returns a VersionInfo for the source code in the Git repository.
func (*GitSemVer) IsEnvTrue ¶
IsEnvTrue returns true if the given environment variable exists and is set to something that parses as true.
func (*GitSemVer) IsReleaseBranch ¶
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.
type Gitter ¶
type Gitter interface {
// CheckGitRepo checks that the given directory is part of a git repository.
CheckGitRepo(dir string) (repo string, err error)
// 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 semver tag for the given commit hash.
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) GoPackage ¶
func (vi *VersionInfo) GoPackage(repo, pkgName string) (retv string, err error)
GoPackage returns a small piece of Go code defining global variables named "PkgName" and "PkgVersion" with the given pkgName in all lower case and the contents of Version. If the pkgName isn't a valid Go identifier, an error is returned.