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

github

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultCacheTTL = 300 * time.Second

DefaultCacheTTL is the TTL applied when caching is enabled and no other value is specified. Five minutes balances freshness with point savings.

View Source
const DefaultTeamCacheTTL = 24 * time.Hour

DefaultTeamCacheTTL is the freshness window for team membership lookups. Team rosters change rarely (org admin action), so a long TTL keeps the fast path instant for repeated invocations while still picking up changes within a working day.

Variables

View Source
var ErrTeamNotFound = errors.New("team not found or not visible to viewer")

ErrTeamNotFound is returned when GitHub responds successfully but the team does not exist (or the viewer cannot see it). Distinct from a transport error so the CLI can produce a precise, user-friendly message.

Functions

func DecodeForTests

func DecodeForTests(raw []byte) (*model.Repo, error)

DecodeForTests decodes a GraphQL response envelope captured as JSON (matching the shape of testdata/fixtures/*.json) into a *model.Repo. Exported solely so internal/render tests can drive golden comparisons. Do not use in production code.

func DefaultCacheDir

func DefaultCacheDir() string

DefaultCacheDir returns the per-user cache directory for gh-prs entries. Falls back to a sibling of the binary's temp dir if UserCacheDir is not resolvable (very rare on macOS/Linux; e.g. HOME unset in a sandbox).

func ParseCacheTTL

func ParseCacheTTL(raw string) (time.Duration, bool)

ParseCacheTTL parses a human duration string (e.g. "60s", "2m"). Empty or invalid input returns (DefaultCacheTTL, false) so callers can distinguish "defaulted" from "explicitly set".

Types

type Client

type Client interface {
	FetchRepo(ctx context.Context, filters filter.Set) (*model.Repo, error)
}

func New

func New(opts Options) (Client, error)

type Options

type Options struct {
	// Debug enables httpretty-style logging of the GraphQL request/response
	// (URL, headers, body, timing) to DebugOut. Honors DebugColor for ANSI.
	Debug      bool
	DebugOut   io.Writer
	DebugColor bool
}

Options configures the GitHub client. Zero-value is safe: no debug.

type SWRClient added in v0.5.0

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

SWRClient wraps a Client with stale-while-revalidate disk caching.

func NewSWRClient added in v0.5.0

func NewSWRClient(
	inner Client,
	resolve func() (repository.Repository, error),
	cacheDir string,
	ttl time.Duration,
) *SWRClient

NewSWRClient wraps the given client with SWR caching.

func (*SWRClient) FetchRepo added in v0.5.0

func (c *SWRClient) FetchRepo(ctx context.Context, filters filter.Set) (*model.Repo, error)

FetchRepo implements Client. It serves from cache when possible and triggers background refreshes for stale entries.

func (*SWRClient) LingerWait added in v0.5.0

func (c *SWRClient) LingerWait()

LingerWait blocks until all background refreshes complete or the linger cap fires. Call this after printing output and before exiting the process.

type TeamResolver added in v0.5.0

type TeamResolver interface {
	ResolveTeam(ctx context.Context, org, slug string) ([]string, error)
}

TeamResolver expands a GitHub team into the set of member logins.

Implementations must:

  • Treat the slug case-insensitively (GitHub team slugs are lowercase).
  • Return logins in deterministic order (sorted) so callers can compare and cache results without spurious diffs.
  • Wrap upstream errors with model.GhError so the CLI exit-code mapper handles them like any other gh failure.

func NewCachedTeamResolver added in v0.5.0

func NewCachedTeamResolver(inner TeamResolver, cacheDir string, ttl time.Duration) TeamResolver

NewCachedTeamResolver wraps inner with a disk-backed cache rooted under cacheDir. A non-positive ttl falls back to DefaultTeamCacheTTL.

func NewTeamResolver added in v0.5.0

func NewTeamResolver(opts Options) (TeamResolver, error)

NewTeamResolver builds a TeamResolver backed by the same GraphQL transport as the main PR client. Kept as a separate factory (rather than expanding Client) so PR-fetch consumers don't take on a transitive dependency on team-resolution code, and so callers that don't need teams pay nothing.

Jump to

Keyboard shortcuts

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