remote

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package remote drives GitHub operations (currently PR review) through the user's `gh` CLI. It performs no HTTPS calls itself — `gh` handles auth, host resolution, and the REST round-trips. See ADR-0016.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGHMissing — the `gh` binary is not on PATH.
	ErrGHMissing = errors.New("remote: gh binary not found on PATH")
	// ErrSelfPR — the authenticated user is the PR author (GitHub blocks
	// self-approval; we reject before fetching the diff).
	ErrSelfPR = errors.New("remote: cannot review your own pull request")
	// ErrTooVolatile — the PR head changed twice during review; aborted.
	ErrTooVolatile = errors.New("remote: pull request changed during review")
)

Sentinel errors let the CLI layer map failures to i18n catalog keys without string-matching. Wrap with %w where extra context helps.

Functions

func BuildCommentBody

func BuildCommentBody(f render.Finding, whoami string) string

BuildCommentBody renders one finding as an inline review comment body. Fixed English (ADR-0016 §10):

[SEVERITY] - Title
Description
Suggestion @whoami by #CommitBrief

func BuildReviewBody

func BuildReviewBody(v Verdict, whoami string) string

BuildReviewBody returns the fixed-English review body for a verdict (ADR-0016 §6.4).

func EnsureGH

func EnsureGH() error

EnsureGH reports ErrGHMissing when the `gh` binary is not on PATH.

func FetchDiff

func FetchDiff(ctx context.Context, r Runner, id, repo string) (string, error)

FetchDiff returns the PR's unified diff (`gh pr diff <id>`).

func FetchLastOID

func FetchLastOID(ctx context.Context, r Runner, id, repo string) (string, error)

FetchLastOID re-reads only the commits to detect a head change cheaply between the diff fetch and the review submission (race check).

func PostComment

func PostComment(ctx context.Context, r Runner, c CommentRequest) error

PostComment posts a single inline review comment via the REST API. `side=RIGHT` is unconditional (the LLM reviews newly-added code); a finding pinned to a deleted line may return 422, which the caller swallows per-comment (ADR-0016 §9).

func SubmitReview

func SubmitReview(ctx context.Context, r Runner, id, repo string, v Verdict, body string) error

SubmitReview submits the review-level verdict via `gh pr review`.

func Whoami

func Whoami(ctx context.Context, r Runner) (string, error)

Whoami returns the authenticated GitHub login (`gh api user -q .login`).

Types

type CommentRequest

type CommentRequest struct {
	RepoSlug string
	PRNumber int
	CommitID string
	Path     string
	Line     int
	Body     string
}

CommentRequest is one inline comment to POST. RepoSlug is the PR's baseRepository ("owner/name", cross-fork correctness); CommitID is the head OID the diff was fetched at.

type PRMeta

type PRMeta struct {
	Number         int      `json:"number"`
	Author         owner    `json:"author"`
	URL            string   `json:"url"`
	HeadRepository repoRef  `json:"headRepository"`
	Commits        []commit `json:"commits"`
}

PRMeta is the subset of `gh pr view --json ...` that remote pr consumes.

Note: gh does not expose a baseRepository field on PRs — the base repo is derived from the PR URL (which always points at the base repo) via BaseSlug.

func FetchPRMeta

func FetchPRMeta(ctx context.Context, r Runner, id, repo string) (PRMeta, error)

FetchPRMeta runs `gh pr view <id> --json number,author,url,headRepository,commits`.

func (PRMeta) AuthorLogin

func (m PRMeta) AuthorLogin() string

AuthorLogin returns the PR author's GitHub login.

func (PRMeta) BaseSlug added in v1.2.0

func (m PRMeta) BaseSlug() string

BaseSlug returns the base repository as "owner/name", parsed from the PR URL (https://<host>/<owner>/<repo>/pull/<n>). A PR's web URL always lives on the base repo, so this is correct even for cross-fork PRs. Returns "" if the URL is malformed.

func (PRMeta) LastOID

func (m PRMeta) LastOID() string

LastOID returns the head commit OID, or "" when the PR has no commits.

type Runner

type Runner interface {
	Run(ctx context.Context, args ...string) ([]byte, error)
}

Runner executes a `gh` invocation and returns its stdout. Production uses execRunner; tests inject a fake to avoid live network and to script sequential responses (race-retry, failure paths).

func NewRunner

func NewRunner() Runner

NewRunner returns the production Runner backed by the `gh` binary.

type Verdict

type Verdict int

Verdict is the review-level action submitted to GitHub.

const (
	// VerdictApprove — no findings reached the request-changes threshold.
	VerdictApprove Verdict = iota
	// VerdictComment — findings exist but none reached the threshold.
	VerdictComment
	// VerdictRequestChanges — at least one finding reached the threshold.
	VerdictRequestChanges
)

Jump to

Keyboard shortcuts

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