fix: issues with pagination not resolving correct url templates

This commit is contained in:
2026-05-31 01:43:42 -05:00
parent 2aca1a3aa3
commit 0438688e32
14 changed files with 287 additions and 467 deletions
+20 -29
View File
@@ -6,52 +6,43 @@ import { formatFilesWithLineNumbers, type DiffFile } from "./checkout.ts";
import type { ToolContext } from "./server.ts";
import { execute, tool } from "./shared.ts";
export const CommitInfo = type({
sha: type.string.describe("the commit SHA (full or abbreviated) to fetch"),
});
interface GiteaCommit {
sha?: string; html_url?: string; parents?: Array<{ sha?: string }>;
commit?: { message?: string; author?: { name?: string; date?: string }; committer?: { name?: string; date?: string } };
author?: { login?: string }; committer?: { login?: string };
stats?: { additions?: number; deletions?: number; total?: number };
files?: Array<{ filename?: string; status?: string; patch?: string }>;
}
export const CommitInfo = type({ sha: type.string.describe("the commit SHA to fetch") });
export function CommitInfoTool(ctx: ToolContext) {
return tool({
name: "get_commit_info",
description:
"Retrieve commit metadata and diff via Gitea API. Returns diffPath pointing to formatted diff file. " +
'Example: `get_commit_info({ sha: "2a6ab5d" })`.',
description: "Retrieve commit metadata and diff via Gitea API. Returns diffPath pointing to formatted diff file.",
parameters: CommitInfo,
execute: execute(async ({ sha }) => {
const result = await ctx.gitea.rest.repository.repoGetSingleCommit({
owner: ctx.repo.owner,
repo: ctx.repo.name,
sha,
});
const data = result.data;
// The SDK's CommitAffectedFiles type omits `patch`, which Gitea does return
// in practice. Cast explicitly so we can pass it to formatFilesWithLineNumbers.
const files: DiffFile[] = (data.files ?? []).map((f) => ({
filename: f.filename,
patch: (f as unknown as { patch?: string }).patch,
}));
const r = await ctx.gitea.request(
"GET /repos/{owner}/{repo}/git/commits/{sha}",
{ owner: ctx.repo.owner, repo: ctx.repo.name, sha }
);
const data = r.data as GiteaCommit;
const files: DiffFile[] = (data.files ?? []).map((f) => ({ filename: f.filename, patch: f.patch }));
const formatResult = formatFilesWithLineNumbers(files);
const tempDir = process.env.SHOCKBOT_TEMP_DIR;
if (!tempDir) {
throw new Error("SHOCKBOT_TEMP_DIR not set - get_commit_info must run in shockbot action context");
}
if (!tempDir) throw new Error("SHOCKBOT_TEMP_DIR not set");
const diffFile = join(tempDir, `commit-${sha.slice(0, 7)}.diff`);
writeFileSync(diffFile, formatResult.content);
log.debug(`wrote commit diff to ${diffFile} (${formatResult.content.length} bytes)`);
log.debug(`wrote commit diff to ${diffFile}`);
return {
sha: data.sha,
message: data.commit?.message,
sha: data.sha, message: data.commit?.message,
author: data.author?.login ?? data.commit?.author?.name ?? null,
committer: data.committer?.login ?? data.commit?.committer?.name ?? null,
date: data.commit?.author?.date ?? data.commit?.committer?.date ?? "",
url: data.html_url,
parents: (data.parents ?? []).map((p) => p.sha),
stats: data.stats ?? { additions: 0, deletions: 0, total: 0 },
fileCount: files.length,
diffFile,
fileCount: files.length, diffFile,
};
}),
});