50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { type } from "arktype";
|
|
import type { ToolContext } from "./server.ts";
|
|
import { execute, tool } from "./shared.ts";
|
|
|
|
export const PullRequestInfo = type({
|
|
pull_number: type.number.describe("The pull request number to fetch"),
|
|
});
|
|
|
|
export function PullRequestInfoTool(ctx: ToolContext) {
|
|
return tool({
|
|
name: "get_pull_request",
|
|
description:
|
|
"Retrieve PR metadata (title, body, state, branches, author, labels). " +
|
|
"Example: `get_pull_request({ pull_number: 1234 })`. " +
|
|
"To checkout a PR branch locally, use checkout_pr instead.",
|
|
parameters: PullRequestInfo,
|
|
execute: execute(async ({ pull_number }) => {
|
|
const result = await ctx.gitea.rest.repository.repoGetPullRequest({
|
|
owner: ctx.repo.owner,
|
|
repo: ctx.repo.name,
|
|
index: pull_number,
|
|
});
|
|
const data = result.data;
|
|
const isFork = data.head?.repo?.full_name !== data.base?.repo?.full_name;
|
|
|
|
return {
|
|
number: data.number,
|
|
url: data.html_url,
|
|
title: data.title,
|
|
body: data.body,
|
|
state: data.state,
|
|
draft: data.draft,
|
|
merged: data.merged,
|
|
maintainerCanModify: data.allow_maintainer_edit,
|
|
base: data.base?.label,
|
|
head: data.head?.label,
|
|
isFork,
|
|
author: data.user?.login,
|
|
assignees: data.assignees
|
|
?.map((a) => a.login)
|
|
.filter((n): n is string => n !== undefined),
|
|
labels: data.labels
|
|
?.map((l) => (typeof l === "string" ? l : l.name))
|
|
.filter((n): n is string => n !== undefined),
|
|
closingIssues: [],
|
|
};
|
|
}),
|
|
});
|
|
}
|