fix: issues with pagination not resolving correct url templates

This commit is contained in:
2026-05-31 03:18:07 -05:00
parent 2aca1a3aa3
commit 0438688e32
14 changed files with 287 additions and 467 deletions
+14 -18
View File
@@ -3,6 +3,8 @@ import { log } from "../utils/cli.ts";
import type { ToolContext } from "./server.ts";
import { execute, tool } from "./shared.ts";
interface GiteaLabel { id: number; name?: string }
export const AddLabelsParams = type({
issue_number: type.number.describe("the issue or PR number to add labels to"),
labels: type.string.array().atLeastLength(1).describe("array of label names to add"),
@@ -11,15 +13,14 @@ export const AddLabelsParams = type({
export function AddLabelsTool(ctx: ToolContext) {
return tool({
name: "add_labels",
description:
"Add labels to a Gitea issue or pull request. Only use labels that already exist in the repository.",
description: "Add labels to a Gitea issue or pull request. Only use labels that already exist in the repository.",
parameters: AddLabelsParams,
execute: execute(async ({ issue_number, labels }) => {
// Resolve label names to IDs (Gitea uses IDs, not names)
const allLabels = await ctx.gitea.paginate(ctx.gitea.rest.issue.issueListLabels, {
owner: ctx.repo.owner,
repo: ctx.repo.name,
});
const allLabelsR = await ctx.gitea.request(
"GET /repos/{owner}/{repo}/labels",
{ owner: ctx.repo.owner, repo: ctx.repo.name, limit: 50 }
);
const allLabels = allLabelsR.data as GiteaLabel[];
const labelIds = labels
.map((name) => allLabels.find((l) => l.name === name)?.id)
.filter((id): id is number => typeof id === "number");
@@ -28,18 +29,13 @@ export function AddLabelsTool(ctx: ToolContext) {
return { success: true, labels: [], message: "No matching labels found in repository" };
}
const result = await ctx.gitea.rest.issue.issueAddLabel({
owner: ctx.repo.owner,
repo: ctx.repo.name,
index: issue_number,
body: { labels: labelIds },
});
const r = await ctx.gitea.request(
"POST /repos/{owner}/{repo}/issues/{index}/labels",
{ owner: ctx.repo.owner, repo: ctx.repo.name, index: issue_number, labels: labelIds }
);
log.info(`» added labels [${labels.join(", ")}] to issue #${issue_number}`);
return {
success: true,
labels: result.data.map((label) => label.name).filter(Boolean),
};
const result = r.data as GiteaLabel[];
return { success: true, labels: result.map((l) => l.name).filter(Boolean) };
}),
});
}