# Review comment threads

Line-anchored review comments on a pull request's diff, their replies and the refusal of a path the diff does not touch.

A review comment anchors to a line of a pull request's diff at its head sha, and a reply joins its thread through `in_reply_to_id`. Comment on the one file pull request #41 changes, reply as its author and ask for a file the diff does not touch:

```bash
H='Authorization: Bearer ghp_anything'
R="$RYSTIC_URL/repos/tb-owner/tb-repo"
sha=$(curl -s "$R/pulls/41" -H "$H" | jq -r .head.sha)
curl -s "$R/pulls/41/files" -H "$H" | jq -c '[.[].filename]'
# -> ["pkg/page/cursor.go"]
curl -s -X POST "$R/pulls/41/comments" -H "$H" -H 'X-Rystic-Actor: actor_b' -d "{\"body\":\"Should this be <= ?\",\"path\":\"pkg/page/cursor.go\",\"line\":12,\"side\":\"RIGHT\",\"commit_id\":\"$sha\"}" | jq -c '{id, path, line, side, user: .user.login}'
# -> {"id":8200001,"path":"pkg/page/cursor.go","line":12,"side":"RIGHT","user":"tb-reviewer-login"}
curl -s -X POST "$R/pulls/41/comments/8200001/replies" -H "$H" -H 'X-Rystic-Actor: tb-contributor' -d '{"body":"No: the cursor is exclusive."}' | jq -c '{in_reply_to_id, user: .user.login}'
# -> {"in_reply_to_id":8200001,"user":"tb-contributor"}
curl -s "$R/pulls/41/comments" -H "$H" | jq -c '[.[] | {in_reply_to_id, body}]'
# -> [{"in_reply_to_id":null,"body":"Should this be <= ?"},{"in_reply_to_id":8200001,"body":"No: the cursor is exclusive."}]
curl -s -X POST "$R/pulls/41/comments" -H "$H" -d "{\"body\":\"x\",\"path\":\"README.md\",\"line\":1,\"side\":\"RIGHT\",\"commit_id\":\"$sha\"}" | jq -c '{message, errors: [.errors[] | {field, message}]}'
# -> {"message":"Validation Failed","errors":[{"field":"path","message":"path is invalid"}]}
```

### Anchoring

A comment anchors through these fields:

- `path`, a file the pull request's diff touches. A `path` the diff does not touch returns `422` with `path is invalid`.
- `line`, the line it comments on. A comment with `subject_type: file` or a `position` can leave it out. One with none of the three returns `422` with `line is invalid`.
- `commit_id`, the commit it comments on.
- `side`, optional: `RIGHT` for the head (the default) or `LEFT` for the base.

### Replies

`POST .../comments/{comment_id}/replies` adds a comment to the thread of an existing top-level comment. The reply carries that comment's id as `in_reply_to_id`, and a reply to a reply returns `404`. `GET .../pulls/{pull_number}/comments` lists a pull request's review comments, replies included. [Issues, events and the timeline](https://www.rystic.ai/docs/simulators/github-pulls/features/issues-and-timeline.md) covers the conversation comments that sit beside them.

---

Source: https://www.rystic.ai/docs/simulators/github-pulls/features/review-comments · Markdown: https://www.rystic.ai/docs/simulators/github-pulls/features/review-comments.md
