fix: issues with pagination not resolving correct url templates
This commit is contained in:
+19
-22
@@ -2,6 +2,15 @@ import { type } from "arktype";
|
||||
import type { ToolContext } from "./server.ts";
|
||||
import { execute, tool } from "./shared.ts";
|
||||
|
||||
interface GiteaPull {
|
||||
number: number; html_url: string; title: string; body?: string | null;
|
||||
state: string; draft?: boolean; merged?: boolean; allow_maintainer_edit?: boolean;
|
||||
head?: { sha: string; ref: string; repo?: { full_name: string } | null };
|
||||
base?: { ref: string; repo?: { full_name: string } };
|
||||
user?: { login: string }; assignees?: Array<{ login: string }>;
|
||||
labels?: Array<string | { name?: string }>;
|
||||
}
|
||||
|
||||
export const PullRequestInfo = type({
|
||||
pull_number: type.number.describe("The pull request number to fetch"),
|
||||
});
|
||||
@@ -11,34 +20,22 @@ export function PullRequestInfoTool(ctx: ToolContext) {
|
||||
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.",
|
||||
"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 r = await ctx.gitea.request(
|
||||
"GET /repos/{owner}/{repo}/pulls/{index}",
|
||||
{ owner: ctx.repo.owner, repo: ctx.repo.name, index: pull_number }
|
||||
);
|
||||
const data = r.data as GiteaPull;
|
||||
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,
|
||||
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,
|
||||
base: data.base?.ref, head: data.head?.ref, isFork,
|
||||
author: data.user?.login,
|
||||
assignees: data.assignees
|
||||
?.map((a) => a.login)
|
||||
.filter((n): n is string => n !== undefined),
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user