githubgh

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package githubgh implements the GitHub provider adapter by shelling out to the `gh` CLI. Lands in M2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Supports

func Supports(raw string) bool

Supports reports whether this adapter can handle the URL. Used by the provider registry to dispatch.

Types

type Adapter

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

Adapter fetches GitHub pull request data via the `gh` CLI.

func New

func New(run provider.Runner) *Adapter

New constructs an Adapter. Passing nil uses provider.DefaultRunner and a default Preflight that calls exec.LookPath. Tests that need to substitute LookPath can build an Adapter literal directly.

func (*Adapter) Fetch

func (a *Adapter) Fetch(ctx context.Context, rawURL string) (*review.ReviewInput, error)

Fetch retrieves PR metadata and the unified diff, then returns a normalized ReviewInput. The diff is parsed via internal/diff to surface classification errors early, before the model is invoked.

func (*Adapter) FetchLinkedIssues added in v0.2.0

func (a *Adapter) FetchLinkedIssues(ctx context.Context, target review.ReviewTarget) ([]review.IssueContext, []string, error)

FetchLinkedIssues resolves the issues this PR formally closes (closingIssuesReferences) and reads each one's title/body via `gh issue view`. diffsmith-144.

Failure contract (review.LinkedIssueFetcher): a failure of the closing-refs query is total (returned as err — the caller surfaces it as one note and proceeds with no criteria); a failure on an individual issue is non-fatal (the issue is dropped and a note is appended), so one inaccessible cross-repo issue can't sink the rest.

func (*Adapter) List

func (a *Adapter) List(ctx context.Context, repo provider.RepoCoord) ([]provider.PRSummary, error)

List enumerates open PRs for the repo and enriches each row with comment count, resolved/unresolved thread counts, and human commenters, all in a single GraphQL call.

func (*Adapter) Preflight

func (a *Adapter) Preflight(ctx context.Context) error

Preflight verifies gh is on PATH and authenticated before any fetch. New always wires a.preflight, and Adapter's fields are unexported so no zero-value literal can escape the package — a defensive nil-init here would be dead code.

func (*Adapter) PreflightList

func (a *Adapter) PreflightList(ctx context.Context) error

PreflightList verifies gh is authenticated before listing PRs.

func (*Adapter) Supports

func (a *Adapter) Supports(rawURL string) bool

Supports reports whether the URL is a GitHub pull request URL.

type Preflight

type Preflight struct {
	Run      provider.Runner
	LookPath func(name string) (string, error)
}

Preflight verifies the runtime environment is ready to fetch GitHub PRs.

Per docs/architecture.md § Pre-Flight Checks, the model is never invoked when these fail; the user sees an actionable message instead of a stack trace from `os/exec`.

func NewPreflight

func NewPreflight(run provider.Runner, lookPath func(string) (string, error)) *Preflight

NewPreflight builds a Preflight with sensible defaults. Tests inject fakes; production code calls NewPreflight(nil, nil).

func (*Preflight) Check

func (p *Preflight) Check(ctx context.Context) error

Check runs `gh` binary presence and `gh auth status` in order. The first failure is surfaced with an actionable message; later checks are skipped.

type PullRequestRef

type PullRequestRef struct {
	Owner  string
	Repo   string
	Number int
	URL    string // canonical form: https://github.com/<owner>/<repo>/pull/<number>
}

PullRequestRef identifies a GitHub pull request parsed from a URL.

func ParseURL

func ParseURL(raw string) (*PullRequestRef, error)

ParseURL extracts a PullRequestRef from a GitHub pull request URL.

Accepts the canonical form and any sub-path under it (e.g. /files, /commits), query strings, and trailing slashes. Rejects URLs that are not pull requests, not GitHub, or not HTTPS.

Jump to

Keyboard shortcuts

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