Documentation
¶
Overview ¶
Package data fetches Pull Request metadata from GitHub.
The PRClient interface keeps the GitHub-specific code behind a small surface so the TUI/CLI can be exercised against a mock in tests.
Index ¶
- func AssigneesLabel(pr PR) string
- func CanonicalURL(raw string) (string, error)
- func DetailsLabel(pr PR) string
- func ETALabel(pr PR) string
- func FetchDiff(ctx context.Context, url string) (string, error)
- func IsTerminal(pr PR) bool
- func ParseURL(url string) (owner, repo string, number int, err error)
- func QueueLabel(pr PR) string
- func QueueLabelShort(pr PR) string
- func QueuePositionLabel(pr PR) string
- func ShortURL(u string) string
- func StatusLabel(pr PR) string
- type DiffSummary
- type GHClient
- type MergeQueueEntry
- type MockClient
- type PR
- type PRClient
- type Result
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssigneesLabel ¶
AssigneesLabel renders the assignee column ("-" when empty).
func CanonicalURL ¶
CanonicalURL returns just the canonical PR URL (no fragments/queries).
func DetailsLabel ¶ added in v0.4.0
DetailsLabel returns the compact "status details" column. When the PR is in the merge queue it summarises queue state + position + ETA; when the PR is open/blocked it explains why (review required, conflicts, behind base, etc.) using MergeStateStatus and ReviewDecision. Otherwise returns "-".
func FetchDiff ¶
FetchDiff returns the raw unified diff text for a PR by shelling out to `gh api` with the diff Accept header. This avoids re-implementing GitHub auth — anywhere `gh` is logged in, this works.
func IsTerminal ¶
IsTerminal reports whether the PR has reached a terminal state (merged or closed) and should be archived.
func ParseURL ¶
ParseURL extracts (owner, repo, number) from a canonical GitHub PR URL. Returns an error if the URL doesn't match.
func QueueLabel ¶
QueueLabel returns the merge-queue column ("-" when not queued).
func QueueLabelShort ¶ added in v0.3.0
QueueLabelShort returns a compact (<= 8 chars) queue state for table display. QueueLabel keeps the verbose form for single-PR views like `prowl get`.
func QueuePositionLabel ¶
QueuePositionLabel renders the position column.
func ShortURL ¶ added in v0.3.0
ShortURL trims the `https://github.com/` (or www / http) prefix so URLs fit in a compact table column. Non-github URLs are returned unchanged.
func StatusLabel ¶
StatusLabel returns the human-friendly status column ("open", "draft", "open/blocked", "merged", "closed", "unknown").
Types ¶
type DiffSummary ¶
type DiffSummary struct {
Files int `json:"files"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}
DiffSummary is a light-weight digest of a unified diff.
func SummarizeDiff ¶
func SummarizeDiff(diff string) DiffSummary
SummarizeDiff counts files, additions, and deletions in a unified diff.
type GHClient ¶
type GHClient struct {
// contains filtered or unexported fields
}
GHClient implements PRClient using go-gh's GraphQL client.
func NewGHClient ¶
NewGHClient builds a real GitHub client. It honours the same auth as `gh`.
type MergeQueueEntry ¶
type MergeQueueEntry struct {
State string `json:"state"`
Position int `json:"position"`
ETA time.Duration `json:"eta,omitempty"`
}
MergeQueueEntry models a PR's membership in GitHub's native merge queue.
type MockClient ¶
MockClient is an in-memory PRClient. Tests populate PRs (and optionally Errors) keyed by URL.
func (*MockClient) FetchBatch ¶
func (m *MockClient) FetchBatch(ctx context.Context, urls []string) []Result
FetchBatch fans out across the mock concurrently to mirror the real client.
func (*MockClient) LoadFixtures ¶
func (m *MockClient) LoadFixtures(path string) error
LoadFixtures reads a JSON file containing a map of canonical URL → PR and merges it into the mock. Multiple calls accumulate.
type PR ¶
type PR struct {
URL string `json:"url"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Number int `json:"number"`
Title string `json:"title,omitempty"`
State string `json:"state"`
MergeStateStatus string `json:"merge_state_status,omitempty"`
ReviewDecision string `json:"review_decision,omitempty"`
CheckRollupState string `json:"check_rollup_state,omitempty"`
IsDraft bool `json:"is_draft"`
Assignees []string `json:"assignees,omitempty"`
Queue *MergeQueueEntry `json:"queue,omitempty"`
}
PR is the structured view of a single GitHub Pull Request.
type PRClient ¶
type PRClient interface {
Fetch(ctx context.Context, url string) (PR, error)
FetchBatch(ctx context.Context, urls []string) []Result
}
PRClient is the surface used by the CLI/TUI/MCP layers to read PR state.
type Stats ¶ added in v0.3.0
type Stats struct {
Active int `json:"active"`
Reviewed int `json:"reviewed"`
Total int `json:"total"`
Open int `json:"open"`
Draft int `json:"draft"`
Blocked int `json:"blocked"`
Merged int `json:"merged"`
Closed int `json:"closed"`
Queued int `json:"queued"`
Errors int `json:"errors,omitempty"`
}
Stats summarises tracked PR counts and the active list's state breakdown. Reviewed counts are URL-only (no fetch) since those PRs are already archived.
func ComputeStats ¶ added in v0.3.0
ComputeStats derives counts from the fetched active results and the raw reviewed-URL count.