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 ValidateBranchName(ctx context.Context, name string) error
- func ValidatePRTitle(ctx context.Context, title string) error
- func ValidatePRURL(ctx context.Context, prURL string) error
- type BitbucketCurrentUserFetcher
- type BitbucketRemoteCoords
- type Brancher
- type BrancherOption
- type Cloner
- type CollaboratorFetcher
- type CollaboratorLister
- type CommandOutputFn
- type PRCreator
- type PRMerger
- type Releaser
- type RepoNameFetcher
- type ReviewFetcher
- type ReviewResult
- type ReviewVerdict
- 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: 1. git add -A 2. Read CHANGELOG.md and rename ## Unreleased to version 3. Bump version (patch or minor) 4. git commit 5. git tag 6. git push + push tag
func CommitCompletedFile ¶ added in v0.2.27
CommitCompletedFile stages and commits a completed prompt file. This is called after MoveToCompleted() to ensure the moved file is committed. Does nothing if the file is already staged or committed.
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 based on the bump type.
func HasDirtyFiles ¶ added in v0.124.0
HasDirtyFiles returns true if there are any uncommitted changes in the working tree.
func MoveFile ¶ added in v0.2.36
MoveFile moves a file using git mv to preserve history. Falls back to os.Rename if git operations fail or not in a git repo.
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 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 BitbucketCurrentUserFetcher ¶ added in v0.107.2
BitbucketCurrentUserFetcher fetches the current authenticated Bitbucket user.
func NewBitbucketCurrentUserFetcher ¶ added in v0.107.2
func NewBitbucketCurrentUserFetcher(baseURL, token string) BitbucketCurrentUserFetcher
NewBitbucketCurrentUserFetcher creates a BitbucketCurrentUserFetcher for the given base URL and token.
type BitbucketRemoteCoords ¶ added in v0.45.0
type BitbucketRemoteCoords struct {
// Project is the Bitbucket project key (uppercased, e.g. "BRO").
Project string
// Repo is the repository slug (lowercased, e.g. "sentinel").
Repo string
}
BitbucketRemoteCoords holds the project key and repo slug parsed from a Bitbucket Server remote URL.
func ParseBitbucketRemoteFromGit ¶ added in v0.45.0
func ParseBitbucketRemoteFromGit( ctx context.Context, remoteName string, ) (*BitbucketRemoteCoords, error)
ParseBitbucketRemoteFromGit reads the git remote URL for the given remote name and parses it. Uses `git remote get-url <remoteName>` to fetch the URL.
func ParseBitbucketRemoteURL ¶ added in v0.45.0
func ParseBitbucketRemoteURL( ctx context.Context, remoteURL string, ) (*BitbucketRemoteCoords, error)
ParseBitbucketRemoteURL parses a Bitbucket Server git remote URL and returns project key and repo slug.
Supported formats:
- SSH: ssh://bitbucket.example.com:7999/bro/sentinel.git
- HTTPS: https://bitbucket.example.com/scm/bro/sentinel.git
The project key is uppercased and the repo slug is lowercased (matching Bitbucket Server conventions).
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)
MergeToDefault(ctx context.Context, branch string) error
CommitsAhead(ctx context.Context, branch string) (int, 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. When set, DefaultBranch() returns this value directly without calling gh. Passing an empty string is a no-op (gh CLI fallback is used).
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 NewBitbucketCollaboratorFetcher ¶ added in v0.49.0
func NewBitbucketCollaboratorFetcher( baseURL string, token string, project string, repo string, defaultBranch string, currentUserFetcher BitbucketCurrentUserFetcher, allowedReviewers []string, ) CollaboratorFetcher
NewBitbucketCollaboratorFetcher creates a CollaboratorFetcher backed by the Bitbucket Server default-reviewers plugin. currentUserFetcher is called lazily to exclude the current user from results. If allowedReviewers is non-empty, it is returned directly without any HTTP calls.
func NewCollaboratorFetcher ¶ added in v0.30.12
func NewCollaboratorFetcher( repoNameFetcher RepoNameFetcher, collaboratorLister CollaboratorLister, useCollaborators bool, allowedReviewers []string, ) CollaboratorFetcher
NewCollaboratorFetcher creates a CollaboratorFetcher. If useCollaborators is false or allowedReviewers is non-empty, collaborators are not fetched from GitHub.
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.
type PRCreator ¶ added in v0.9.0
type PRCreator interface {
Create(ctx context.Context, title string, body 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 NewBitbucketPRCreator ¶ added in v0.49.0
func NewBitbucketPRCreator( baseURL string, token string, project string, repo string, defaultBranch string, reviewerFetcher CollaboratorFetcher, ) PRCreator
NewBitbucketPRCreator creates a PRCreator backed by the Bitbucket Server REST API. reviewerFetcher is called lazily at PR creation time to resolve the reviewer list.
func NewPRCreator ¶ added in v0.9.0
NewPRCreator creates a new PRCreator.
func NewPRCreatorWithCommandOutput ¶ added in v0.44.1
func NewPRCreatorWithCommandOutput(ghToken string, fn CommandOutputFn) PRCreator
NewPRCreatorWithCommandOutput creates a new PRCreator with a custom command output function.
type PRMerger ¶ added in v0.17.6
PRMerger watches a PR until mergeable and merges it.
func NewBitbucketPRMerger ¶ added in v0.49.0
func NewBitbucketPRMerger( baseURL string, token string, project string, repo string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) PRMerger
NewBitbucketPRMerger creates a PRMerger backed by the Bitbucket Server REST API.
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
}
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 ReviewFetcher ¶ added in v0.17.35
type ReviewFetcher interface {
// FetchLatestReview returns the latest review from a trusted reviewer.
// Returns ReviewVerdictNone if no trusted review exists yet.
FetchLatestReview(
ctx context.Context,
prURL string,
allowedReviewers []string,
) (*ReviewResult, error)
// FetchPRState returns the raw PR state string: "OPEN", "MERGED", "CLOSED".
FetchPRState(ctx context.Context, prURL string) (string, error)
}
ReviewFetcher polls a GitHub PR for reviews from trusted reviewers.
func NewBitbucketReviewFetcher ¶ added in v0.49.0
func NewBitbucketReviewFetcher( baseURL string, token string, project string, repo string, ) ReviewFetcher
NewBitbucketReviewFetcher creates a ReviewFetcher backed by the Bitbucket Server REST API.
func NewReviewFetcher ¶ added in v0.17.35
func NewReviewFetcher(ghToken string) ReviewFetcher
NewReviewFetcher creates a new ReviewFetcher.
type ReviewResult ¶ added in v0.17.35
type ReviewResult struct {
Verdict ReviewVerdict
Body string // full review body text
}
ReviewResult holds the latest review from a trusted reviewer.
type ReviewVerdict ¶ added in v0.17.35
type ReviewVerdict string
ReviewVerdict represents the outcome of a PR review.
const ( ReviewVerdictNone ReviewVerdict = "" ReviewVerdictApproved ReviewVerdict = "approved" ReviewVerdictChangesRequested ReviewVerdict = "changes_requested" )
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.
// If the branch does not yet exist, it is created from the current HEAD.
// Returns a wrapped error on failure (e.g. branch already checked out elsewhere).
Add(ctx context.Context, worktreePath string, branch string) error
// Remove removes the linked worktree at worktreePath.
// Uses --force to handle cases where the worktree is in an unclean state.
// Failure is logged as a warning but does NOT return an error (callers treat
// cleanup failure as non-fatal, per spec constraint).
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.
Source Files
¶
- bitbucket_collaborator_fetcher.go
- bitbucket_current_user_fetcher.go
- bitbucket_http.go
- bitbucket_pr_creator.go
- bitbucket_pr_merger.go
- bitbucket_remote.go
- bitbucket_review_fetcher.go
- brancher.go
- changelog.go
- cloner.go
- collaborator_fetcher.go
- doc.go
- git.go
- pr_creator.go
- pr_merger.go
- review_fetcher.go
- root.go
- semver.go
- validate.go
- worktreer.go