branches

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package branches provides logic for finding and managing branches across multiple git repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAutomationBranch added in v0.3.0

func IsAutomationBranch(branch string) bool

IsAutomationBranch returns true if the branch name matches a known automation pattern.

Types

type MergeMethodResolver added in v0.10.0

type MergeMethodResolver interface {
	PRMergeMethod(owner, repo, mergeCommitSHA string) (string, error)
}

MergeMethodResolver determines how a PR was merged by inspecting the merge commit. Implemented by *github.Client.

type MergedBranch

type MergedBranch struct {
	RepoPath   string
	RepoName   string
	Branch     string
	LastCommit time.Time
	HasRemote  bool
	// ForceDelete is true when the branch was detected as merged via the
	// GitHub API (e.g. squash-merge) rather than by git. These branches
	// require git branch -D because git does not recognize them as merged.
	ForceDelete bool
	// PRNumber is the GitHub PR number (0 if not available or git-detected).
	PRNumber int
	// PRMergedAt is the timestamp when the PR was merged on GitHub.
	PRMergedAt time.Time
	// MergeCommitSHA is the merge commit SHA from the GitHub API, used for
	// determining the merge method without an extra API call.
	MergeCommitSHA string
	// MergeMethod is "merge", "squash", or "" if unknown.
	MergeMethod string
}

MergedBranch represents a branch that has been merged into the default branch.

func EnrichMergeMethod added in v0.10.0

func EnrichMergeMethod(merged []MergedBranch, resolver MergeMethodResolver, workers int) []MergedBranch

EnrichMergeMethod fetches the merge method (merge vs squash) for branches that were detected via the GitHub API. Uses the MergeCommitSHA already captured during detection to avoid extra API calls per branch. The returned slice is the same as the input; items are modified in place.

func FindMerged

func FindMerged(repos []string, detector *merge.Detector, workers int, onProgress func(completed, total int)) ([]MergedBranch, error)

FindMerged scans the given repositories and returns branches that have been merged into each repo's default branch. The current branch and the default branch itself are excluded from results. Work is parallelized across the given number of workers. The detector combines local git checks with GitHub API lookups to catch squash-merges.

func (MergedBranch) Label

func (m MergedBranch) Label() string

Label returns a display string for the merged branch in the form "repo: branch". Branches with a remote counterpart are annotated with "(backed up remotely)". PR info is appended when available.

type StaleBranch added in v0.2.2

type StaleBranch struct {
	RepoPath          string
	RepoName          string
	Branch            string
	LastCommit        time.Time
	LastCommitMessage string
	CommitsAhead      int
	CommitsBehind     int
	HasRemote         bool
	// IsLocalOnly is true when the branch has no remote tracking branch.
	// These are candidates for cleanup but require extra caution since
	// commits may not exist anywhere else.
	IsLocalOnly bool
	// IsAutomation is true for branches matching known automation patterns
	// (e.g. dependabot/*, renovate/*, release-please--*).
	IsAutomation bool
	// IsOwnBranch is true when the user is the sole author of all commits
	// on this branch since it diverged from the default branch.
	IsOwnBranch bool
	// PRNumber is the GitHub PR number if the branch has a merged PR.
	PRNumber int
	// PRMergedAt is the timestamp when the PR was merged.
	PRMergedAt time.Time
}

StaleBranch represents a branch that has not been committed to within the configured staleness threshold and has not been merged.

func FindStale added in v0.2.2

func FindStale(repos []string, threshold time.Duration, detector *merge.Detector, workers int, onProgress func(completed, total int)) ([]StaleBranch, error)

FindStale scans the given repositories and returns branches whose last commit is older than the given threshold. Merged branches, the default branch, and the currently checked out branch are excluded. Work is parallelized across the given number of workers. The detector combines local git checks with GitHub API lookups to determine which branches are merged.

func (StaleBranch) Label added in v0.2.2

func (s StaleBranch) Label() string

Label returns a display string for the stale branch in the form "repo: branch".

Jump to

Keyboard shortcuts

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