initial version of pr review tools

This commit is contained in:
David Blass
2025-10-30 10:52:01 -04:00
parent 2042a5bf98
commit 05fb2065b2
4 changed files with 84 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
create a PR implementing bogosort to https://github.com/pullfrogai/scratch/
add a github review for the following PR: https://github.com/pullfrogai/scratch/pull/14
+34
View File
@@ -0,0 +1,34 @@
import { type } from "arktype";
import { contextualize, tool } from "./shared.ts";
export const PullRequestInfo = type({
pull_number: type.number.describe("The pull request number to fetch"),
});
export const PullRequestInfoTool = tool({
name: "get_pull_request",
description: "Retrieve detailed information and diff for a specific pull request by number.",
parameters: PullRequestInfo,
execute: contextualize(async ({ pull_number }, ctx) => {
const pr = await ctx.octokit.rest.pulls.get({
owner: ctx.owner,
repo: ctx.name,
pull_number,
});
// Fetch diff using raw request
const diff = await ctx.octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: ctx.owner,
repo: ctx.name,
pull_number,
headers: {
Accept: 'application/vnd.github.v3.diff',
},
});
return {
...pr.data,
diff: diff.data,
};
}),
});
+46
View File
@@ -0,0 +1,46 @@
import { type } from "arktype";
import { contextualize, tool } from "./shared.ts";
import type { RestEndpointMethodTypes } from "@octokit/rest";
export const Review = type({
pull_number: type.number.describe("The pull request number to review"),
event: type.enumerated("APPROVE", "REQUEST_CHANGES", "COMMENT").describe("'APPROVE', 'REQUEST_CHANGES', or 'COMMENT' (the review action)"),
body: type.string.describe("The body content for the review (required for REQUEST_CHANGES or COMMENT)").optional(),
commit_id: type.string.describe("Optional SHA of the commit being reviewed. Defaults to latest.").optional(),
comments: type
({
path: type.string.describe("The file path to comment on"),
position: type.number.describe("The diff position in the file"),
body: type.string.describe("The comment text"),
})
.array()
.describe("Array of draft review comments for specific lines, optional.")
.optional()
});
export const ReviewTool = tool({
name: "submit_pull_request_review",
description: "Submit a review (approve, request changes, or comment) for an existing pull request.",
parameters: Review,
execute: contextualize(async ({ pull_number, event, body, commit_id, comments = [] }, ctx) => {
// Compose the request
const params: RestEndpointMethodTypes["pulls"]["createReview"]["parameters"] = {
owner: ctx.owner,
repo: ctx.name,
pull_number,
event,
};
if (body) params.body = body;
if (commit_id) params.commit_id = commit_id;
if (comments.length > 0) params.comments = comments;
const result = await ctx.octokit.rest.pulls.createReview(params);
return {
success: true,
reviewId: result.data.id,
html_url: result.data.html_url,
state: result.data.state,
user: result.data.user?.login,
submitted_at: result.data.submitted_at,
};
}),
});
+3 -1
View File
@@ -4,6 +4,8 @@ import { FastMCP } from "fastmcp";
import { CommentTool } from "./comment.ts";
import { IssueTool } from "./issue.ts";
import { PullRequestTool } from "./pr.ts";
import { ReviewTool } from "./review.ts";
import { PullRequestInfoTool } from "./prInfo.ts";
import { addTools } from "./shared.ts";
const server = new FastMCP({
@@ -11,6 +13,6 @@ const server = new FastMCP({
version: "0.0.1",
});
addTools(server, [CommentTool, IssueTool, PullRequestTool]);
addTools(server, [CommentTool, IssueTool, PullRequestTool, ReviewTool, PullRequestInfoTool]);
server.start();