feat: emit channel events for forgejo intake
This commit is contained in:
parent
ff5b3dc937
commit
419881acbd
|
|
@ -167,6 +167,7 @@ fable-agent plinius godmode "improve explanation quality"
|
||||||
- `--repo <repo>`
|
- `--repo <repo>`
|
||||||
- `--out <path>`
|
- `--out <path>`
|
||||||
- `--dry-run`
|
- `--dry-run`
|
||||||
|
- `--run <id>`
|
||||||
|
|
||||||
### `familiar`
|
### `familiar`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import { findPromptInjection, type PromptInjectionFinding } from "../core/prompt-injection-safety.js";
|
import { findPromptInjection, type PromptInjectionFinding } from "../core/prompt-injection-safety.js";
|
||||||
|
import { emitChannelEvent } from "./channel.js";
|
||||||
|
|
||||||
export type ForgejoIntakeKind = "issue" | "pull" | "wiki";
|
export type ForgejoIntakeKind = "issue" | "pull" | "wiki";
|
||||||
export type ForgejoRoute = "security" | "seo" | "client-report" | "data-pipeline" | "dev" | "wiki" | "triage" | "human-review";
|
export type ForgejoRoute = "security" | "seo" | "client-report" | "data-pipeline" | "dev" | "wiki" | "triage" | "human-review";
|
||||||
|
|
@ -48,6 +49,8 @@ export interface ForgejoIntakeOptions {
|
||||||
token?: string;
|
token?: string;
|
||||||
outDir?: string;
|
outDir?: string;
|
||||||
dryRun?: boolean;
|
dryRun?: boolean;
|
||||||
|
runId?: string;
|
||||||
|
channelRoot?: string;
|
||||||
now?: Date;
|
now?: Date;
|
||||||
fetcher?: ForgejoFetch;
|
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 }> {
|
export async function intakeForgejoItem(opts: ForgejoIntakeOptions): Promise<{ receipt: ForgejoIntakeReceipt; path?: string }> {
|
||||||
const parsed = parseForgejoRef(opts.ref, opts.repo);
|
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;
|
const baseUrl = opts.baseUrl?.replace(/\/$/, "") ?? parsed.baseUrl;
|
||||||
if (!baseUrl) throw new Error("FORGEJO_URL is required unless ISSUE is a full Forgejo URL");
|
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 item = await fetchForgejoItem(baseUrl, parsed, opts.token, opts.fetcher ?? fetch);
|
||||||
const receipt = createForgejoIntakeReceipt(item, opts.now);
|
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 };
|
if (opts.dryRun) return { receipt };
|
||||||
const outDir = opts.outDir ?? ".fable/tasks";
|
const outDir = opts.outDir ?? ".fable/tasks";
|
||||||
fs.mkdirSync(outDir, { recursive: true });
|
fs.mkdirSync(outDir, { recursive: true });
|
||||||
|
|
|
||||||
|
|
@ -1492,7 +1492,8 @@ forgejo
|
||||||
.option("--repo <repo>", "Repo slug for numeric issue refs, e.g. org/repo")
|
.option("--repo <repo>", "Repo slug for numeric issue refs, e.g. org/repo")
|
||||||
.option("--out <path>", "Receipt output directory", ".fable/tasks")
|
.option("--out <path>", "Receipt output directory", ".fable/tasks")
|
||||||
.option("--dry-run", "Print receipt JSON without writing a file")
|
.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 {
|
try {
|
||||||
const { intakeForgejoItem } = await import("./fable5/forgejo-intake.js");
|
const { intakeForgejoItem } = await import("./fable5/forgejo-intake.js");
|
||||||
const result = await intakeForgejoItem({
|
const result = await intakeForgejoItem({
|
||||||
|
|
@ -1500,6 +1501,7 @@ forgejo
|
||||||
repo: opts.repo,
|
repo: opts.repo,
|
||||||
outDir: opts.out,
|
outDir: opts.out,
|
||||||
dryRun: opts.dryRun,
|
dryRun: opts.dryRun,
|
||||||
|
runId: opts.run,
|
||||||
baseUrl: process.env.FORGEJO_URL,
|
baseUrl: process.env.FORGEJO_URL,
|
||||||
token: process.env.FORGEJO_TOKEN,
|
token: process.env.FORGEJO_TOKEN,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue