stack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanTitle

func CleanTitle(title string) string

CleanTitle strips the stack prefix from a title, returning the clean title. Returns the title unchanged if no prefix is present.

func CollectOpen

func CollectOpen(stackName string, prs []forge.PR) []forge.PR

CollectOpen returns all open PRs belonging to the given stack, sorted by their position prefix. PRs without a stack prefix are skipped.

func ComputeDepends

func ComputeDepends(prs []forge.PR)

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

func DeriveName(branch string) string

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

func DiagnoseBroken(openPRs, allPRs []forge.PR) []string

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

func FormatPrefix(p Prefix) string

FormatPrefix builds a stack prefix string from its components.

FormatPrefix(Prefix{Name: "auth", Pos: 2, Total: 3}) → "[auth:2/3]"

func Populate

func Populate(prs []forge.PR)

Populate scans PR titles and sets each PR's Stack field from its prefix. PRs without a prefix keep their Stack field unchanged.

func Sort

func Sort(prs []forge.PR)

Sort sorts PRs in place: unstacked first by number, then by stack name, then position.

func SortKey

func SortKey(pr forge.PR) string

SortKey returns a deterministic sort key for a PR that groups by stack: unstacked PRs sort first by number; stacked PRs sort by (stack name, position, number).

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

func ParsePrefix(title string) (Prefix, bool)

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

func NewTracker(prs PRUpdater) *Tracker

NewTracker creates a Tracker with the given PR updater.

func (*Tracker) Renumber

func (t *Tracker) Renumber(ctx context.Context, prs []forge.PR, stackName string) error

Renumber updates the title prefix of every open PR in the slice to reflect the current position (1-indexed) and total count. PRs whose title already matches the computed prefix are skipped.

Jump to

Keyboard shortcuts

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