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

github

package
v0.0.0-...-f4d9c11 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package github fetches the viewer's pull requests from the GitHub GraphQL API and maps them into domain types. It is the only package that knows the wire format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSearch

func BuildSearch(now time.Time, closedDays int) string

BuildSearch returns the search string: every PR the viewer authored or is assigned to, open or closed inside the window. DATE is date-granular, so it carries one extra day of margin. sort:updated-desc filters nothing; it makes a page-capped list keep the most recently updated PRs. There is deliberately no archived:false qualifier: open PRs in archived repositories must be listed.

Types

type Client

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

Client fetches pull requests. It implements ui.Fetcher.

func NewClient

func NewClient(opts Options) (*Client, error)

NewClient builds a Client. The token is passed explicitly and never logged: LogIgnoreEnv stops GH_DEBUG from writing HTTP traffic over the screen, and the response cache stays off so polling never shows stale data.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context) (domain.Snapshot, error)

Fetch runs the discovery query page by page, de-duplicates by node id, merges in the saved watch list (the saved PRs that discovery did not return are looked up, in chunks), keeps the PRs inside the closed window and orders them for display. A Lookup that fails as a whole fails the refresh, so the rows on screen stay. It then names the failing check of every failing PR with a second query (D-01), inside the same call, so the whole refresh stays one single-flight fetch.

func (*Client) FetchDetail

func (c *Client) FetchDetail(ctx context.Context, id string) (domain.Detail, error)

FetchDetail returns the full detail of one pull request: its de-duplicated, sorted checks, every reviewer with their state, and the counts.

Contexts are read 100 at a time for at most maxPages pages. Counts always come from the de-duplicated checks of the pages read (D-03), so a run superseded on another page is not counted. Truncated is set only when check runs were not read: the pull request has more runs than the page cap reads, a later page fails, or fewer runs were read than GitHub reports (for example nodes that GraphQL returned as null). Read and Total say how many runs were read of how many exist. Partial is set separately when any page came back with a GraphQL error whose data was kept, because a check, a reviewer or a review request may then be missing (G-03-6, WR-05). A failure on page 1 is returned; so are a rate limit and a cancelled context on any page.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, ref domain.Ref) (domain.PR, error)

Lookup loads one PR by ref for the add prompt (D-02). A PR that cannot be read comes back with Unavail set; an error means the request failed as a whole. A PR with failing CI also gets its failing check named, so the new row looks like every other. It may run while Fetch runs: the two share only the GraphQL client and the header capture, which are safe for concurrent use.

type Error

type Error struct {
	Kind    ErrorKind
	Status  int
	Message string

	// RetryAfter and ResetAt are set for KindRateLimited when GitHub sent
	// them; zero means absent.
	RetryAfter time.Duration
	ResetAt    time.Time
	// contains filtered or unexported fields
}

Error is a failed fetch, described for the user. Its text is built only from the HTTP status, fixed strings and a cleaned API message: never from headers, request dumps or the token.

func (*Error) Backoff

func (e *Error) Backoff() (time.Duration, time.Time, bool)

Backoff reports how long GitHub asked prv to wait (Retry-After), when the limit resets, and whether this failure is a rate limit at all. The ui reads it through its own interface.

func (*Error) Error

func (e *Error) Error() string

Error returns the description shown in the error panel.

func (*Error) Hint

func (e *Error) Hint() string

Hint says how to fix the failure.

func (*Error) Short

func (e *Error) Short() string

Short names the failure in one or two words for the header (D-07). The text is fixed per kind: it never holds the API message or the token.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error, for errors.Is and errors.As.

type ErrorKind

type ErrorKind int

ErrorKind says what kind of failure GitHub or the network produced.

const (
	KindAuth ErrorKind = iota
	KindForbidden
	KindServer
	KindNetwork
	KindGraphQL
	KindUnknown
	KindRateLimited
)

type Options

type Options struct {
	Token      string
	ClosedDays int
	Now        func() time.Time
	Transport  http.RoundTripper // nil means the default transport; tests inject a fake
	Watch      WatchSource       // nil means no saved list
}

Options configures a Client.

type WatchSource

type WatchSource interface {
	Load() ([]domain.Ref, []string, error)
}

WatchSource supplies the saved watch list. *watchlist.Store implements it. Load runs inside Fetch, which runs in a tea.Cmd, so every refresh reads the file (D-16).

Jump to

Keyboard shortcuts

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