Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow action to work on pull_request_target triggers #533

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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...__
__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -455,8 +455,9 @@ 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!');
throw new Error('Error, action only works for pull_request, pull_request_target or push events!');
}
});
}
2 changes: 1 addition & 1 deletion src/githubHelper.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class GithubHelper {
}

private async initialize(): Promise<void> {
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
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -3,8 +3,11 @@ import * as github from '@actions/github'
export async function validateEventType(): Promise<void> {
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!'
)
}
}