Documentation
¶
Overview ¶
Package orphans classifies stale git branches by whether their pull request was merged, closed, or never opened, so gh-sweep can flag them for cleanup.
Index ¶
- type Detector
- type NamespaceScanResult
- type NamespaceScanner
- func (s *NamespaceScanner) ScanNamespace(ctx context.Context, namespace string) (*NamespaceScanResult, error)
- func (s *NamespaceScanner) ScanNamespaceWithProgress(ctx context.Context, namespace string, progressCh chan<- ScanProgress) (*NamespaceScanResult, error)
- func (s *NamespaceScanner) ScanRepo(ctx context.Context, repo github.Repository) ScanResult
- type OrphanType
- type OrphanedBranch
- type ScanOptions
- type ScanProgress
- type ScanResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector classifies individual branches as orphaned according to a fixed ScanOptions.
func NewDetector ¶
func NewDetector(options ScanOptions) *Detector
NewDetector returns a Detector that classifies branches using options.
func (*Detector) ClassifyBranch ¶
func (d *Detector) ClassifyBranch( repo github.Repository, branch github.Branch, prs []github.PullRequest, ) *OrphanedBranch
ClassifyBranch returns branch's OrphanedBranch classification, or nil when branch is excluded, protected, has an open PR, or doesn't otherwise qualify as orphaned.
type NamespaceScanResult ¶
type NamespaceScanResult struct {
Namespace string `json:"namespace"`
IsOrg bool `json:"is_org"`
Results []ScanResult `json:"results"`
TotalRepos int `json:"total_repos"`
TotalOrphans int `json:"total_orphans"`
}
NamespaceScanResult aggregates the ScanResult for every repository in a user or organization namespace.
func (*NamespaceScanResult) AllOrphans ¶
func (r *NamespaceScanResult) AllOrphans() []OrphanedBranch
AllOrphans flattens every repository's orphaned branches into one slice.
func (*NamespaceScanResult) OrphansByType ¶
func (r *NamespaceScanResult) OrphansByType(t OrphanType) []OrphanedBranch
OrphansByType returns AllOrphans filtered to the given OrphanType.
type NamespaceScanner ¶
type NamespaceScanner struct {
// contains filtered or unexported fields
}
NamespaceScanner scans every non-archived repository in a GitHub user or organization namespace for orphaned branches, concurrently up to its ScanOptions.Concurrency limit.
func NewNamespaceScanner ¶
func NewNamespaceScanner(client *github.Client, options ScanOptions) *NamespaceScanner
NewNamespaceScanner returns a NamespaceScanner that scans repositories via client using options.
func (*NamespaceScanner) ScanNamespace ¶
func (s *NamespaceScanner) ScanNamespace( ctx context.Context, namespace string, ) (*NamespaceScanResult, error)
ScanNamespace scans every repository in namespace and returns the aggregated result.
func (*NamespaceScanner) ScanNamespaceWithProgress ¶
func (s *NamespaceScanner) ScanNamespaceWithProgress( ctx context.Context, namespace string, progressCh chan<- ScanProgress, ) (*NamespaceScanResult, error)
ScanNamespaceWithProgress scans every repository in namespace concurrently, sending a ScanProgress update after each repository completes when progressCh is non-nil. Updates are dropped rather than blocking if the channel isn't ready to receive.
func (*NamespaceScanner) ScanRepo ¶
func (s *NamespaceScanner) ScanRepo(ctx context.Context, repo github.Repository) ScanResult
ScanRepo scans repo's non-default branches and returns the ScanResult, stopping early (with whatever orphans were already found) if ctx is canceled mid-scan.
type OrphanType ¶
type OrphanType string
OrphanType categorizes why a branch has no active pull request.
const ( OrphanTypeMergedPR OrphanType = "merged_pr" OrphanTypeClosedPR OrphanType = "closed_pr" OrphanTypeStale OrphanType = "stale" OrphanTypeRecentNoPR OrphanType = "recent_no_pr" )
The set of reasons a branch can be classified as orphaned.
func (OrphanType) Label ¶
func (t OrphanType) Label() string
Label returns the human-readable name for t.
type OrphanedBranch ¶
type OrphanedBranch struct {
Repository string `json:"repository"`
BranchName string `json:"branch_name"`
SHA string `json:"sha"`
LastCommitDate time.Time `json:"last_commit_date"`
Type OrphanType `json:"type"`
PRNumber *int `json:"pr_number,omitempty"`
PRTitle *string `json:"pr_title,omitempty"`
DaysSinceActivity int `json:"days_since_activity"`
Protected bool `json:"protected"`
}
OrphanedBranch is a branch classified as safe to clean up, along with the pull request context that justified the classification.
func (OrphanedBranch) Key ¶
func (o OrphanedBranch) Key() string
Key uniquely identifies the branch within a scan by repository and name.
type ScanOptions ¶
type ScanOptions struct {
StaleDaysThreshold int
IncludeRecentNoPR bool
ExcludePatterns []string
IncludeProtected bool
Concurrency int
}
ScanOptions configures how a Detector or NamespaceScanner classifies and scans branches.
func DefaultScanOptions ¶
func DefaultScanOptions() ScanOptions
DefaultScanOptions returns the ScanOptions gh-sweep uses when the caller hasn't customized any scan settings.
type ScanProgress ¶
ScanProgress reports a NamespaceScanner's progress as it works through a namespace's repositories.
type ScanResult ¶
type ScanResult struct {
Repository github.Repository `json:"repository"`
Orphans []OrphanedBranch `json:"orphans"`
DefaultBranch string `json:"default_branch"`
Error error `json:"error,omitempty"`
}
ScanResult holds the orphaned branches found in a single repository, or the error encountered scanning it.