37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { type } from "arktype";
|
|
import type { ToolContext } from "./server.ts";
|
|
import { execute, tool } from "./shared.ts";
|
|
|
|
export const GetIssueComments = type({
|
|
issue_number: type.number.describe("The issue number to get comments for"),
|
|
});
|
|
|
|
export function GetIssueCommentsTool(ctx: ToolContext) {
|
|
return tool({
|
|
name: "get_issue_comments",
|
|
description:
|
|
"Get all comments for a Gitea issue or PR. " +
|
|
"Example: `get_issue_comments({ issue_number: 1234 })`.",
|
|
parameters: GetIssueComments,
|
|
execute: execute(async ({ issue_number }) => {
|
|
ctx.toolState.issueNumber = issue_number;
|
|
|
|
const comments = await ctx.gitea.paginate(ctx.gitea.rest.issue.issueGetComments, {
|
|
owner: ctx.repo.owner,
|
|
repo: ctx.repo.name,
|
|
index: issue_number,
|
|
});
|
|
|
|
return {
|
|
issue_number,
|
|
comments: comments.map((c) => ({
|
|
id: c.id,
|
|
body: c.body,
|
|
user: c.user?.login,
|
|
})),
|
|
count: comments.length,
|
|
};
|
|
}),
|
|
});
|
|
}
|