scope

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package scope encapsulates ambit of the git-semver functionality.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrBumpMajorOverflow when the major axis resets to zero
	ErrBumpMajorOverflow = errors.New("bump overflow: major")

	// ErrBumpMinorOverflow when the minor axis resets to zero
	ErrBumpMinorOverflow = errors.New("bump overflow: minor")

	// ErrBumpPatchOverflow when the patch axis resets to zero
	ErrBumpPatchOverflow = errors.New("bump overflow: patch")

	// ErrBumpPRVerOverflow when the pre-release version resets to zero
	ErrBumpPRVerOverflow = errors.New("bump overflow: pre-release version")
)
View Source
var (
	// RemoteName is the name of the remote that this tooling should work with.
	RemoteName = GetEnv("SEMVER_REMOTE_NAME", git.DefaultRemoteName)

	// PrePrefix is the default value for the pre-axis.
	PrePrefix = GetEnv("SEMVER_PRE_PREFIX", "pre")

	// UserEmail is the value for the git config user.email in the local semver repository.
	UserEmail = GetEnv("SEMVER_USER_EMAIL",
		GetEnv("GIT_AUTHOR_EMAIL",
			GetEnv("GIT_COMMITTER_EMAIL", "semver@semver.org"),
		),
	)

	// UserName is the value for the git config user.name in the local semver repository.
	UserName = GetEnv("SEMVER_USER_NAME",
		GetEnv("GIT_AUTHOR_NAME",
			GetEnv("GIT_COMMITTER_NAME", "semver"),
		),
	)
)

Functions

func Bump

func Bump(my, sv *Extent, axis, pre string) error

Bump the specified semver axis with prefix, invoking WriteVersion on the result.

func GetEnv

func GetEnv(key, def string) string

GetEnv attempt os.LookupEnv returning the default if the key is not found.

func Push

func Push(my, sv *Extent) error

Push the semver branch and any tags to the remote.

func Tag

func Tag(my, sv *Extent) error

Tag the current HEAD with the current semver version.

func WriteVersion

func WriteVersion(my, sv *Extent, ver Version) error

WriteVersion writes the version string value to a file named after the current branch.

Types

type Extent

type Extent struct {
	Store  *filesystem.Storage
	Repo   *git.Repository
	Tree   *git.Worktree
	Branch string
}

Extent is an Open()'ed GIT repository.

func Init

func Init(my *Extent, create bool) (*Extent, error)

Init attempts to clone, but failing that will initialize, the semver orphan branch into .semver directory.

func Open

func Open(path string) (*Extent, error)

Open the GIT "extent" located at path.

type MakeOpt

type MakeOpt func(*Version) error

MakeOpt is an option passed to MakeVersion

func BumpFinal

func BumpFinal() MakeOpt

BumpFinal will strip the pre-release suffix.

Example
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpFinal())
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

1.2.3

func BumpMajor

func BumpMajor() MakeOpt

BumpMajor will bump the major axis.

Example
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpMajor())
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

2.0.0

func BumpMinor

func BumpMinor() MakeOpt

BumpMinor will bump the minor axis.

Example
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpMinor())
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

1.3.0

func BumpPatch

func BumpPatch() MakeOpt

BumpPatch will bump the patch axis.

Example
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpPatch())
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

1.2.4

func BumpPre

func BumpPre(pre string) MakeOpt

BumpPre will bump the pre-release suffix. Passing a different prefix than what is currently encoded will bump from zero with the new pre-release.

Example (Dev)
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpPre("dev"))
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

1.2.3-dev.5
Example (Pre)
package main

import (
	"fmt"

	"github.com/edgexfoundry/git-semver/scope"
)

func main() {
	ver, err := scope.MakeVersion("1.2.3-dev.4", scope.BumpPre("pre"))
	if err != nil {
		fmt.Printf("%s", err)
	} else {
		fmt.Printf("%s", ver)
	}
}
Output:

1.2.3-pre.1

func WithBuild

func WithBuild(s string) MakeOpt

WithBuild attaches build/metadata to the version string.

func WithPre

func WithPre(pre string) MakeOpt

WithPre does nothing for empty prefixes and works like BumpPre otherwise.

type Version

type Version = semver.Version

Version type alias

func MakeVersion

func MakeVersion(s string, m ...MakeOpt) (Version, error)

MakeVersion parses the version string and applies the supplied options.

func ReadVersion

func ReadVersion(my, sv *Extent) (Version, error)

ReadVersion reads the semver version for the current branch.

Jump to

Keyboard shortcuts

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