27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
// git as peppa-bot: the per-repo `peppa` credential helper answers for the Gitea host.
|
|
import { execFile } from "node:child_process";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { promisify } from "node:util";
|
|
import { loadEnv, peppaRoot } from "@peppa/shared";
|
|
|
|
export const run = promisify(execFile);
|
|
|
|
export function credentialHelper(): string {
|
|
return `!${peppaRoot(resolve(dirname(fileURLToPath(import.meta.url)), "../../.."))}/packages/cli/bin/git-credential-peppa`;
|
|
}
|
|
|
|
export function git(cwd: string, ...args: string[]) {
|
|
// The peppa helper answers for the Gitea host with the bot token; nothing else is consulted.
|
|
return run("git", ["-c", "credential.helper=", "-c", `credential.helper=${credentialHelper()}`, ...args], {
|
|
cwd,
|
|
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
});
|
|
}
|
|
|
|
/** Clone URL of the shared project template (override for tests). */
|
|
export function templateRepoUrl(override?: string): string {
|
|
const env = loadEnv();
|
|
return override ?? process.env.PEPPA_TEMPLATE_URL ?? `${env.GITEA_URL}/${env.GITEA_TEMPLATE_REPO}.git`;
|
|
}
|