Review threads
Calls
const pull = { owner: "owner", repo: "repo", number: 1234 };
const threads = await forge.threads.list(pull, { state: "unresolved", perPage: 20 });
const thread = await forge.threads.get(pull, { threadId: threads.items[0]!.id });
await forge.threads.reply(pull, { threadId: thread.id, body: "Fixed in the next push." });
await forge.threads.resolve(pull, { threadId: thread.id });
await forge.threads.unresolve(pull, { threadId: thread.id });
const [first] = thread.comments;
await forge.threads.updateComment(pull, {
threadId: thread.id,
commentId: first!.id,
body: "Fixed.",
});
await forge.threads.deleteComment(pull, { threadId: thread.id, commentId: first!.id });
ListThreadOptions is cursor, perPage and state, and state is unresolved, resolved or all.
The shape
interface Thread {
id: string; // opaque; pass it back unchanged
isResolved: boolean;
isOutdated: boolean;
path: string;
line: number | null;
startLine: number | null;
comments: {
id: string;
body: string;
author: { login: string };
url: string;
createdAt: string;
}[];
}
What each platform means by a thread
| Platform | Source | isResolved | isOutdated |
|---|---|---|---|
| GitHub | GraphQL review threads | real | real |
| GitLab | REST merge request discussions | real | always false |
| Gitea, Forgejo | review comments | real | always false |
| GitBucket | nothing | unsupported | unsupported |
GitHub's REST API has no resolved flag at all, so list, get and resolve go through GraphQL. A reply still goes through the REST endpoint for comment replies. That is also why GitHub threads need a token: GraphQL has no anonymous access, full stop.
GitLab answers 401 for discussions without a token, even on a public project. With one, each discussion is a thread. There is no outdated flag in the API, so the field is false and stays false.
Gitea has no parent id on review comments, so every review comment is its own thread with one comment. A reply creates a new review comment on the same line and shows up as another thread. Not pretty, but honest about what the API has.
GitBucket serves REST v3 only. Thread calls against it fail with an explicit unsupported endpoint error rather than a bare 404 you would spend an hour on.
Writes
reply, resolve and unresolve need a credential. Resolving an already resolved thread changes nothing. Replying twice leaves two replies. The agent tools advertise exactly that, so a client can retry one and not the other.
threads.updateComment edits a thread comment, and threads.deleteComment removes one. Both check the thread first and raise NotFoundError if the comment isn't in it.
Gitea before 1.25 can answer 204 to a review comment delete and keep the comment, which is quite the disappearing act. The library reads it back and raises ForgesError with status 501 if it remains. That's better than a quiet success.
resolve and unresolve hand back the whole thread. Their agent tools don't. A resolve flips one flag and every comment stays as it was. Why read the whole review twice? forges_threads_resolve answers with the state and a commentCount, and forges_threads_get still reads the comments.