From 05b7519cdd920c5ddb7c8a03896096054c72a2cc Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Tue, 8 Oct 2024 16:22:19 -0400 Subject: [PATCH 1/4] Allow action to work on pull_request_target triggers. --- src/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.ts b/src/utils.ts index adcaa2e..80e9daa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import * as github from '@actions/github' export async function validateEventType(): Promise { if ( github.context.eventName !== 'pull_request' && + github.context.eventName !== 'pull_request_target' && github.context.eventName !== 'push' ) { throw new Error('Error, action only works for pull_request or push events!') From 993123407d6f4c8acebd05958397f2c560c42554 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Tue, 8 Oct 2024 16:33:48 -0400 Subject: [PATCH 2/4] Oops. Needed a release task to run. --- dist/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/dist/index.js b/dist/index.js index fe5bf69..64fd396 100644 --- a/dist/index.js +++ b/dist/index.js @@ -455,6 +455,7 @@ const github = __importStar(__nccwpck_require__(5438)); function validateEventType() { return __awaiter(this, void 0, void 0, function* () { if (github.context.eventName !== 'pull_request' && + github.context.eventName !== 'pull_request_target' && github.context.eventName !== 'push') { throw new Error('Error, action only works for pull_request or push events!'); } From ecb33b7b260c3bd5e3181fc3e3389635536d1ace Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Tue, 8 Oct 2024 16:47:05 -0400 Subject: [PATCH 3/4] Updated README and error output. --- README.md | 6 +++--- src/utils.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a37c9bd..9158a4c 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ A simple Github Action that allows us to update the status of a commit. GitHub does not update the status of a commit when running workflow and therefore tools that rely on the context/status of a given commit are not compatible with it. -Currently the action supports `pull_request` and `push` events: -* When the event is `pull_request`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered. +Currently the action supports `pull_request`, `pull_request_target` and `push` events: +* When the event is `pull_request` or `pull_request_target`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered. * When the event is `push`, the action will set the status to the last commit pushed at the moment the workflow was triggered. ## Input Parameters @@ -279,4 +279,4 @@ tide: ## Development -__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__ \ No newline at end of file +__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__ diff --git a/src/utils.ts b/src/utils.ts index 80e9daa..3d3d9a5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,6 +6,8 @@ export async function validateEventType(): Promise { github.context.eventName !== 'pull_request_target' && github.context.eventName !== 'push' ) { - throw new Error('Error, action only works for pull_request or push events!') + throw new Error( + 'Error, action only works for pull_request, pull_request_target or push events!' + ) } } From 975a82b5a4420cabe91a6b0501be84181e8b2ae9 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Tue, 8 Oct 2024 16:47:36 -0400 Subject: [PATCH 4/4] Allow sha and other data to be picked up on pull_request_target types. --- dist/index.js | 4 ++-- src/githubHelper.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 64fd396..e07f4c8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -60,7 +60,7 @@ class GithubHelper { initialize() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11; return __awaiter(this, void 0, void 0, function* () { - if (github_1.context.eventName === 'pull_request') { + if (['pull_request', 'pull_request_target'].includes(github_1.context.eventName)) { this.isPR = true; this.owner = (_e = (_d = (_c = (_b = (_a = github_1.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.head) === null || _c === void 0 ? void 0 : _c.repo) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.login; this.repo = (_j = (_h = (_g = (_f = github_1.context.payload) === null || _f === void 0 ? void 0 : _f.pull_request) === null || _g === void 0 ? void 0 : _g.head) === null || _h === void 0 ? void 0 : _h.repo) === null || _j === void 0 ? void 0 : _j.name; @@ -457,7 +457,7 @@ function validateEventType() { if (github.context.eventName !== 'pull_request' && github.context.eventName !== 'pull_request_target' && github.context.eventName !== 'push') { - throw new Error('Error, action only works for pull_request or push events!'); + throw new Error('Error, action only works for pull_request, pull_request_target or push events!'); } }); } diff --git a/src/githubHelper.ts b/src/githubHelper.ts index a3c16c1..039a8e9 100644 --- a/src/githubHelper.ts +++ b/src/githubHelper.ts @@ -34,7 +34,7 @@ class GithubHelper { } private async initialize(): Promise { - if (context.eventName === 'pull_request') { + if (['pull_request', 'pull_request_target'].includes(context.eventName)) { this.isPR = true this.owner = context.payload?.pull_request?.head?.repo?.owner?.login this.repo = context.payload?.pull_request?.head?.repo?.name