1

On the Github web UI, I can click on a line and say something like:

Good architecture, but please pass the std::vector<std::uint8_t> hugedata as const &, to avoid a copy.

and bundle such comments as one review with a final verdict.

So far, I've only found gh pr review, which only allows me to generally approve/comment/reject a PR that I'm reviewing.

  • Is there a way to do detailed in-code reviews using the gh CLI?
  • if not, how can I use the github api to do that myself?
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Rest api supports this directly (https://docs.github.com/en/rest/pulls/reviews): note, that json comment object has fields for "target path" as well as "target line range", apart from the obvious "body". `gh` tool may not implement it just yet, but it is definitely doable with some cli flags or body markdown tags (`gh` is calling the same rest api). – oakad Jul 10 '22 at 09:53

1 Answers1

3

gh doesn't seem to have built in support for this, but you can still use gh api to call the API:

  1. Note the repository owner, repository name, and pull request ID
  2. Get a diff of the pull request so you can get the right files and positions
gh api -H "Accept: application/vnd.github.v3.diff" /repos/OWNER/REPO/pulls/ID
  1. Note any files you want to comment on after +++
  2. Note any positions you want to comment on after @@ (by number of lines after that line)
  3. Create a pull request review with your comments (using the file as path, the line offset from the start of the hunk as position, and your commend as body)
echo '{ "comments": [{"path": ...,"position": ...,"body": ...}, ...] }' |
  gh api -X POST /repos/OWNER/REPO/pulls/ID/reviews
  1. Submit the pull request review on GitHub (alternatively if you want to automate this, add the body and event properties to your review's body)
Nick McCurdy
  • 17,658
  • 5
  • 50
  • 82
  • 1
    My `gh api` (current from .. sigh .. brew) does not support `-d`, but piping into `gh api --method=POST ` seems to work (`echo '' | gh api <...>`). – Felix Jun 13 '23 at 20:02
  • 1
    (the `-d` might be a copy/pasty from using cURL) – Felix Jun 13 '23 at 20:47
  • I'm not sure where I got `-d`, but it's not working with the latest version (2.30.0), so I've edited this to include a pipe. – Nick McCurdy Jun 14 '23 at 02:45
  • Did you try that the pipe works? I might be mistaken. One thing works consistently here: specifying the payload in a file (and pass `--input`). – Felix Jun 14 '23 at 06:25