feat: emit channel events for forgejo intake

This commit is contained in:
artale 2026-06-18 00:24:35 +02:00
parent ff5b3dc937
commit 419881acbd
3 changed files with 9 additions and 1 deletions

View File

@ -167,6 +167,7 @@ fable-agent plinius godmode "improve explanation quality"
- `--repo <repo>`
- `--out <path>`
- `--dry-run`
- `--run <id>`
### `familiar`

View File

@ -1,6 +1,7 @@
import * as fs from "node:fs";
import * as path from "node:path";
import { findPromptInjection, type PromptInjectionFinding } from "../core/prompt-injection-safety.js";
import { emitChannelEvent } from "./channel.js";
export type ForgejoIntakeKind = "issue" | "pull" | "wiki";
export type ForgejoRoute = "security" | "seo" | "client-report" | "data-pipeline" | "dev" | "wiki" | "triage" | "human-review";
@ -48,6 +49,8 @@ export interface ForgejoIntakeOptions {
token?: string;
outDir?: string;
dryRun?: boolean;
runId?: string;
channelRoot?: string;
now?: Date;
fetcher?: ForgejoFetch;
}
@ -98,11 +101,13 @@ export function createForgejoIntakeReceipt(item: ForgejoItem, now = new Date()):
export async function intakeForgejoItem(opts: ForgejoIntakeOptions): Promise<{ receipt: ForgejoIntakeReceipt; path?: string }> {
const parsed = parseForgejoRef(opts.ref, opts.repo);
if (opts.runId) emitChannelEvent(opts.runId, { source: "intake", type: "started", data: { ref: opts.ref, repo: parsed.repo, kind: parsed.kind } }, opts.channelRoot, opts.now);
const baseUrl = opts.baseUrl?.replace(/\/$/, "") ?? parsed.baseUrl;
if (!baseUrl) throw new Error("FORGEJO_URL is required unless ISSUE is a full Forgejo URL");
const item = await fetchForgejoItem(baseUrl, parsed, opts.token, opts.fetcher ?? fetch);
const receipt = createForgejoIntakeReceipt(item, opts.now);
if (opts.runId) emitChannelEvent(opts.runId, { source: "intake", type: "receipt", data: receipt }, opts.channelRoot, opts.now);
if (opts.dryRun) return { receipt };
const outDir = opts.outDir ?? ".fable/tasks";
fs.mkdirSync(outDir, { recursive: true });

View File

@ -1492,7 +1492,8 @@ forgejo
.option("--repo <repo>", "Repo slug for numeric issue refs, e.g. org/repo")
.option("--out <path>", "Receipt output directory", ".fable/tasks")
.option("--dry-run", "Print receipt JSON without writing a file")
.action(async (ref: string, opts: { repo?: string; out?: string; dryRun?: boolean }) => {
.option("--run <id>", "Emit intake events to .runs/<id>/channel.jsonl")
.action(async (ref: string, opts: { repo?: string; out?: string; dryRun?: boolean; run?: string }) => {
try {
const { intakeForgejoItem } = await import("./fable5/forgejo-intake.js");
const result = await intakeForgejoItem({
@ -1500,6 +1501,7 @@ forgejo
repo: opts.repo,
outDir: opts.out,
dryRun: opts.dryRun,
runId: opts.run,
baseUrl: process.env.FORGEJO_URL,
token: process.env.FORGEJO_TOKEN,
});