Documentation
¶
Overview ¶
Package stack implements PR stack tracking — parsing, ordering, renumbering, and diagnosing linear chains of dependent PRs identified by title prefixes.
Pure functions (ParsePrefix, FormatPrefix, CleanTitle, Populate, SortKey, Sort, ComputeDepends, DeriveName, CollectOpen, DiagnoseBroken) require no dependencies and are tested directly. Orchestration that requires forge API access lives on Tracker, which takes a narrow PRUpdater interface.
Index ¶
- func CleanTitle(title string) string
- func CollectOpen(stackName string, prs []forge.PR) []forge.PR
- func ComputeDepends(prs []forge.PR)
- func DeriveName(branch string) string
- func DiagnoseBroken(openPRs, allPRs []forge.PR) []string
- func FormatPrefix(p Prefix) string
- func Populate(prs []forge.PR)
- func Sort(prs []forge.PR)
- func SortKey(pr forge.PR) string
- type PRUpdater
- type Prefix
- type Tracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanTitle ¶
CleanTitle strips the stack prefix from a title, returning the clean title. Returns the title unchanged if no prefix is present.
func CollectOpen ¶
CollectOpen returns all open PRs belonging to the given stack, sorted by their position prefix. PRs without a stack prefix are skipped.
func ComputeDepends ¶
ComputeDepends walks base.ref/head.ref relationships across the slice and populates DependsOn and DependedOnBy on each PR. PRs must already have Stack populated.
func DeriveName ¶
DeriveName returns a stack name from a branch name. If the branch contains a '/', the segment after the last '/' becomes the name. Branches without '/' return the empty string.
"feat/auth" → "auth" "fix-branch" → ""
func DiagnoseBroken ¶
DiagnoseBroken checks for broken stacks — PRs closed (not merged) between the first and last open PR in a stack. Returns diagnostic messages for each gap found.
The caller must fetch all PRs (open and closed) and pass them via allPRs. openPRs is the subset the caller already has; DiagnoseBroken uses it to find the active range within each stack.
func FormatPrefix ¶
FormatPrefix builds a stack prefix string from its components.
FormatPrefix(Prefix{Name: "auth", Pos: 2, Total: 3}) → "[auth:2/3]"
func Populate ¶
Populate scans PR titles and sets each PR's Stack field from its prefix. PRs without a prefix keep their Stack field unchanged.
Types ¶
type PRUpdater ¶
type PRUpdater interface {
Update(ctx context.Context, opts forge.PRUpdateOptions) (*forge.PR, error)
}
PRUpdater is the narrow interface the stack module needs from a forge. forge.PRService satisfies this automatically.
type Prefix ¶
type Prefix struct {
Name string // stack name (e.g., "auth")
Pos int // position in the stack (1-indexed)
Total int // total PRs in the stack at time of prefix
}
Prefix holds the parsed components of a stack title prefix.
func ParsePrefix ¶
ParsePrefix extracts stack info from a PR title. Returns the Prefix and whether a prefix was found.
"[auth:2/3] Add OAuth" → Prefix{Name: "auth", Pos: 2, Total: 3}, true
"Fix login" → Prefix{}, false
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker orchestrates stack operations that require forge API access.
func NewTracker ¶
NewTracker creates a Tracker with the given PR updater.