Skip to content

feat(review): post the notes to the pull request on GitHub (ctrl+g), after a summary - #179

Open
backnotprop wants to merge 18 commits into
mainfrom
feat/post-to-github
Open

backnotprop wants to merge 18 commits into
mainfrom
feat/post-to-github

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Tested on real GitHub, in a private scratch repository made for it and deleted after. The real binary, in a private tmux, posted 8 reviews (19 inline comments) to a scratch PR with a real gh login, and each result was checked with gh api .../pulls/N/reviews and .../comments. GitHub took the payload as built: line, side and start_line/start_side came back exactly as sent for new lines, removed lines, ranges over changed and context lines, a renamed file (both sides), a deleted file, a new file, single and multi-line suggestions (rendered as applicable suggestions), unicode, markdown, backticks and a 5,171-character note. Also checked for real: the review body (whole-change, file and outside-the-diff notes, with a permalink that resolves at the reviewed commit), a second post skipping posted notes and re-posting edited ones, a post after the PR moved on (GitHub keeps the comments on the reviewed commit and marks them outdated), the outdated body shape after a reload, Approve and Request changes on one's own PR (GitHub's 422 is named, nothing is posted or marked posted), a closed and a merged PR (GitHub takes a Comment review on both), and a lost login (named, nothing lost, Enter again posts once it is back). Not tested for real: a successful Approve or Request changes (one account, so only one's own PR), a permission error, a rate limit, no network, and GitHub Enterprise (--hostname).

The real test found three problems, fixed here: a suggestion whose code has a line of three backticks (Markdown) broke out of its suggestion block, so GitHub offered a change that drops a line (now fenced past the code's backticks, checked again on GitHub); notes drawn in the diff (the new inline boxes) never said they were posted; and the summary did not say when the PR is closed or merged. The error tests now use GitHub's real words. The later fixes from an independent review (Enter only after the summary is drawn, gh off the screen's thread with timeouts, "may have been posted" outcomes, length checks, a pinned PR diff context, plain comments for old-line suggestions, posted marks kept when saving fails) were tested with the fake gh and unit tests only, not on real GitHub.

What it does

In a pull request review (plannotator-tui review <PR>), ctrl+g or Post to GitHub… in the Review menu (m) posts the notes to the PR as one GitHub review. This is in addition to sending them to the agent, not instead of it. In any other review, the key and the menu row say that the feature needs a pull request review.

A summary always opens first. It shows:

  • the repository and PR number;
  • how many notes become inline comments;
  • how many go into the review body, and why: whole-change notes, file notes, notes outside the diff, and line notes that are outdated or no longer in the diff;
  • what is skipped: already posted, or empty;
  • how many edited notes are posted again as new comments;
  • the verdict.

The verdict is Comment by default. Approve and Request changes are explicit choices with h/l, because the browser app offers them too. Enter posts and Esc cancels. There is no way to skip the summary, and Enter counts only once the summary has been drawn with the PR checked: keys typed before it appeared are dropped, so a fast ctrl+g Enter or a double Enter in the menu posts nothing.

Payload (matches the browser's ReviewSubmissionDialog.tsx)

It is one request: gh api --method POST repos/OWNER/REPO/pulls/N/reviews --input -, with {commit_id, body, event, comments[]} on stdin. Inline comments use line, side, and start_line/start_side (only for a range), never position.

  • Inline comments: line notes that GitHub can place at the reviewed commit. Old lines get LEFT and new lines get RIGHT. A suggestion becomes a ```suggestion block, fenced past any backticks in its code. A suggestion on old lines (browser or Pi) goes as a plain comment with the code quoted, since GitHub cannot apply it; the summary counts those. A browser-written note keeps its conventional-comment prefix.
  • Review body, in note order:
    • whole-change notes, as plain text;
    • file notes, as **path:** text;
    • outdated or no-longer-in-diff line notes, as **path (L5-L9, side):** with an "Outdated" label and a "Commented on" code block. This is the browser's withheld/outdated shape.
    • notes outside the diff, under Comments outside the diff, with the code quoted (40 lines at most, fenced past any backticks in it) and a permalink to the reviewed commit.
  • Empty body: if the body is empty but there are inline comments, it becomes See inline comments. An approval needs no placeholder.
  • Difference from the browser: on GitHub, the browser posts file notes as file-level threads. That takes a pending review, GraphQL calls and a submit, so it is not atomic. Here file notes go in the body, in the browser's own fallback shape. This keeps a post to one atomic request.

Commit and errors

  • Which commit: comments are anchored to the head commit the diff was captured at, which is the commit the person reviewed. The PR diff is made with -U3 --inter-hunk-context=0 so its hunks are GitHub's whatever the person's diff.context says. While the summary is open, a read-only gh pr view checks the PR's head. If the PR has moved on, the summary warns about it and points to r to reload; it also says when the PR is closed or merged.
  • Off the screen's thread: the check and the post run on threads of their own and wake the event loop, as go to definition does; the summary says "Checking the PR on GitHub…" and then "Posting to GitHub…". gh is killed after 20 s (check) or 60 s (post).
  • Length: a note over GitHub's 65,536 characters, or a review body over it, is named in the summary before Enter (for the body, by which kind of notes fill it), and Enter refuses to post.
  • Refusals are named in the summary, which stays open. Nothing is posted, because GitHub creates the review whole or not at all. The named cases are:
    • gh missing or not logged in;
    • no permission;
    • rate limit;
    • offline;
    • the reviewed commit was force-pushed away;
    • approving your own PR;
    • GitHub refusing a comment's position.
  • Unknown outcome: a timeout, a connection lost mid-request, a 5xx, or any failure that is not a clear refusal (an HTTP 4xx, no login, a connection never made) says the review may have been posted and to check the PR before posting again. Nothing is marked posted.
  • Position errors: for these, the message also lists where each inline comment was. Each one was already checked against the reviewed diff before posting. GitHub's error does not say which comment it refused.

Posted state

A note is "posted" once a post covers it at or after its last edit. This works like deliveries, and it is a separate state from "sent": a note can be both. The state is saved in review.json as posted: [{at, url, commitId, annotationIds}].

A later post carries only notes that are new or edited since. Edited notes are posted again as new comments, and the summary says so. After a post, the footer shows the review's link, and the rail and the notes drawn in the diff mark notes posted. If saving the posted state fails, the marks stay in memory for the session (so it does not post them twice) and the footer says a later session may repeat them. If a bubble's title has no room, its sent/posted marks move into the bubble's body.

Key

ctrl+g (post-to-github, rebindable) is free in every code-review context. leaf uses the same key for this.

Tests

  • Unit tests (plannotator-tui-review/src/post/tests.rs) cover: one line, range, both sides, suggestion, file note, whole-change note, outside-diff (quoting, cap, fence, permalink), outdated and off-diff notes, already-posted and edited filtering, the reviewed commit when the PR moved on, empty notes, placeholder per event, the conventional prefix, and gh error classification. A store test covers the posted state across restarts and edits.
  • Flow tests (review/tests/post_flow.rs) use the fake gh from the existing PR tests. They cover:
    • the summary, then exactly one request, only after Enter;
    • Esc posts nothing;
    • a second post carries only new and edited notes;
    • a 422 position error posts nothing and names the comments;
    • auth, permission, rate-limit and offline errors;
    • a moved PR head (warning shown, commit_id stays on the reviewed commit);
    • the menu row, and the explanation outside a PR;
    • the rail when a note is both sent and posted.

Manual run

On real GitHub: see the first paragraph. Before that, I ran the real binary in a private tmux with a scratch HOME and data folder, the fake gh and a local bare repository. The summary, the footer after posting, and the rail's posted marks looked right, and the JSON the fake gh received was the expected one.

Not verified

  • a successful Approve or Request changes (GitHub refuses both on one's own PR, and there was one account);
  • GitHub's real wording for a permission error, a rate limit and no network (those are still based on known messages);
  • gh behaviour on GitHub Enterprise hosts (--hostname);
  • a range across hunks from this app: the diff keeps a selection inside one hunk, and such a note goes in the body. (Sent by hand, GitHub accepted one.)

backnotprop and others added 18 commits November 20, 2026 00:07
# Conflicts:
#	README.md
#	crates/plannotator-tui/src/keys.rs
#	crates/plannotator-tui/src/review/draw.rs
#	crates/plannotator-tui/src/review/input.rs
#	crates/plannotator-tui/src/review/mod.rs
#	crates/plannotator-tui/src/review/overlays.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant