VoidBot/scripts/install-source-index-post-push-hooks.ts

62 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2026-04-24 13:17:00 +01:00
import "dotenv/config";
import { loadConfig } from "@voidbot/config";
import { discoverSourceRepos, selectSourceRepos } from "@voidbot/rag";
2026-05-02 12:49:23 +01:00
import { installSourceIndexPushHooks } from "./source-repo-hooks";
2026-04-24 13:17:00 +01:00
interface ScriptOptions {
repos?: string[];
}
async function main(): Promise<void> {
if (!process.env.DISCORD_OWNER_ID) {
process.env.DISCORD_OWNER_ID = "__source_hook_install__";
}
const config = loadConfig();
if (!config.sourceRepoRoot) {
throw new Error("SOURCE_REPO_ROOT is not configured.");
}
const options = parseArgs(process.argv.slice(2));
2026-05-02 12:49:23 +01:00
const discoveredRepos = await discoverSourceRepos(config.sourceRepoRoot, config.sourceRepoPatterns);
const selectedRepos = selectSourceRepos(discoveredRepos, options.repos);
const summary = await installSourceIndexPushHooks(process.cwd(), selectedRepos);
2026-04-24 13:17:00 +01:00
2026-05-02 12:49:23 +01:00
for (const message of summary.messages) {
console.log(message);
2026-04-24 13:17:00 +01:00
}
console.log(
[
2026-05-02 12:49:23 +01:00
`installed=${summary.installed}`,
`updated=${summary.updated}`,
`backedUp=${summary.backedUp}`,
`skipped=${summary.skipped}`,
2026-04-24 13:17:00 +01:00
].join(" "),
);
}
function parseArgs(argv: string[]): ScriptOptions {
const options: ScriptOptions = {};
for (let index = 0; index < argv.length; index += 1) {
const argument = argv[index];
if ((argument === "--repo" || argument === "--repos") && argv[index + 1]) {
options.repos = argv[index + 1]
.split(",")
.map((entry) => entry.trim())
.filter((entry) => entry.length > 0);
index += 1;
}
}
return options;
}
void main().catch((error) => {
console.error(error);
process.exitCode = 1;
});