Restore Superpowers reviews (#12)
Co-authored-by: Danny Kim <temeddix@gmail.com> Co-committed-by: Danny Kim <temeddix@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
// so it appears as the bot account.
|
||||
import { TextLineStream } from "jsr:@std/streams@1/text-line-stream";
|
||||
import { retryInvalidToken } from "./auth.ts";
|
||||
import {
|
||||
type BotType,
|
||||
parseBotType,
|
||||
superpowersInstallCommands,
|
||||
} from "./superpowers.ts";
|
||||
|
||||
type GiteaUser = { login: string; email: string };
|
||||
type GiteaComment = { user: GiteaUser; created_at: string; body: string };
|
||||
@@ -18,6 +23,7 @@ const API = env("GITEA_API_URL");
|
||||
const REPO = env("GITEA_REPOSITORY");
|
||||
const INDEX = env("ISSUE_INDEX");
|
||||
const EVENT = env("EVENT_NAME");
|
||||
const BOT = parseBotType(env("BOT_TYPE"));
|
||||
const AUTHOR_TOKEN = env("GITEA_TOKEN");
|
||||
const REVIEWER_TOKEN = env("REVIEWER_TOKEN");
|
||||
const RULES_PATH = "repos/commons/code-rules/raw/README.md";
|
||||
@@ -146,6 +152,14 @@ async function run(command: string, args: string[]): Promise<void> {
|
||||
if (!success) throw new Error(`${command} ${args[0]} exited with ${code}`);
|
||||
}
|
||||
|
||||
// The reviewer uses Superpowers' requesting-code-review template. Both plugin
|
||||
// installers are idempotent on the persisted bot home.
|
||||
async function installSuperpowers(bot: BotType): Promise<void> {
|
||||
for (const { command, args } of superpowersInstallCommands(bot)) {
|
||||
await run(command, args);
|
||||
}
|
||||
}
|
||||
|
||||
// Commits belong to the same account as the pull request they end up in.
|
||||
async function configureGitAuthor(): Promise<void> {
|
||||
const user: GiteaUser = await (await gitea(AUTHOR_TOKEN, "user")).json();
|
||||
@@ -188,6 +202,7 @@ async function runClaude(prompt: string): Promise<string> {
|
||||
"Run `claude setup-token` locally and set the `bot-token` action input.",
|
||||
);
|
||||
}
|
||||
await installSuperpowers("claude");
|
||||
const claude = new Deno.Command("claude", {
|
||||
args: [
|
||||
"--print",
|
||||
@@ -257,6 +272,7 @@ async function runCodex(prompt: string): Promise<string> {
|
||||
})
|
||||
.output();
|
||||
if (!loggedIn.success) await codexDeviceLogin();
|
||||
await installSuperpowers("codex");
|
||||
const file = await Deno.makeTempFile();
|
||||
const attempt = async () => {
|
||||
const codex = new Deno.Command("codex", {
|
||||
@@ -294,7 +310,7 @@ async function runCodex(prompt: string): Promise<string> {
|
||||
try {
|
||||
await configureGitAuthor();
|
||||
const prompt = await renderPrompt();
|
||||
const result = env("BOT_TYPE") === "claude"
|
||||
const result = BOT === "claude"
|
||||
? await runClaude(prompt)
|
||||
: await runCodex(prompt);
|
||||
await postResult(result);
|
||||
|
||||
Reference in New Issue
Block a user