From a5a0a45931448f97f8d17b2cd2bbf9602f69f737 Mon Sep 17 00:00:00 2001 From: mmatotan Date: Thu, 25 May 2023 15:58:26 +0200 Subject: [PATCH] Optionally select the second element from array, fixes #214 --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7da1cf6..3f6d230 100644 --- a/index.js +++ b/index.js @@ -179,7 +179,9 @@ const pkg = getPackageJson(); currentBranch = process.env.GITHUB_HEAD_REF; isPullRequest = true; } else { - currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1]; + let regexBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF); + // If GITHUB_REF is null then do not set the currentBranch + currentBranch = regexBranch ? regexBranch[1] : undefined; } if (process.env['INPUT_TARGET-BRANCH']) { // We want to override the branch that we are pulling / pushing to @@ -229,7 +231,7 @@ const pkg = getPackageJson(); } catch (e) { console.warn( 'git commit failed because you are using "actions/checkout@v2" or later; ' + - 'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"', + 'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"', ); }