Get reviews with comments

This commit is contained in:
Colin McDonnell
2025-12-15 21:37:46 -08:00
parent 316b6cb83c
commit b038fc574f
4 changed files with 251 additions and 47 deletions
+89 -22
View File
@@ -97449,7 +97449,7 @@ function query({
// package.json
var package_default = {
name: "@pullfrog/action",
version: "0.0.138",
version: "0.0.139",
type: "module",
files: [
"index.js",
@@ -124848,41 +124848,108 @@ var ReviewTool = tool({
// mcp/reviewComments.ts
init_out4();
init_shared3();
var REVIEW_THREADS_QUERY = `
query ($owner: String!, $repo: String!, $pullNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pullNumber) {
reviewThreads(first: 100) {
nodes {
comments(first: 100) {
nodes {
id
databaseId
body
path
line
startLine
diffSide
startSide
url
author {
login
}
createdAt
updatedAt
pullRequestReview {
databaseId
}
replyTo {
databaseId
}
}
}
}
}
}
}
}
`;
var GetReviewComments = type({
pull_number: type.number.describe("The pull request number"),
review_id: type.number.describe("The review ID to get comments for")
});
var GetReviewCommentsTool = tool({
name: "get_review_comments",
description: "Get all review comments for a specific pull request review. Returns line-by-line comments that were left on specific code locations.",
description: "Get all review comments and their replies for a specific pull request review. Returns line-by-line comments that were left on specific code locations, including any threaded replies.",
parameters: GetReviewComments,
execute: contextualize(async ({ pull_number, review_id }, ctx) => {
const comments = await ctx.octokit.paginate(ctx.octokit.rest.pulls.listCommentsForReview, {
const response = await ctx.octokit.graphql(REVIEW_THREADS_QUERY, {
owner: ctx.owner,
repo: ctx.name,
pull_number,
review_id
pullNumber: pull_number
});
const pullRequest = response.repository?.pullRequest;
if (!pullRequest) {
return {
review_id,
pull_number,
comments: [],
count: 0
};
}
const threadNodes = pullRequest.reviewThreads?.nodes;
if (!threadNodes) {
return {
review_id,
pull_number,
comments: [],
count: 0
};
}
const allComments = [];
for (const thread of threadNodes) {
if (!thread?.comments?.nodes) continue;
const threadComments = thread.comments.nodes.filter(
(c) => c !== null
);
if (threadComments.length === 0) continue;
const rootComment = threadComments.find((c) => c.replyTo === null);
if (!rootComment) continue;
const threadBelongsToReview = rootComment.pullRequestReview?.databaseId === review_id;
if (!threadBelongsToReview) continue;
for (const comment of threadComments) {
allComments.push({
id: comment.databaseId,
body: comment.body,
path: comment.path,
line: comment.line,
start_line: comment.startLine,
side: comment.diffSide,
start_side: comment.startSide,
user: comment.author?.login ?? null,
created_at: comment.createdAt,
updated_at: comment.updatedAt,
html_url: comment.url,
in_reply_to_id: comment.replyTo?.databaseId ?? null,
pull_request_review_id: comment.pullRequestReview?.databaseId ?? null
});
}
}
return {
review_id,
pull_number,
comments: comments.map((comment) => ({
id: comment.id,
body: comment.body,
path: comment.path,
line: comment.line,
side: comment.side,
start_line: comment.start_line,
start_side: comment.start_side,
user: typeof comment.user === "string" ? comment.user : comment.user?.login,
created_at: comment.created_at,
updated_at: comment.updated_at,
html_url: comment.html_url,
in_reply_to_id: comment.in_reply_to_id,
diff_hunk: comment.diff_hunk,
reactions: comment.reactions
})),
count: comments.length
comments: allComments,
count: allComments.length
};
})
});