Skip to content

Commit

Permalink
fix: pr ref to branch head (#37)
Browse files Browse the repository at this point in the history
* fix: update the ref for PRs to use the branch head
* chore: build latest version
  • Loading branch information
KyleTryon authored Dec 15, 2022
1 parent db79717 commit 63a07f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.DS_Store
.idea
.vscode
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 63a07f8

Please sign in to comment.