UNPKG

@dapplion/benchmark

Version:

Ensures that new code does not introduce performance regressions with CI. Tracks:

30 lines (29 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDefaultBranch = getDefaultBranch; const context_js_1 = require("../github/context.js"); const octokit_js_1 = require("../github/octokit.js"); const shell_js_1 = require("./shell.js"); let defaultBranch = null; /** * Return a cached value of a best guess of the repo's default branch */ async function getDefaultBranch(opts) { if (opts?.defaultBranch) { return opts.defaultBranch; } if (defaultBranch === null) { defaultBranch = (0, context_js_1.isGaRun)() ? await (0, octokit_js_1.getGithubDefaultBranch)() : await guessLocalDefaultBranch(); } return defaultBranch; } async function guessLocalDefaultBranch() { const branchesRes = await (0, shell_js_1.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"); }