vcs

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package vcs abstracts the version-control operations releasegen needs.

The Repo interface is defined here in the consumer package per Go best practice. The default implementation is GitRepo (in git.go), which uses go-git. Tests use mockery-generated mocks under internal/vcs/mocks.

Index

Constants

This section is empty.

Variables

View Source
var ErrVCS = errors.New("vcs error")

ErrVCS is the sentinel returned (wrapped) when any git-side operation (open, walk, commit, tag, push) fails. Callers should use errors.Is to branch on it for exit code mapping rather than scanning error strings.

Functions

func LatestTagForModule

func LatestTagForModule(tags []TagInfo, moduleName string) string

LatestTagForModule returns the most recent tag in tags belonging to the named module (empty name = root). It returns "" when no tag is found.

Types

type CommitTagPushOptions

type CommitTagPushOptions struct {
	ChangelogPath string
	ModuleName    string
	Version       string // bare semver
	Actor         string
	Token         string // pushed via basic auth
}

CommitTagPushOptions describes a single per-module commit + tag + push.

type GitRepo

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

GitRepo is a Repo implementation backed by go-git operating on an on-disk repository.

func Open

func Open(repoPath, branch string, log *slog.Logger) (*GitRepo, error)

Open opens the git repository at the given path and returns a GitRepo configured for the named release branch.

func (*GitRepo) AllChangelogPaths

func (g *GitRepo) AllChangelogPaths(ctx context.Context) ([]string, error)

AllChangelogPaths walks HEAD's tree and returns every CHANGELOG.md path.

func (*GitRepo) CommitTagAndPush

func (g *GitRepo) CommitTagAndPush(ctx context.Context, opts CommitTagPushOptions) error

CommitTagAndPush stages, commits, pushes, tags, and pushes the tag for a single module release. Errors are wrapped with the failing step name so the caller can decide on recovery.

func (*GitRepo) IsChangelogModifiedSinceTag

func (g *GitRepo) IsChangelogModifiedSinceTag(ctx context.Context, changelogPath, tagName string) (bool, error)

IsChangelogModifiedSinceTag returns true if changelogPath was changed between the commit referenced by tagName and HEAD. When tagName is empty the function returns true (first release).

func (*GitRepo) ReachableTags

func (g *GitRepo) ReachableTags(ctx context.Context) ([]TagInfo, error)

ReachableTags returns all tags whose target commits are ancestors of the configured release branch tip.

type Repo

type Repo interface {
	// AllChangelogPaths returns every CHANGELOG.md file in HEAD's tree.
	AllChangelogPaths(ctx context.Context) ([]string, error)

	// ReachableTags returns all tags whose commits are reachable from the
	// configured release branch.
	ReachableTags(ctx context.Context) ([]TagInfo, error)

	// IsChangelogModifiedSinceTag reports whether the file at changelogPath
	// has been modified between the commit pointed at by tagName and HEAD.
	// When tagName is empty (no prior tag) the function returns true.
	IsChangelogModifiedSinceTag(ctx context.Context, changelogPath, tagName string) (bool, error)

	// CommitTagAndPush stages the changelog file, commits it with a
	// "[skip ci]" message, pushes the commit, creates an annotated tag for
	// the release name, and pushes the tag. It is intentionally a single
	// operation so the implementation can attempt cleanup on failure.
	CommitTagAndPush(ctx context.Context, opts CommitTagPushOptions) error
}

Repo is the abstraction the runner uses to interact with git. It is intentionally tiny so it can be mocked easily.

type TagInfo

type TagInfo struct {
	Name       string        // e.g. "v1.2.3" or "module/v1.2.3"
	ModuleName string        // empty for root tags
	Date       int64         // unix seconds (commit or tagger date)
	Hash       plumbing.Hash // the commit the tag points at
}

TagInfo describes a single tag reachable from the release branch.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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