feat: Add review submission tool with line-specific comments #67

Open
opened 2026-06-20 15:33:17 +00:00 by llm-bot · 1 comment
Member

Problem

The prompt builder (src/prompt.ts) references a submit-review tool for pull_request_review_requested events, but this tool does not exist. The agent can only create comments and PRs — it cannot formally submit a review (approve, request changes, or comment) through the Forgejo API.

This means the agent's review capability is limited to posting regular comments rather than structured reviews that affect the PR review state.

Proposed Solution

Add a submit-review tool that uses Forgejo's review API to submit formal PR reviews.

API Endpoint to Add (src/forgejo/index.ts)

  1. postReview(repo, prNumber, review) — Submit a review on a PR

    • POST /repos/{owner}/{repo}/pulls/{index}/reviews
    • Supports body, event (COMMENT/APPROVE/REQUEST_CHANGES), and line-specific comments
  2. postReviewComment(repo, prNumber, comment) — Post a single review comment

    • POST /repos/{owner}/{repo}/pulls/{index}/comments
  3. postReviewCommentThread(repo, prNumber, comments) — Post a threaded review comment

    • POST /repos/{owner}/{repo}/pulls/{index}/comments
    • For multi-turn comments on the same line
  4. patchReview(repo, reviewId, body) — Edit an existing review comment

    • PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id}
  5. getReviewComments(repo, prNumber) — Fetch existing review comments

    • GET /repos/{owner}/{repo}/pulls/{index}/comments

Tool to Add (src/tools.ts)

submit-review — Submit a formal review on a PR

Parameters:

{
  repository: string;        // owner/name
  prNumber: number;          // PR number
  event: "COMMENT" | "APPROVE" | "REQUEST_CHANGES";
  body?: string;             // General review comment body
  comments?: Array<{
    path: string;            // File path
    line: number;            // Line number (for line-specific comments)
    body: string;            // Comment text
  }>;
}

Behavior:

  • If event is "APPROVE" or "REQUEST_CHANGES" with no line-specific comments, posts a general review
  • If comments array is provided, posts line-specific review comments
  • Returns confirmation of the submitted review

Prompt Integration (src/prompt.ts)

Current prompt for review events:

You have been assigned as a reviewer of the pull request. Report any findings with the `submit-review` tool.

Enhanced prompt should include:

  • Guidance on when to use each event type (APPROVE vs REQUEST_CHANGES vs COMMENT)
  • How to reference specific lines and files in review comments
  • When to leave a general review vs line-specific feedback

Schema Updates (src/schemas.ts)

Add TypeBox schemas for:

  • reviewEventSchema — Union of "COMMENT", "APPROVE", "REQUEST_CHANGES"
  • reviewCommentSchema — Line-specific review comment
  • reviewResponseSchema — Response from posting a review
  • reviewCommentResponseSchema — Response from posting a review comment

Example Agent Workflow

  1. Agent reviews PR code
  2. Agent finds issues on specific lines → calls submit-review with REQUEST_CHANGES and line-specific comments
  3. Agent finds no issues → calls submit-review with APPROVE and a positive body
  4. Agent has suggestions but no blocking issues → calls submit-review with COMMENT

Files to Modify

File Changes
src/forgejo/fetch.ts No changes needed (already generic)
src/forgejo/index.ts Add 5 new API functions
src/schemas.ts Add schemas for review events, review comments, review responses
src/tools.ts Add 1 new tool (submit-review)
src/prompt.ts Enhance review event prompt with usage guidance
src/main.ts Register new tool in customTools array

Notes

  • Forgejo's review API follows the GitHub review API closely
  • The event field is case-sensitive: must be "COMMENT", "APPROVE", or "REQUEST_CHANGES"
  • Line-specific comments require both path and line parameters
  • The auth token must have repo scope to submit reviews
  • Consider adding side parameter for left/right side of diff (Forgejo may support this)
## Problem The prompt builder (`src/prompt.ts`) references a `submit-review` tool for `pull_request_review_requested` events, but this tool does not exist. The agent can only create comments and PRs — it cannot formally submit a review (approve, request changes, or comment) through the Forgejo API. This means the agent's review capability is limited to posting regular comments rather than structured reviews that affect the PR review state. ## Proposed Solution Add a `submit-review` tool that uses Forgejo's review API to submit formal PR reviews. ### API Endpoint to Add (`src/forgejo/index.ts`) 1. **`postReview(repo, prNumber, review)`** — Submit a review on a PR - `POST /repos/{owner}/{repo}/pulls/{index}/reviews` - Supports body, event (COMMENT/APPROVE/REQUEST_CHANGES), and line-specific comments 2. **`postReviewComment(repo, prNumber, comment)`** — Post a single review comment - `POST /repos/{owner}/{repo}/pulls/{index}/comments` 3. **`postReviewCommentThread(repo, prNumber, comments)`** — Post a threaded review comment - `POST /repos/{owner}/{repo}/pulls/{index}/comments` - For multi-turn comments on the same line 4. **`patchReview(repo, reviewId, body)`** — Edit an existing review comment - `PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id}` 5. **`getReviewComments(repo, prNumber)`** — Fetch existing review comments - `GET /repos/{owner}/{repo}/pulls/{index}/comments` ### Tool to Add (`src/tools.ts`) **`submit-review`** — Submit a formal review on a PR Parameters: ```typescript { repository: string; // owner/name prNumber: number; // PR number event: "COMMENT" | "APPROVE" | "REQUEST_CHANGES"; body?: string; // General review comment body comments?: Array<{ path: string; // File path line: number; // Line number (for line-specific comments) body: string; // Comment text }>; } ``` Behavior: - If `event` is `"APPROVE"` or `"REQUEST_CHANGES"` with no line-specific comments, posts a general review - If `comments` array is provided, posts line-specific review comments - Returns confirmation of the submitted review ### Prompt Integration (`src/prompt.ts`) Current prompt for review events: ``` You have been assigned as a reviewer of the pull request. Report any findings with the `submit-review` tool. ``` Enhanced prompt should include: - Guidance on when to use each event type (APPROVE vs REQUEST_CHANGES vs COMMENT) - How to reference specific lines and files in review comments - When to leave a general review vs line-specific feedback ### Schema Updates (`src/schemas.ts`) Add TypeBox schemas for: - `reviewEventSchema` — Union of "COMMENT", "APPROVE", "REQUEST_CHANGES" - `reviewCommentSchema` — Line-specific review comment - `reviewResponseSchema` — Response from posting a review - `reviewCommentResponseSchema` — Response from posting a review comment ### Example Agent Workflow 1. Agent reviews PR code 2. Agent finds issues on specific lines → calls `submit-review` with `REQUEST_CHANGES` and line-specific comments 3. Agent finds no issues → calls `submit-review` with `APPROVE` and a positive body 4. Agent has suggestions but no blocking issues → calls `submit-review` with `COMMENT` ### Files to Modify | File | Changes | |------|---------| | `src/forgejo/fetch.ts` | No changes needed (already generic) | | `src/forgejo/index.ts` | Add 5 new API functions | | `src/schemas.ts` | Add schemas for review events, review comments, review responses | | `src/tools.ts` | Add 1 new tool (`submit-review`) | | `src/prompt.ts` | Enhance review event prompt with usage guidance | | `src/main.ts` | Register new tool in `customTools` array | ### Notes - Forgejo's review API follows the GitHub review API closely - The `event` field is case-sensitive: must be `"COMMENT"`, `"APPROVE"`, or `"REQUEST_CHANGES"` - Line-specific comments require both `path` and `line` parameters - The auth token must have `repo` scope to submit reviews - Consider adding `side` parameter for left/right side of diff (Forgejo may support this)
Owner

Added the tool in the #99 PR, now it would be useful to give some more context in the prompt for successive review requests.

Added the tool in the #99 PR, now it would be useful to give some more context in the prompt for successive review requests.
Sign in to join this conversation.
No labels
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
projects/forgejo-agent#67
No description provided.