Documentation
¶
Overview ¶
Package git provides version control operations for commits, tags, branches, and PRs.
Index ¶
- Variables
- func CommitAll(ctx context.Context, message string) error
- func CommitAndRelease(ctx context.Context, bump VersionBump) error
- func CommitCompletedFile(ctx context.Context, path string) error
- func CommitWithRetry(ctx context.Context, backoff run.Backoff, fn func(context.Context) error) error
- func GetNextVersion(ctx context.Context, bump VersionBump) (string, error)
- func HasDirtyFiles(ctx context.Context) (bool, error)
- func MoveFile(ctx context.Context, oldPath string, newPath string) error
- func ResolveGitRoot(ctx context.Context) (string, error)
- func StderrFromError(err error) string
- func TruncateStderr(s string) string
- func ValidateBranchName(ctx context.Context, name string) error
- func ValidatePRTitle(ctx context.Context, title string) error
- func ValidatePRURL(ctx context.Context, prURL string) error
- type Brancher
- type BrancherOption
- type Cloner
- type CollaboratorFetcher
- type CollaboratorLister
- type CommandOutputFn
- type Helpers
- func (h *Helpers) CommitAll(ctx context.Context, message string) error
- func (h *Helpers) CommitAndRelease(ctx context.Context, bump VersionBump) error
- func (h *Helpers) CommitCompletedFile(ctx context.Context, path string) error
- func (h *Helpers) HasDirtyFiles(ctx context.Context) (bool, error)
- func (h *Helpers) MoveFile(ctx context.Context, oldPath string, newPath string) error
- func (h *Helpers) ResolveGitRoot(ctx context.Context) (string, error)
- type PRCreator
- type PRMerger
- type Releaser
- type RepoNameFetcher
- type SemanticVersionNumber
- type VersionBump
- type Worktreer
Constants ¶
This section is empty.
Variables ¶
var DefaultCommitBackoff = run.Backoff{ Delay: 2 * time.Second, Factor: 1.0, Retries: 3, }
DefaultCommitBackoff defines the default retry backoff for git commit operations. 3 retries with exponential backoff: ~2s, ~4s, ~8s.
Functions ¶
func CommitAll ¶ added in v0.124.0
CommitAll stages all changes and commits with the given message. Used during committing recovery to commit work files left from a prior run.
func CommitAndRelease ¶
func CommitAndRelease(ctx context.Context, bump VersionBump) error
CommitAndRelease performs the full git workflow (package-level wrapper for tests and scripts).
func CommitCompletedFile ¶ added in v0.2.27
CommitCompletedFile stages and commits a completed prompt file (package-level wrapper).
func CommitWithRetry ¶ added in v0.124.0
func CommitWithRetry( ctx context.Context, backoff run.Backoff, fn func(context.Context) error, ) error
CommitWithRetry runs fn with retry logic using the given backoff configuration. Logs WARN on each retry attempt. Pass DefaultCommitBackoff for production use; tests can pass a Backoff with Delay: 0 and small Retries.
func GetNextVersion ¶ added in v0.2.0
func GetNextVersion(ctx context.Context, bump VersionBump) (string, error)
GetNextVersion determines the next version (package-level wrapper).
func HasDirtyFiles ¶ added in v0.124.0
HasDirtyFiles returns true if there are any uncommitted changes in the working tree.
func ResolveGitRoot ¶ added in v0.32.0
ResolveGitRoot returns the absolute path to the root of the current git repository by running `git rev-parse --show-toplevel`. Returns an error if not inside a git repo.
func StderrFromError ¶ added in v0.185.0
StderrFromError extracts and truncates the child stderr captured in a wrapped *exec.ExitError. Exported so sibling packages (e.g. pkg/gitprovider/bitbucket) can use it without duplicating the logic.
func TruncateStderr ¶ added in v0.184.0
TruncateStderr returns s unchanged if len(s) <= maxStderrBytes. If s exceeds the limit, the first maxStderrBytes bytes are returned followed by the literal string " (truncated)". Exported so sibling git-provider packages (e.g. pkg/gitprovider/bitbucket) can use it without duplicating.
func ValidateBranchName ¶ added in v0.54.0
ValidateBranchName returns an error if the branch name contains characters that could be used for argument injection in git commands.
func ValidatePRTitle ¶ added in v0.54.0
ValidatePRTitle returns an error if the PR title is empty or starts with a dash, which could be interpreted as a flag by the gh CLI.
Types ¶
type Brancher ¶ added in v0.9.0
type Brancher interface {
CreateAndSwitch(ctx context.Context, name string) error
Push(ctx context.Context, name string) error
Switch(ctx context.Context, name string) error
CurrentBranch(ctx context.Context) (string, error)
Fetch(ctx context.Context) error
FetchAndVerifyBranch(ctx context.Context, branch string) error
DefaultBranch(ctx context.Context) (string, error)
Pull(ctx context.Context) error
MergeOriginDefault(ctx context.Context) error
IsClean(ctx context.Context) (bool, error)
// IsCleanIgnoring returns the dirty paths that are NOT covered by any of
// the given ignorePrefixes. An empty slice means the tree is effectively
// clean for the caller's purposes. The prefix comparison is
// strings.HasPrefix(path, prefix) on the path as reported by
// git status --porcelain (relative, no leading slash).
// A non-nil error means the git command itself failed.
IsCleanIgnoring(ctx context.Context, ignorePrefixes []string) ([]string, error)
// DiscardUncommittedInPaths restores each path prefix to its HEAD state using
// git checkout HEAD -- <prefix>. Prefixes not covered by any uncommitted change
// are silently skipped. An empty prefixes slice is a no-op.
DiscardUncommittedInPaths(ctx context.Context, prefixes []string) error
MergeToDefault(ctx context.Context, branch string) error
CommitsAhead(ctx context.Context, branch string) (int, error)
// FetchBranch fetches the named branch from origin as a local branch
// (git fetch origin <branch>:<branch>).
FetchBranch(ctx context.Context, branch string) error
}
Brancher handles git branch operations.
func NewBrancher ¶ added in v0.9.0
func NewBrancher(opts ...BrancherOption) Brancher
NewBrancher creates a new Brancher.
type BrancherOption ¶ added in v0.33.0
type BrancherOption func(*brancher)
BrancherOption is a functional option for configuring a brancher.
func WithDefaultBranch ¶ added in v0.33.0
func WithDefaultBranch(branch string) BrancherOption
WithDefaultBranch sets a configured default branch on the brancher.
type Cloner ¶ added in v0.30.4
type Cloner interface {
Clone(ctx context.Context, srcDir string, destDir string, branch string) error
Remove(ctx context.Context, path string) error
}
Cloner handles local git clone operations.
type CollaboratorFetcher ¶ added in v0.30.12
CollaboratorFetcher fetches GitHub repository collaborators.
func NewCollaboratorFetcher ¶ added in v0.30.12
func NewCollaboratorFetcher( repoNameFetcher RepoNameFetcher, collaboratorLister CollaboratorLister, useCollaborators bool, allowedReviewers []string, ) CollaboratorFetcher
NewCollaboratorFetcher creates a CollaboratorFetcher.
type CollaboratorLister ¶ added in v0.30.15
CollaboratorLister lists collaborator logins for a GitHub repository.
func NewGHCollaboratorLister ¶ added in v0.30.15
func NewGHCollaboratorLister(ghToken string) CollaboratorLister
NewGHCollaboratorLister creates a CollaboratorLister that uses gh CLI.
type CommandOutputFn ¶ added in v0.44.1
CommandOutputFn executes a command and returns its output. Kept for backward compatibility; new code should use the runner-based constructors.
type Helpers ¶ added in v0.185.0
type Helpers struct {
// contains filtered or unexported fields
}
Helpers groups git CLI free functions onto a runner-bearing struct so production wiring injects a runner once and tests inject a fake.
func NewHelpers ¶ added in v0.185.0
func NewHelpers() *Helpers
NewHelpers wires a Helpers with the default production runner.
func NewHelpersWithRunner ¶ added in v0.185.0
NewHelpersWithRunner is the test seam.
func (*Helpers) CommitAll ¶ added in v0.185.0
CommitAll stages all changes and commits with the given message.
func (*Helpers) CommitAndRelease ¶ added in v0.185.0
func (h *Helpers) CommitAndRelease(ctx context.Context, bump VersionBump) error
CommitAndRelease performs the full git workflow.
func (*Helpers) CommitCompletedFile ¶ added in v0.185.0
CommitCompletedFile stages and commits a completed prompt file.
func (*Helpers) HasDirtyFiles ¶ added in v0.185.0
HasDirtyFiles returns true if there are any uncommitted changes in the working tree.
type PRCreator ¶ added in v0.9.0
type PRCreator interface {
// Create creates a pull request on the given branch and returns the PR URL.
Create(ctx context.Context, title string, body string, branch string) (string, error)
// FindOpenPR returns the URL of an open PR for the given branch, or "" if none exists.
FindOpenPR(ctx context.Context, branch string) (string, error)
}
PRCreator handles GitHub pull request creation.
func NewPRCreator ¶ added in v0.9.0
NewPRCreator creates a new PRCreator.
func NewPRCreatorWithCommandOutput ¶ added in v0.44.1
func NewPRCreatorWithCommandOutput(ghToken string, _ CommandOutputFn) PRCreator
NewPRCreatorWithCommandOutput creates a PRCreator. The CommandOutputFn is accepted for backward compatibility but the spawn goes through the runner.
type PRMerger ¶ added in v0.17.6
PRMerger watches a PR until mergeable and merges it.
func NewPRMerger ¶ added in v0.17.6
func NewPRMerger(ghToken string, currentDateTimeGetter libtime.CurrentDateTimeGetter) PRMerger
NewPRMerger creates a new PRMerger.
type Releaser ¶ added in v0.2.26
type Releaser interface {
GetNextVersion(ctx context.Context, bump VersionBump) (string, error)
CommitAndRelease(ctx context.Context, bump VersionBump) error
CommitCompletedFile(ctx context.Context, path string) error
CommitOnly(ctx context.Context, message string) error
HasChangelog(ctx context.Context) bool
MoveFile(ctx context.Context, oldPath string, newPath string) error
PushBranch(ctx context.Context) error
// DetermineBump inspects CHANGELOG.md in the current directory and returns
// the appropriate version bump. PatchBump if missing or no `- feat:` entry.
DetermineBump(ctx context.Context) VersionBump
// CommitWithRetry runs fn with the default retry backoff and lock-aware
// logging. Application-layer code uses this seam instead of the package-
// level git.CommitWithRetry so processor stays mockable.
CommitWithRetry(ctx context.Context, fn func(context.Context) error) error
}
Releaser handles git commit, tag, and push operations.
type RepoNameFetcher ¶ added in v0.30.15
RepoNameFetcher fetches the current GitHub repository name with owner.
func NewGHRepoNameFetcher ¶ added in v0.30.15
func NewGHRepoNameFetcher(ghToken string) RepoNameFetcher
NewGHRepoNameFetcher creates a RepoNameFetcher that uses gh CLI.
type SemanticVersionNumber ¶ added in v0.2.33
SemanticVersionNumber represents a parsed semantic version.
func ParseSemanticVersionNumber ¶ added in v0.2.33
func ParseSemanticVersionNumber(ctx context.Context, tag string) (SemanticVersionNumber, error)
ParseSemanticVersionNumber parses "vX.Y.Z" into a SemanticVersionNumber. Returns error if format is invalid.
func (SemanticVersionNumber) BumpMinor ¶ added in v0.2.33
func (v SemanticVersionNumber) BumpMinor() SemanticVersionNumber
BumpMinor returns a new version with minor incremented and patch reset to 0.
func (SemanticVersionNumber) BumpPatch ¶ added in v0.2.33
func (v SemanticVersionNumber) BumpPatch() SemanticVersionNumber
BumpPatch returns a new version with patch incremented.
func (SemanticVersionNumber) Less ¶ added in v0.2.33
func (v SemanticVersionNumber) Less(other SemanticVersionNumber) bool
Less returns true if v is lower than other.
func (SemanticVersionNumber) String ¶ added in v0.2.33
func (v SemanticVersionNumber) String() string
String returns the "vX.Y.Z" representation.
type VersionBump ¶ added in v0.2.30
type VersionBump int
VersionBump specifies the type of version bump to perform.
const ( // PatchBump increments the patch version (vX.Y.Z -> vX.Y.Z+1) PatchBump VersionBump = iota // MinorBump increments the minor version (vX.Y.Z -> vX.Y+1.0) MinorBump )
func DetermineBumpFromChangelog ¶ added in v0.52.3
func DetermineBumpFromChangelog(ctx context.Context, dir string) VersionBump
DetermineBumpFromChangelog reads CHANGELOG.md from the given directory and returns MinorBump if any ## Unreleased entry starts with "- feat:", PatchBump otherwise. Returns PatchBump when CHANGELOG.md is missing or has no ## Unreleased section.
type Worktreer ¶ added in v0.113.0
type Worktreer interface {
// Add creates a linked worktree at worktreePath on branch.
Add(ctx context.Context, worktreePath string, branch string) error
// Remove removes the linked worktree at worktreePath.
Remove(ctx context.Context, worktreePath string) error
}
Worktreer handles git worktree operations.
func NewWorktreer ¶ added in v0.113.0
func NewWorktreer() Worktreer
NewWorktreer creates a new Worktreer.