UNPKG

@dapplion/benchmark

Version:

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

42 lines (41 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseRef = parseRef; exports.parseBranchFromRef = parseBranchFromRef; const refsRegex = /^refs\/(\w*)\/(.*)/; /** * Parses a git ref string: * ``` * refs/heads/* > { type: "heads", name: "*" } * refs/tags/* > { type: "tags", name: "*" } * refs/remotes/ > { type: "remotes", name: "" } * ``` * @param refStr "refs/heads/dapplion/feat1" */ function parseRef(refStr) { const match = refStr.match(refsRegex); if (match === null) { throw Error(`Invalid ref ${refStr}`); } const type = match[1]; const name = match[2]; return { type, name }; } /** * Parse ref * @param refStr * @returns */ function parseBranchFromRef(refStr) { const ref = parseRef(refStr); switch (ref.type) { case "heads": return ref.name; case "pull": throw Error("Merge commit not supported. Make sure to checkout head branch commit"); case "tags": throw Error("Running on tags not supported. Trigger on push events only"); default: throw Error(`Ref type '${ref.type}' not supported: ${refStr}`); } }