fix: issues with pagination not resolving correct url templates
This commit is contained in:
+19
-30
@@ -2,6 +2,13 @@ import { type } from "arktype";
|
||||
import type { ToolContext } from "./server.ts";
|
||||
import { execute, tool } from "./shared.ts";
|
||||
|
||||
interface GiteaIssue {
|
||||
number: number; title: string; body?: string | null; state: string; html_url: string;
|
||||
user?: { login: string }; labels?: Array<{ name?: string }>; assignees?: Array<{ login: string }>;
|
||||
comments: number; created_at: string; updated_at: string; closed_at?: string | null;
|
||||
milestone?: { title: string } | null; pull_request?: { html_url?: string } | null;
|
||||
}
|
||||
|
||||
export const IssueInfo = type({
|
||||
issue_number: type.number.describe("The issue number to fetch"),
|
||||
});
|
||||
@@ -9,42 +16,24 @@ export const IssueInfo = type({
|
||||
export function IssueInfoTool(ctx: ToolContext) {
|
||||
return tool({
|
||||
name: "get_issue",
|
||||
description:
|
||||
"Retrieve Gitea issue information by issue number. " +
|
||||
"Example: `get_issue({ issue_number: 1234 })`.",
|
||||
description: "Retrieve Gitea issue information by issue number. Example: `get_issue({ issue_number: 1234 })`.",
|
||||
parameters: IssueInfo,
|
||||
execute: execute(async ({ issue_number }) => {
|
||||
const result = await ctx.gitea.rest.issue.issueGetIssue({
|
||||
owner: ctx.repo.owner,
|
||||
repo: ctx.repo.name,
|
||||
index: issue_number,
|
||||
});
|
||||
const data = result.data;
|
||||
const r = await ctx.gitea.request(
|
||||
"GET /repos/{owner}/{repo}/issues/{index}",
|
||||
{ owner: ctx.repo.owner, repo: ctx.repo.name, index: issue_number }
|
||||
);
|
||||
const data = r.data as GiteaIssue;
|
||||
ctx.toolState.issueNumber = issue_number;
|
||||
|
||||
const hints: string[] = [];
|
||||
if ((data.comments ?? 0) > 0) {
|
||||
hints.push("use get_issue_comments to retrieve all comments for this issue");
|
||||
}
|
||||
|
||||
if (data.comments > 0) hints.push("use get_issue_comments to retrieve all comments for this issue");
|
||||
return {
|
||||
number: data.number,
|
||||
url: data.html_url,
|
||||
title: data.title,
|
||||
body: data.body,
|
||||
number: data.number, url: data.html_url, title: data.title, body: data.body,
|
||||
state: data.state,
|
||||
labels: data.labels
|
||||
?.map((l) => (typeof l === "string" ? l : l.name))
|
||||
.filter((n): n is string => n !== undefined),
|
||||
assignees: data.assignees
|
||||
?.map((a) => a.login)
|
||||
.filter((n): n is string => n !== undefined),
|
||||
user: data.user?.login,
|
||||
created_at: data.created_at,
|
||||
updated_at: data.updated_at,
|
||||
closed_at: data.closed_at,
|
||||
comments: data.comments,
|
||||
milestone: data.milestone?.title,
|
||||
labels: data.labels?.map((l) => l.name).filter((n): n is string => n !== undefined),
|
||||
assignees: data.assignees?.map((a) => a.login).filter((n): n is string => n !== undefined),
|
||||
user: data.user?.login, created_at: data.created_at, updated_at: data.updated_at,
|
||||
closed_at: data.closed_at, comments: data.comments, milestone: data.milestone?.title,
|
||||
pull_request: data.pull_request ? { html_url: data.pull_request.html_url } : null,
|
||||
hints,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user