From 63a07f869d0e7ae49686c9d898b9cad89311b74c Mon Sep 17 00:00:00 2001 From: "Kyle a.k.a. TechSquidTV" <33272306+KyleTryon@users.noreply.github.com> Date: Thu, 15 Dec 2022 09:32:07 -0500 Subject: [PATCH] fix: pr ref to branch head (#37) * fix: update the ref for PRs to use the branch head * chore: build latest version --- .gitignore | 1 + dist/index.js | 9 +++++---- index.js | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5e56989..0ce7786 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ .DS_Store .idea +.vscode \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 4b6257e..ef54fb5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12707,14 +12707,15 @@ const repoName = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo; (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`Org: ${repoOrg}`); (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`Repo: ${repoName}`); const ref = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref; -const headRef = process.env.GITHUB_HEAD_REF; const getBranch = () => { if (ref.startsWith("refs/heads/")) { return ref.substring(11); - } else if (ref.startsWith("refs/pull/") && headRef) { - (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`This is a PR. Using head ref ${headRef} instead of ${ref}`); - return headRef; + } else if (ref.startsWith("refs/pull/")) { + (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.info)(`This is a PR. Using head PR branch`); + const pullRequestNumber = ref.match(/refs\/pull\/([0-9]*)\//)[1]; + const newref = `pull/${pullRequestNumber}/head`; + return newref; } return ref; }; diff --git a/index.js b/index.js index 0c1ac68..942344d 100644 --- a/index.js +++ b/index.js @@ -15,14 +15,15 @@ const repoName = context.repo.repo; info(`Org: ${repoOrg}`); info(`Repo: ${repoName}`); const ref = context.ref; -const headRef = process.env.GITHUB_HEAD_REF; const getBranch = () => { if (ref.startsWith("refs/heads/")) { return ref.substring(11); - } else if (ref.startsWith("refs/pull/") && headRef) { - info(`This is a PR. Using head ref ${headRef} instead of ${ref}`); - return headRef; + } else if (ref.startsWith("refs/pull/")) { + info(`This is a PR. Using head PR branch`); + const pullRequestNumber = ref.match(/refs\/pull\/([0-9]*)\//)[1]; + const newref = `pull/${pullRequestNumber}/head`; + return newref; } return ref; };