gitsemver

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValid

func IsValid(version string) bool

IsValid reports whether version is a valid version string in any of the three recognised formats: stable, RC, or dev build.

func IsValidDev

func IsValidDev(version string) bool

IsValidDev reports whether version is a valid dev-build version (X.Y.Z-dev.<branch>.<YYYY-MM-DD>.<HH-MM-SS> or with a leading v, no leading zeros in X.Y.Z components).

func IsValidRC

func IsValidRC(version string) bool

IsValidRC reports whether version is a valid release-candidate version (X.Y.Z-rc.N or vX.Y.Z-rc.N, no leading zeros in any numeric component).

func IsValidStable

func IsValidStable(version string) bool

IsValidStable reports whether version is a valid stable release version (X.Y.Z or vX.Y.Z, no leading zeros in any component).

func TopLevel

func TopLevel(ctx context.Context, path string) (string, error)

TopLevel Toplevel finds absolute path of top-level git directory. The output is the same as:

`git rev-parse --show-toplevel`

Types

type Config

type Config struct {
	AuthBasicToken string
	Dir            string
	URL            string
}

type ExecutionFailedError

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

func (*ExecutionFailedError) Error

func (e *ExecutionFailedError) Error() string

func (*ExecutionFailedError) Is

func (e *ExecutionFailedError) Is(target error) bool

type FileNotFoundError

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

func (*FileNotFoundError) Error

func (e *FileNotFoundError) Error() string

func (*FileNotFoundError) Is

func (e *FileNotFoundError) Is(target error) bool

type FolderNotFoundError

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

func (*FolderNotFoundError) Error

func (e *FolderNotFoundError) Error() string

func (*FolderNotFoundError) Is

func (e *FolderNotFoundError) Is(target error) bool

type InvalidConfigError

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

func (*InvalidConfigError) Error

func (e *InvalidConfigError) Error() string

func (*InvalidConfigError) Is

func (e *InvalidConfigError) Is(target error) bool

type ReferenceNotFoundError

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

func (*ReferenceNotFoundError) Error

func (e *ReferenceNotFoundError) Error() string

func (*ReferenceNotFoundError) Is

func (e *ReferenceNotFoundError) Is(target error) bool

type Repo

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

func New

func New(config Config) (*Repo, error)

func (*Repo) EnsureUpToDate

func (r *Repo) EnsureUpToDate(ctx context.Context) error

EnsureUpToDate fetches latest changes from remote.

func (*Repo) GetFileContent

func (r *Repo) GetFileContent(path, ref string) ([]byte, error)

GetFileContent retrieves content of file stored at path on version specified in ref. When empty ref defaults to master branch.

func (*Repo) GetFolderContent

func (r *Repo) GetFolderContent(path, ref string) ([]os.FileInfo, error)

GetFolderContent retrieves content of a folder stored at path on version specified in ref. When empty ref defaults to master branch.

func (*Repo) HeadBranch

func (r *Repo) HeadBranch(ctx context.Context) (string, error)

HeadBranch returns branch name for the HEAD ref.

func (*Repo) HeadSHA

func (r *Repo) HeadSHA(ctx context.Context) (string, error)

HeadSHA returns sha for the HEAD ref.

func (*Repo) HeadTag

func (r *Repo) HeadTag(ctx context.Context) (string, error)

HeadTag returns tag for the HEAD ref.

If GS_TAG_PREFIX environment variable is set, it looks for tags prefixed with that. For example, when the value is 'module-a', it filters found tags to 'module-a/v1.2.0', must match <module_name>/v<semantic_version>.

Note: if GS_TAG_PREFIX is not set, all tags matching the prefixed tag regex are filtered out!

It returns error handled by IsReferenceNotFound if the HEAD ref is not tagged.

func (*Repo) ResolveVersion

func (r *Repo) ResolveVersion(ctx context.Context, ref string) (string, error)

ResolveVersion resolves the version for a git reference:

  • Stable tag vX.Y.Z on the commit → returns "X.Y.Z"
  • Pre-release tag vX.Y.Z-<pre> on the commit → returns "X.Y.Z-<pre>" (e.g. "1.2.3-rc.1")
  • Untagged commit → returns a semVer dev build: "X.Y.(Z+1)-dev.<branch>.<YYYY-MM-DD>.<HH-MM-SS>" where X.Y.Z is the most recent stable (non-pre-release) ancestor tag reachable from the reference, or "0.0.0" when no stable ancestor exists. The branch name is resolved from GS_BRANCH_NAME env var, then the HEAD branch of the CWD git repo, then "unknown". Non-reachable tags are never used as the base.

If GS_GIT_TAG_PREFIX is set, only tags prefixed with "<value>/" are considered, e.g. "module-a/v1.2.3". The prefix, separator, and "v" are stripped from the result.

It returns an error handled by IsReferenceNotFound if the reference cannot be resolved.

type RepositoryNotFoundError

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

func (*RepositoryNotFoundError) Error

func (e *RepositoryNotFoundError) Error() string

func (*RepositoryNotFoundError) Is

func (e *RepositoryNotFoundError) Is(target error) bool

Jump to

Keyboard shortcuts

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