From efe9b737162bee1038f1a558432e8d59139788e0 Mon Sep 17 00:00:00 2001 From: garronej Date: Wed, 19 Jan 2022 00:34:13 +0100 Subject: [PATCH] Fix is package json version upgraded when branch name contains slashes --- dist/index.js | 5 ++++- src/is_package_json_version_upgraded.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1603086..1385e98 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12386,7 +12386,10 @@ function action(_actionName, params, core) { return __awaiter(this, void 0, void 0, function* () { core.debug(JSON.stringify(params)); const { owner, repo, github_token } = params; - const branch = params.branch.split("/").reverse()[0]; + //params.branch <- github.head_ref || github.ref + //When it's a normal branch: github.head_ref==="" and github.ref==="refs/heads/main" + //When it's a pr from: github.head_ref==="" + const branch = params.branch.replace(/^refs\/heads\//, ""); const to_version = yield getPackageJsonVersion({ owner, repo, branch }); if (to_version === undefined) { throw new Error(`No version in package.json on ${owner}/${repo}#${branch} (or repo is private)`); diff --git a/src/is_package_json_version_upgraded.ts b/src/is_package_json_version_upgraded.ts index c610fd0..35b6b25 100644 --- a/src/is_package_json_version_upgraded.ts +++ b/src/is_package_json_version_upgraded.ts @@ -34,7 +34,10 @@ export async function action( const { owner, repo, github_token } = params; - const branch = params.branch.split("/").reverse()[0]; + //params.branch <- github.head_ref || github.ref + //When it's a normal branch: github.head_ref==="" and github.ref==="refs/heads/main" + //When it's a pr from: github.head_ref==="" + const branch = params.branch.replace(/^refs\/heads\//, ""); const to_version = await getPackageJsonVersion({ owner, repo, branch });