pr

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustColumnWidths added in v0.0.14

func AdjustColumnWidths(cols []TableColumn, prs []PRInfo)

AdjustColumnWidths widens each column so every value fits without truncation.

func AgeColorCode added in v0.0.49

func AgeColorCode(created, now time.Time) string

AgeColorCode returns the ANSI color prefix for a PR age: "" while the PR is fresh, yellow once it passes ageWarnAfter, red once it passes ageStaleAfter. Callers must reset with \033[0m when non-empty.

func AgeColorFunc added in v0.0.49

func AgeColorFunc(p PRInfo) string

AgeColorFunc is the table-column color accessor for the Age column.

func AgeDays added in v0.0.49

func AgeDays(created, now time.Time) int

AgeDays returns the whole number of days since created, or 0 for a zero creation time.

func AgeInfoFunc added in v0.0.49

func AgeInfoFunc(p PRInfo) string

AgeInfoFunc is the table-column accessor for the Age column.

func AuthorInfoFunc added in v0.0.9

func AuthorInfoFunc(p PRInfo) string

func ColorizeRescue added in v0.0.49

func ColorizeRescue(m *RescueMarker, now time.Time) string

ColorizeRescue wraps the FormatRescue annotation in ANSI colors: a stale marker renders yellow (retriable -- the code changed since the attempt), a fresh one bold red (a rescue already failed on exactly this code; a human is needed).

func ColorizeStatus added in v0.0.10

func ColorizeStatus(state StatusState, detail string) string

func DependencyInfoFunc added in v0.0.6

func DependencyInfoFunc(p PRInfo) string

func DisableLineWrap added in v0.0.41

func DisableLineWrap(w *os.File)

DisableLineWrap turns off the terminal's auto-wrap (DECAWM) so rows wider than the terminal are clipped at the right edge instead of wrapping onto a second physical line. UpdateTable's cursor-up math counts logical rows, so a wrapped row would desync the redraw and produce the garbled output users see when CI detail strings push a line past the terminal width.

func EnableLineWrap added in v0.0.41

func EnableLineWrap(w *os.File)

EnableLineWrap restores the terminal's auto-wrap mode. Always pair it with DisableLineWrap (typically via defer) so an early return does not leave the user's terminal in a clipped state.

func ExtractDependencyName

func ExtractDependencyName(title string) string

func ExtractOwnerRepo added in v0.0.10

func ExtractOwnerRepo(htmlURL string) (string, string, error)

ExtractOwnerRepo parses owner and repo from a GitHub HTML URL (e.g. "https://github.com/OWNER/REPO/pull/123").

func ExtractVersion added in v0.0.9

func ExtractVersion(title string) string

func FormatAge added in v0.0.49

func FormatAge(created, now time.Time) string

FormatAge renders the time since created as a compact human string ("5h", "3d", "2w"). It returns "" for a zero creation time so callers can omit the column value when the discovery path did not provide it.

func FormatRescue added in v0.0.49

func FormatRescue(m *RescueMarker, now time.Time) string

FormatRescue renders the marker as a short human-readable annotation for status output, e.g. "rescue failed 1d ago (klaus): ESM-only" or "rescue failed 3d ago (klaus), stale: new commits since".

func IsDependencyUpdateTitle added in v0.0.5

func IsDependencyUpdateTitle(title string) bool

IsDependencyUpdateTitle returns true if the PR title looks like an automated dependency update (Renovate or Dependabot), regardless of who authored it.

func MakeHyperlink(text, url string) string

func ParsePRURL added in v0.0.49

func ParsePRURL(htmlURL string) (owner, repo string, number int, err error)

ParsePRURL parses owner, repo, and PR number from a GitHub pull request URL (e.g. "https://github.com/OWNER/REPO/pull/123").

func PrintPlainResults added in v0.0.7

func PrintPlainResults(w *os.File, status *PRStatus)

func PrintRow added in v0.0.6

func PrintRow(w *os.File, e StatusEntry, cols []TableColumn)

func PrintTableHeader

func PrintTableHeader(w *os.File, cols []TableColumn)

func RepoInfoFunc added in v0.0.6

func RepoInfoFunc(p PRInfo) string

func UpdateTable

func UpdateTable(w *os.File, entries []StatusEntry, cols []TableColumn)

func VersionInfoFunc added in v0.0.9

func VersionInfoFunc(p PRInfo) string

Types

type PRGroup

type PRGroup struct {
	Key   string
	PRs   []PRInfo
	Count int
}

func GroupByDependency

func GroupByDependency(prs []PRInfo) []PRGroup

func GroupByRepo

func GroupByRepo(prs []PRInfo) []PRGroup

type PRInfo

type PRInfo struct {
	Owner     string
	Repo      string
	Number    int
	Title     string
	URL       string
	Author    string
	CreatedAt time.Time
}

type PRStatus

type PRStatus struct {
	// contains filtered or unexported fields
}

func NewPRStatus

func NewPRStatus() *PRStatus

func (*PRStatus) ActionRequired added in v0.0.7

func (s *PRStatus) ActionRequired() []StatusEntry

ActionRequired returns the failure entries, oldest PR first: the longer a dependency PR has been open, the more sweeps it has already survived, so the old ones are the most likely to need manual work. Entries without a known creation time sort last, in insertion order.

func (*PRStatus) Add

func (s *PRStatus) Add(pr PRInfo) int

func (*PRStatus) BlockedEntries added in v0.0.47

func (s *PRStatus) BlockedEntries() []StatusEntry

BlockedEntries returns entries whose CI could not run because a GitHub Actions budget / spending-limit block prevented every job from starting. These are deliberately kept out of ActionRequired and the failed counts: the remedy is "raise or await the Actions budget", not "rescue the code".

func (*PRStatus) FormatSummary

func (s *PRStatus) FormatSummary() string

func (*PRStatus) Len

func (s *PRStatus) Len() int

func (*PRStatus) MergedEntries added in v0.0.7

func (s *PRStatus) MergedEntries() []StatusEntry

func (*PRStatus) SecurityFailedEntries added in v0.0.41

func (s *PRStatus) SecurityFailedEntries() []StatusEntry

SecurityFailedEntries returns entries that failed specifically because a security-related check reported a problem.

func (*PRStatus) SetRescue added in v0.0.49

func (s *PRStatus) SetRescue(idx int, marker *RescueMarker)

SetRescue attaches a prior rescue-attempt marker to an entry.

func (*PRStatus) SkippedEntries added in v0.0.7

func (s *PRStatus) SkippedEntries() []StatusEntry

func (*PRStatus) Snapshot

func (s *PRStatus) Snapshot() []StatusEntry

func (*PRStatus) StateAt added in v0.0.49

func (s *PRStatus) StateAt(idx int) StatusState

StateAt returns the current state of the entry at idx, or StatusPending when idx is out of range.

func (*PRStatus) Summary

func (s *PRStatus) Summary() (merged, failed, blocked, skipped int)

Summary returns aggregate counts across all entries.

func (*PRStatus) Update

func (s *PRStatus) Update(idx int, state StatusState, detail string)

type RescueMarker added in v0.0.49

type RescueMarker struct {
	Tool    string    `json:"tool,omitempty"`
	Outcome string    `json:"outcome"`
	Reason  string    `json:"reason,omitempty"`
	HeadSHA string    `json:"head_sha,omitempty"`
	At      time.Time `json:"at,omitempty"`

	// Stale is computed by MarkStale, never serialized into the marker.
	Stale bool `json:"-"`
}

RescueMarker records a prior automated rescue attempt on a PR. It is embedded as a machine-readable HTML comment inside an ordinary PR comment, so any tool that can comment on a PR (a klaus agent, a Cursor agent, a GitHub Action) can participate without coupling to marge:

<!-- ai-rescue: {"tool":"klaus","outcome":"failed","reason":"...","head_sha":"...","at":"2026-06-09T18:40:00Z"} -->

HeadSHA ties the attempt to the code it was attempted against. Renovate force-pushes on rebase or version change, so a marker whose head_sha no longer matches the PR head describes code that no longer exists -- the attempt is stale and the PR is fair game for another rescue.

func ParseRescueMarker added in v0.0.49

func ParseRescueMarker(body string) *RescueMarker

ParseRescueMarker extracts the last ai-rescue marker from a comment body. It returns nil when the body contains no parseable marker; a malformed JSON payload is ignored rather than treated as an error so a mangled comment can never break a sweep.

func (*RescueMarker) CommentBody added in v0.0.49

func (m *RescueMarker) CommentBody() string

CommentBody renders the full PR comment for this marker: a human-readable summary followed by the machine-readable marker.

func (*RescueMarker) MarkStale added in v0.0.49

func (m *RescueMarker) MarkStale(currentHeadSHA string)

MarkStale sets Stale by comparing the marker's recorded head SHA with the PR's current head. Short-vs-full SHA prefixes match. A marker without a recorded SHA cannot be aged out, so it stays non-stale until a newer marker replaces it.

type StatusEntry

type StatusEntry struct {
	PR     PRInfo
	State  StatusState
	Detail string
	// Rescue is the most recent prior automated rescue attempt found on
	// the PR, if any. Only populated for failure-state entries.
	Rescue *RescueMarker
}

func SplitActionRequired added in v0.0.41

func SplitActionRequired(entries []StatusEntry) (security, other []StatusEntry)

SplitActionRequired partitions the action-required list into security failures and everything else, preserving the input order in each group.

type StatusState

type StatusState int
const (
	StatusPending StatusState = iota
	StatusChecking
	StatusApproving
	StatusMerging
	StatusRetrying
	StatusMerged
	StatusAlreadyMerged
	StatusAutoMerge
	StatusFailed
	StatusFailedSecurity
	StatusBlockedCI
	StatusSkipped
	StatusConflict
	StatusUntrustedAuthor
)

func (StatusState) String

func (s StatusState) String() string

type TableColumn added in v0.0.9

type TableColumn struct {
	Label string
	Width int
	Fn    func(PRInfo) string
	// Color optionally returns an ANSI color prefix for a value. The
	// value is padded to Width first, then wrapped, so colored cells
	// stay aligned with the rest of the table.
	Color func(PRInfo) string
}

func DependencySelectedColumns added in v0.0.9

func DependencySelectedColumns() []TableColumn

func FullColumns added in v0.0.9

func FullColumns() []TableColumn

func RepoSelectedColumns added in v0.0.9

func RepoSelectedColumns() []TableColumn

Jump to

Keyboard shortcuts

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