{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package remote\n\nPackage 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.\n\n## Variables\n\n```go\nvar (\n\t// ErrGHMissing — the `gh` binary is not on PATH.\n\tErrGHMissing = errors.New(\"remote: gh binary not found on PATH\")\n\t// ErrSelfPR — the authenticated user is the PR author (GitHub blocks\n\t// self-approval; we reject before fetching the diff).\n\tErrSelfPR = errors.New(\"remote: cannot review your own pull request\")\n\t// ErrTooVolatile — the PR head changed twice during review; aborted.\n\tErrTooVolatile = errors.New(\"remote: pull request changed during review\")\n)\n```\nSentinel errors let the CLI layer map failures to i18n catalog keys without string-matching. Wrap with %w where extra context helps.\n\n## Functions\n\n```go\nfunc BuildCommentBody(f render.Finding, whoami string) string\n```\nBuildCommentBody renders one finding as an inline review comment body. Fixed English (ADR-0016 §10):\n\n\t[SEVERITY] - Title\n\tDescription\n\t💡 Suggestion @whoami by #commitbrief\n\nA finding that carries a fingerprint also gets the identity marker on its own trailing line (ADR-0046); the visible text is unchanged.\n\n```go\nfunc BuildReviewBody(v Verdict, whoami string) string\n```\nBuildReviewBody returns the fixed-English review body for a verdict (ADR-0016 §6.4).\n\n```go\nfunc BuildUnanchoredSection(findings []render.Finding) string\n```\nBuildUnanchoredSection renders the findings that fell back to the review body. Returns \"\" when there are none so callers can append it unconditionally.\n\n```go\nfunc CommentText(f render.Finding, whoami string) string\n```\nCommentText renders the visible part of a finding's comment (no marker).\n\n```go\nfunc EnsureGH() error\n```\nEnsureGH reports ErrGHMissing when the \\`gh\\` binary is not on PATH.\n\n```go\nfunc FetchCompareDiff(ctx context.Context, r Runner, slug, base, head string) (string, error)\n```\nFetchCompareDiff returns the unified diff of base...head. Large comparisons make the API fail; the caller then falls back to the full PR diff.\n\n```go\nfunc FetchDiff(ctx context.Context, r Runner, id, repo string) (string, error)\n```\nFetchDiff returns the PR's unified diff (\\`gh pr diff \\\u003cid\u003e\\`).\n\n```go\nfunc FetchLastOID(ctx context.Context, r Runner, id, repo string) (string, error)\n```\nFetchLastOID re-reads only the commits to detect a head change cheaply between the diff fetch and the review submission (race check).\n\n```go\nfunc FetchLastReviewedOID(ctx context.Context, r Runner, slug string, number int) (string, error)\n```\nFetchLastReviewedOID returns the head OID recorded in the newest review the viewer authored that carries the K8 marker, looking at the PR's last 100 reviews only. An empty OID with a nil error means there is none.\n\n```go\nfunc NormalizeText(s string) string\n```\nNormalizeText prepares comment text for the \"is the body the same?\" comparison: CRLF -\u003e LF, trailing whitespace trimmed per line and overall.\n\n```go\nfunc ParseReviewedMarker(body string) (string, bool)\n```\nParseReviewedMarker extracts the head OID from a review body. When a body holds several markers the last one wins.\n\n```go\nfunc PostComment(ctx context.Context, r Runner, c CommentRequest) error\n```\nPostComment 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).\n\n```go\nfunc ReplyToComment(ctx context.Context, r Runner, slug string, number int, commentID int64, body string) error\n```\nReplyToComment posts a reply into the thread rooted at commentID.\n\n```go\nfunc ResolveThread(ctx context.Context, r Runner, nodeID string) error\n```\nResolveThread marks a review thread resolved.\n\n```go\nfunc ReviewedMarker(oid string) string\n```\nReviewedMarker returns the hidden marker recording that a review covered the PR up to head commit oid.\n\n```go\nfunc SubmitReview(ctx context.Context, r Runner, id, repo string, v Verdict, body string) error\n```\nSubmitReview submits the review-level verdict via \\`gh pr review\\`.\n\n```go\nfunc UnresolveThread(ctx context.Context, r Runner, nodeID string) error\n```\nUnresolveThread reopens a resolved review thread.\n\n```go\nfunc UpdateComment(ctx context.Context, r Runner, slug string, commentID int64, body string) error\n```\nUpdateComment replaces the body of one review comment (REST PATCH).\n\n```go\nfunc ValidFingerprint(fp string) bool\n```\nValidFingerprint reports whether fp is a 64-char lowercase hex digest, the only shape the identity marker accepts.\n\n```go\nfunc Whoami(ctx context.Context, r Runner) (string, error)\n```\nWhoami returns the authenticated GitHub login (\\`gh api user -q .login\\`).\n\n```go\nfunc WithReviewedMarker(body, oid string) string\n```\nWithReviewedMarker appends the K8 marker for oid to a review body. An empty oid leaves the body unchanged.\n\n## Types\n\n```go\ntype Class int\n```\nClass is how a thread CommitBrief owns is currently classified (S1-S9).\n\n```go\nconst (\n\t// ClassActive is an open thread CommitBrief manages (S1).\n\tClassActive Class = iota\n\t// ClassHeld is an open thread a human reopened or marked to keep (S2-S5).\n\tClassHeld\n\t// ClassClosedByUs is a thread CommitBrief resolved and nobody touched since (S6).\n\tClassClosedByUs\n\t// ClassClosedByHuman is a closed thread a human decided on (S7-S9).\n\tClassClosedByHuman\n)\n```\n\n```go\nfunc Classify(t Thread, m Marker) (c Class, record string)\n```\nClassify applies the S1-S9 table to one thread. record is the state the run should write into the root marker (\"reopened\" for S2, \"closed\" for S7/S8) or \"\" when nothing is to be recorded.\n\n```go\ntype Comment struct {\n\tID              int64\n\tBody            string\n\tViewerDidAuthor bool\n\tViewerCanUpdate bool\n}\n```\nComment is one review comment as the sync layer sees it.\n\n```go\ntype CommentRequest struct {\n\tRepoSlug string\n\tPRNumber int\n\tCommitID string\n\tPath     string\n\tLine     int\n\tSide     string\n\tBody     string\n}\n```\nCommentRequest 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.\n\n```go\ntype Compare struct {\n\tStatus       string          `json:\"status\"`\n\tTotalCommits int             `json:\"total_commits\"`\n\tCommits      []CompareCommit `json:\"commits\"`\n}\n```\nCompare is the part of GET /repos/{o}/{r}/compare/{base}...{head} that the incremental review needs.\n\n```go\nfunc FetchCompare(ctx context.Context, r Runner, slug, base, head string) (Compare, error)\n```\nFetchCompare compares two commits through the REST API. The commit list is paginated by GitHub, so every page is read and merged.\n\n```go\nfunc (c Compare) Ahead() bool\n```\nAhead reports whether head is strictly ahead of base, i.e. base is an ancestor of head (no force-push in between).\n\n```go\nfunc (c Compare) Complete() bool\n```\nComplete reports whether Commits lists every compared commit. The API caps the list; an incomplete one cannot prove the absence of merge commits.\n\n```go\nfunc (c Compare) HasMerge() bool\n```\nHasMerge reports whether any compared commit is a merge commit.\n\n```go\ntype CompareCommit struct {\n\tSHA     string `json:\"sha\"`\n\tParents []struct {\n\t\tSHA string `json:\"sha\"`\n\t} `json:\"parents\"`\n}\n```\nCompareCommit is one commit of a comparison; Parents has more than one entry for a merge commit.\n\n```go\ntype Group struct {\n\tFP       string\n\tRep      render.Finding\n\tMembers  []render.Finding\n\tSeverity render.Severity\n\tSide     string\n\tAnchored bool\n\tText     string\n}\n```\nGroup is every finding that shares one fingerprint, folded into a single comment. Rep is the finding the comment is anchored on (lowest anchorable line); Text is the rendered comment without the identity marker. A group with an empty FP is unmanaged: it never matches a thread and is always posted fresh, like before comment sync existed.\n\n```go\ntype Marker struct {\n\tFP    string\n\tAttrs []string\n}\n```\nMarker is a parsed identity marker. Attrs holds every attribute token other than \\`v=1\\`, in document order — unknown keys and values included — so a rewrite preserves what it does not understand.\n\n```go\nfunc NewMarker(fp string) Marker\n```\nNewMarker returns a marker with no attributes (a thread CommitBrief manages and has not closed).\n\n```go\nfunc SplitMarker(body string) (text string, m Marker, ok bool)\n```\nSplitMarker separates a comment body into its text and identity marker. ok is false when the body carries no valid v=1 marker. text is normalized for comparison (CRLF -\u003e LF, trailing whitespace trimmed).\n\n```go\nfunc (m Marker) Last() int64\n```\nLast is the \\`last=\\` comment id; 0 when absent or malformed.\n\n```go\nfunc (m Marker) State() string\n```\nState is the \\`state=\\` value, \"\" when absent.\n\n```go\nfunc (m Marker) String() string\n```\nString renders the marker exactly as it is stored in a comment body.\n\n```go\nfunc (m Marker) WithState(state string, last int64) Marker\n```\nWithState returns a copy with \\`state\\` (and \\`last\\`, when non-zero) replaced. An empty state removes both. Every other attribute is kept as is, in order. These are the only two keys CommitBrief ever rewrites.\n\n```go\ntype PRMeta struct {\n\tNumber         int      `json:\"number\"`\n\tAuthor         owner    `json:\"author\"`\n\tURL            string   `json:\"url\"`\n\tHeadRepository repoRef  `json:\"headRepository\"`\n\tCommits        []commit `json:\"commits\"`\n}\n```\nPRMeta is the subset of \\`gh pr view --json ...\\` that remote pr consumes.\n\nNote: 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.\n\n```go\nfunc FetchPRMeta(ctx context.Context, r Runner, id, repo string) (PRMeta, error)\n```\nFetchPRMeta runs \\`gh pr view \\\u003cid\u003e --json number,author,url,headRepository,commits\\`.\n\n```go\nfunc (m PRMeta) AuthorLogin() string\n```\nAuthorLogin returns the PR author's GitHub login.\n\n```go\nfunc (m PRMeta) BaseSlug() string\n```\nBaseSlug returns the base repository as \"owner/name\", parsed from the PR URL (https://\\\u003chost\u003e/\\\u003cowner\u003e/\\\u003crepo\u003e/pull/\\\u003cn\u003e). 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.\n\n```go\nfunc (m PRMeta) LastOID() string\n```\nLastOID returns the head commit OID, or \"\" when the PR has no commits.\n\n```go\ntype Result struct {\n\tPosted     int\n\tPostFailed int\n\tUpdated    int\n\tUnchanged  int\n\tResolved   int\n\tReplied    int\n\tHeld       int\n\t// StaleOpen counts duplicate (non-canonical) threads that could not be\n\t// resolved and were left open.\n\tStaleOpen int\n\t// StaleReason says why the duplicates stayed open: \"permission\" when the\n\t// viewer may not resolve (or record), otherwise the first API error.\n\tStaleReason string\n\t// Unanchored are findings that could not be given an inline comment and\n\t// must be listed in the review body instead.\n\tUnanchored []render.Finding\n\tWarnings   []Warning\n\t// OpenOurs counts CommitBrief threads that were already on the PR and are\n\t// still open once the sync is done: untouched, held and out-of-scope\n\t// ones, and threads left open by a failed resolve. Comments this run\n\t// posted are not counted: the verdict already weighs the findings they\n\t// carry. An incremental verdict that approves must not ignore OpenOurs\n\t// (ADR-0046 §A.7b).\n\tOpenOurs int\n}\n```\nResult is the outcome of one Sync run.\n\n```go\nfunc Sync(ctx context.Context, p SyncParams) Result\n```\nSync reconciles the PR's CommitBrief review threads with the current findings (ADR-0046). The decision logic is pure over the thread snapshot; all GitHub writes go through the small helpers in threads.go/comment.go.\n\n```go\ntype Runner interface {\n\tRun(ctx context.Context, args ...string) ([]byte, error)\n}\n```\nRunner 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).\n\n```go\nfunc NewRunner() Runner\n```\nNewRunner returns the production Runner backed by the \\`gh\\` binary.\n\n```go\ntype SyncParams struct {\n\tRunner   Runner\n\tSlug     string\n\tPRNumber int\n\tCommitID string\n\tThreads  []Thread\n\tGroups   []Group\n\tSelect   func([]render.Finding) []render.Finding\n\t// InScope reports whether a thread's file was part of this run's review.\n\t// A nil InScope means the whole PR was reviewed. Threads outside the\n\t// scope are never touched: a narrowed run (--file/--dir/--exclude-*) says\n\t// nothing about files it did not look at (ADR-0046 §Update 2026-10-18).\n\tInScope func(path string) bool\n\t// Incremental marks a --since-last-review run: only the delta since the\n\t// last review was re-reviewed, so a finding missing from Groups proves\n\t// nothing about code outside that delta. In that mode a thread whose\n\t// finding is gone is resolved only when it is active, outdated and its\n\t// file is in InDiff (ADR-0046 §A.7b); every other thread is left alone.\n\tIncremental bool\n\t// InDiff reports whether a file is part of the incremental diff. It is\n\t// consulted only when Incremental is set; nil then means no file is.\n\tInDiff func(path string) bool\n}\n```\nSyncParams is the input of Sync. Select applies the loop cap (ADR-0016 §6) to the findings that need a brand-new inline comment.\n\n```go\ntype Thread struct {\n\tNodeID       string\n\tPath         string\n\tResolved     bool\n\tOutdated     bool\n\tCanResolve   bool\n\tCanUnresolve bool\n\tCanReply     bool\n\tRoot         Comment\n\tRecent       []Comment\n}\n```\nThread is a review thread snapshot (GraphQL \\`reviewThreads\\`). Root is the first comment (it carries the identity marker); Recent is the tail of the thread, oldest first, so its last element is the thread's latest comment.\n\n```go\nfunc FetchThreads(ctx context.Context, r Runner, slug string, number int) ([]Thread, error)\n```\nFetchThreads reads every review thread of a PR through GraphQL. \\`gh api graphql --paginate\\` emits one JSON document per page, back to back, so the output is decoded as a stream. Empty output is an empty snapshot.\n\n```go\nfunc (t Thread) LastID() int64\n```\nLastID is the database id of the thread's most recent comment.\n\n```go\ntype Verdict int\n```\nVerdict is the review-level action submitted to GitHub.\n\n```go\nconst (\n\t// VerdictApprove — no findings reached the request-changes threshold.\n\tVerdictApprove Verdict = iota\n\t// VerdictComment — findings exist but none reached the threshold.\n\tVerdictComment\n\t// VerdictRequestChanges — at least one finding reached the threshold.\n\tVerdictRequestChanges\n)\n```\n\n```go\ntype Warning struct {\n\tOp  string\n\tRef string\n\tErr error\n}\n```\nWarning is a non-fatal problem met while syncing. Err is nil when the operation was skipped for lack of permission.\n\n","path":"github.com/CommitBrief/commitbrief/internal/remote","name":"remote","synopsis":"Package remote drives GitHub operations (currently PR review) through the user's `gh` CLI.","isRedistributable":true}
