Help us shape the future of Go! Take the 2026 Go Developer Survey

data

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssigneesLabel

func AssigneesLabel(pr PR) string

AssigneesLabel renders the assignee column ("-" when empty).

func CanonicalURL

func CanonicalURL(raw string) (string, error)

CanonicalURL returns just the canonical PR URL (no fragments/queries).

func DetailsLabel added in v0.4.0

func DetailsLabel(pr PR) string

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 ETALabel

func ETALabel(pr PR) string

ETALabel formats the queue ETA as ~Ns / ~Nm / ~Nh, "-" if unset.

func FetchDiff

func FetchDiff(ctx context.Context, url string) (string, error)

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

func IsTerminal(pr PR) bool

IsTerminal reports whether the PR has reached a terminal state (merged or closed) and should be archived.

func ParseURL

func ParseURL(url string) (owner, repo string, number int, err error)

ParseURL extracts (owner, repo, number) from a canonical GitHub PR URL. Returns an error if the URL doesn't match.

func QueueLabel

func QueueLabel(pr PR) string

QueueLabel returns the merge-queue column ("-" when not queued).

func QueueLabelShort added in v0.3.0

func QueueLabelShort(pr PR) string

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

func QueuePositionLabel(pr PR) string

QueuePositionLabel renders the position column.

func ShortURL added in v0.3.0

func ShortURL(u string) string

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

func StatusLabel(pr PR) string

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

func NewGHClient() (*GHClient, error)

NewGHClient builds a real GitHub client. It honours the same auth as `gh`.

func (*GHClient) Fetch

func (c *GHClient) Fetch(ctx context.Context, url string) (PR, error)

Fetch retrieves a single PR by URL.

func (*GHClient) FetchBatch

func (c *GHClient) FetchBatch(ctx context.Context, urls []string) []Result

FetchBatch concurrently fetches many PRs. Returned slice is in input order. Per-URL errors do not abort the batch — they're attached to the corresponding Result instead.

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

type MockClient struct {
	PRs    map[string]PR
	Errors map[string]error
}

MockClient is an in-memory PRClient. Tests populate PRs (and optionally Errors) keyed by URL.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient builds an empty MockClient.

func (*MockClient) Fetch

func (m *MockClient) Fetch(_ context.Context, url string) (PR, error)

Fetch looks up a single 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"`
	UnresolvedThreads int              `json:"unresolved_threads,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 Result

type Result struct {
	URL string
	PR  PR
	Err error
}

Result is a per-URL outcome from FetchBatch.

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

func ComputeStats(active []Result, reviewedCount int) Stats

ComputeStats derives counts from the fetched active results and the raw reviewed-URL count.

Jump to

Keyboard shortcuts

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