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; };