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 ¶
- Variables
- func BuildCommentBody(f render.Finding, whoami string) string
- func BuildReviewBody(v Verdict, whoami string) string
- func BuildUnanchoredSection(findings []render.Finding) string
- func EnsureGH() error
- func FetchDiff(ctx context.Context, r Runner, id, repo string) (string, error)
- func FetchLastOID(ctx context.Context, r Runner, id, repo string) (string, error)
- func PostComment(ctx context.Context, r Runner, c CommentRequest) error
- func SubmitReview(ctx context.Context, r Runner, id, repo string, v Verdict, body string) error
- func Whoami(ctx context.Context, r Runner) (string, error)
- type CommentRequest
- type PRMeta
- type Runner
- type Verdict
Constants ¶
This section is empty.
Variables ¶
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 ¶
BuildCommentBody renders one finding as an inline review comment body. Fixed English (ADR-0016 §10):
[SEVERITY] - Title Description 💡 Suggestion @whoami by #commitbrief
func BuildReviewBody ¶
BuildReviewBody returns the fixed-English review body for a verdict (ADR-0016 §6.4).
func BuildUnanchoredSection ¶ added in v1.2.1
BuildUnanchoredSection renders the findings that fell back to the review body. Returns "" when there are none so callers can append it unconditionally.
func EnsureGH ¶
func EnsureGH() error
EnsureGH reports ErrGHMissing when the `gh` binary is not on PATH.
func FetchLastOID ¶
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 is chosen by the caller from the parsed diff (RIGHT for added / context lines, LEFT for removed ones); a finding whose line is outside the diff is filtered out upstream and never reaches here, so a 422 is now an unexpected GitHub error rather than the routine hallucinated-line case (ADR-0016 §9).
func SubmitReview ¶
SubmitReview submits the review-level verdict via `gh pr review`.
Types ¶
type CommentRequest ¶
type CommentRequest struct {
RepoSlug string
PRNumber int
CommitID string
Path string
Line int
Side string
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. Side is "RIGHT" (new file) or "LEFT" (old file); empty defaults to RIGHT.
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 ¶
FetchPRMeta runs `gh pr view <id> --json number,author,url,headRepository,commits`.
func (PRMeta) AuthorLogin ¶
AuthorLogin returns the PR author's GitHub login.
type Runner ¶
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).