feat: adapt pullfrog for gitea + ollama

This commit is contained in:
2026-05-31 01:01:00 -05:00
parent 36ac64a5b6
commit 2aca1a3aa3
183 changed files with 1419 additions and 28292 deletions
+19 -22
View File
@@ -2,7 +2,7 @@ import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { type } from "arktype";
import { log } from "../utils/cli.ts";
import { formatFilesWithLineNumbers } from "./checkout.ts";
import { formatFilesWithLineNumbers, type DiffFile } from "./checkout.ts";
import type { ToolContext } from "./server.ts";
import { execute, tool } from "./shared.ts";
@@ -14,27 +14,28 @@ export function CommitInfoTool(ctx: ToolContext) {
return tool({
name: "get_commit_info",
description:
"Retrieve commit metadata and diff via GitHub API. Use this instead of git show for reviewing commits - " +
"it works with shallow clones and shows the actual changes in the commit. Returns diffPath pointing to formatted diff file. " +
"Retrieve commit metadata and diff via Gitea API. Returns diffPath pointing to formatted diff file. " +
'Example: `get_commit_info({ sha: "2a6ab5d" })`.',
parameters: CommitInfo,
execute: execute(async ({ sha }) => {
const response = await ctx.octokit.rest.repos.getCommit({
const result = await ctx.gitea.rest.repository.repoGetSingleCommit({
owner: ctx.repo.owner,
repo: ctx.repo.name,
ref: sha,
sha,
});
const data = result.data;
const data = response.data;
const files = data.files ?? [];
// 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,
}));
// format diff with line numbers and write to file
const formatResult = formatFilesWithLineNumbers(files);
const tempDir = process.env.PULLFROG_TEMP_DIR;
const tempDir = process.env.SHOCKBOT_TEMP_DIR;
if (!tempDir) {
throw new Error(
"PULLFROG_TEMP_DIR not set - get_commit_info must run in pullfrog action context"
);
throw new Error("SHOCKBOT_TEMP_DIR not set - get_commit_info must run in shockbot action context");
}
const diffFile = join(tempDir, `commit-${sha.slice(0, 7)}.diff`);
writeFileSync(diffFile, formatResult.content);
@@ -42,17 +43,13 @@ export function CommitInfoTool(ctx: ToolContext) {
return {
sha: data.sha,
message: data.commit.message,
author: data.author?.login ?? null,
committer: data.committer?.login ?? null,
date: data.commit.author?.date ?? data.commit.committer?.date ?? "",
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: {
additions: data.stats?.additions ?? 0,
deletions: data.stats?.deletions ?? 0,
total: data.stats?.total ?? 0,
},
parents: (data.parents ?? []).map((p) => p.sha),
stats: data.stats ?? { additions: 0, deletions: 0, total: 0 },
fileCount: files.length,
diffFile,
};