Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@ var CliOsPath;
CliOsPath["MacOS"] = "Darwin/mayhem.pkg";
CliOsPath["Windows"] = "Windows/mayhem.exe";
})(CliOsPath || (CliOsPath = {}));
/**
* Strips a "refs/heads/" prefix only if present, instead of unconditionally
* slicing it off - GITHUB_REF_NAME is already short, so the old unconditional
* slice chopped real characters off the branch name (could crash the mayhem
* CLI's arg parser if that left a leading "-", e.g. "delta-repro-...").
*/
function resolveBranchName(refName) {
if (!refName) {
return "main";
}
const refsHeadsPrefix = "refs/heads/";
return refName.startsWith(refsHeadsPrefix)
? refName.slice(refsHeadsPrefix.length)
: refName;
}
function getConfig() {
var _a;
const githubToken = (0, core_1.getInput)("github-token", {
required: true,
});
Expand Down Expand Up @@ -73,7 +87,7 @@ function getConfig() {
ciUrl: `${ghRepo}/actions/runs/${process.env["GITHUB_RUN_ID"]}`,
branchName: eventPullRequest
? eventPullRequest.head.ref
: ((_a = process.env["GITHUB_REF_NAME"]) === null || _a === void 0 ? void 0 : _a.slice("refs/heads/".length)) || "main",
: resolveBranchName(process.env["GITHUB_REF_NAME"]),
revision: eventPullRequest
? eventPullRequest.head.sha
: process.env["GITHUB_SHA"] || "unknown",
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ type Config = {
mergeBaseBranchName: string;
};

/**
* Strips a "refs/heads/" prefix only if present, instead of unconditionally
* slicing it off - GITHUB_REF_NAME is already short, so the old unconditional
* slice chopped real characters off the branch name (could crash the mayhem
* CLI's arg parser if that left a leading "-", e.g. "delta-repro-...").
*/
function resolveBranchName(refName: string | undefined): string {
if (!refName) {
return "main";
}
const refsHeadsPrefix = "refs/heads/";
return refName.startsWith(refsHeadsPrefix)
? refName.slice(refsHeadsPrefix.length)
: refName;
}

function getConfig(): Config {
const githubToken: string = getInput("github-token", {
required: true,
Expand Down Expand Up @@ -85,7 +101,7 @@ function getConfig(): Config {
ciUrl: `${ghRepo}/actions/runs/${process.env["GITHUB_RUN_ID"]}`,
branchName: eventPullRequest
? eventPullRequest.head.ref
: process.env["GITHUB_REF_NAME"]?.slice("refs/heads/".length) || "main",
: resolveBranchName(process.env["GITHUB_REF_NAME"]),
revision: eventPullRequest
? eventPullRequest.head.sha
: process.env["GITHUB_SHA"] || "unknown",
Expand Down
Loading