@dapplion/benchmark
Version:
Ensures that new code does not introduce performance regressions with CI. Tracks:
27 lines (26 loc) • 999 B
JavaScript
import { isGaRun } from "../github/context.js";
import { getGithubDefaultBranch } from "../github/octokit.js";
import { shell } from "./shell.js";
let defaultBranch = null;
/**
* Return a cached value of a best guess of the repo's default branch
*/
export async function getDefaultBranch(opts) {
if (opts?.defaultBranch) {
return opts.defaultBranch;
}
if (defaultBranch === null) {
defaultBranch = isGaRun() ? await getGithubDefaultBranch() : await guessLocalDefaultBranch();
}
return defaultBranch;
}
async function guessLocalDefaultBranch() {
const branchesRes = await shell("git branch --all --format='%(refname:short)'");
const branches = branchesRes.split("\n");
const branchSet = new Set(branches);
for (const branch of ["main", "master"]) {
if (branchSet.has(branch) || branchSet.has(`origin/${branch}`))
return branch;
}
throw Error("Could not figure out local default branch. Use persistBranches option");
}