Skip to content

Commit

Permalink
Add support for for pull_request_target event (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean90 authored Mar 14, 2021
1 parent cb48f59 commit 6df415b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
18 changes: 8 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ function parseBranch(eventName, event) {
if (eventName === "push") {
return event.ref.substring(11); // Remove "refs/heads/" from start of string
}
if (eventName === "pull_request") {
if (eventName === "pull_request" || eventName === "pull_request_target") {
return event.pull_request.head.ref;
}
throw Error(`${actionName} does not support "${eventName}" GitHub events`);
Expand All @@ -1045,7 +1045,7 @@ function parseBranch(eventName, event) {
function parseRepository(eventName, event) {
const repoName = event.repository.full_name;
let forkName;
if (eventName === "pull_request") {
if (eventName === "pull_request" || eventName === "pull_request_target") {
// "pull_request" events are triggered on the repository where the PR is made. The PR branch can
// be on the same repository (`forkRepository` is set to `null`) or on a fork (`forkRepository`
// is defined)
Expand Down Expand Up @@ -1102,12 +1102,6 @@ const { getContext } = __nccwpck_require__(476);
const linters = __nccwpck_require__(565);
const { getSummary } = __nccwpck_require__(149);

// Abort action on unhandled promise rejections
process.on("unhandledRejection", (err) => {
core.error(err);
throw new Error(`Exiting because of unhandled promise rejection`);
});

/**
* Parses the action configuration and runs all enabled linters on matching files
*/
Expand All @@ -1119,7 +1113,8 @@ async function runAction() {
const gitEmail = core.getInput("git_email", { required: true });
const commitMessage = core.getInput("commit_message", { required: true });
const checkName = core.getInput("check_name", { required: true });
const isPullRequest = context.eventName === "pull_request";
const isPullRequest =
context.eventName === "pull_request" || context.eventName === "pull_request_target";

// If on a PR from fork: Display messages regarding action limitations
if (isPullRequest && context.repository.hasFork) {
Expand Down Expand Up @@ -1232,7 +1227,10 @@ async function runAction() {
}
}

runAction();
runAction().catch((error) => {
core.debug(error.stack || "No error stack trace");
core.setFailed(error.message);
});


/***/ }),
Expand Down
4 changes: 2 additions & 2 deletions src/github/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function parseBranch(eventName, event) {
if (eventName === "push") {
return event.ref.substring(11); // Remove "refs/heads/" from start of string
}
if (eventName === "pull_request") {
if (eventName === "pull_request" || eventName === "pull_request_target") {
return event.pull_request.head.ref;
}
throw Error(`${actionName} does not support "${eventName}" GitHub events`);
Expand All @@ -76,7 +76,7 @@ function parseBranch(eventName, event) {
function parseRepository(eventName, event) {
const repoName = event.repository.full_name;
let forkName;
if (eventName === "pull_request") {
if (eventName === "pull_request" || eventName === "pull_request_target") {
// "pull_request" events are triggered on the repository where the PR is made. The PR branch can
// be on the same repository (`forkRepository` is set to `null`) or on a fork (`forkRepository`
// is defined)
Expand Down
14 changes: 6 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ const { getContext } = require("./github/context");
const linters = require("./linters");
const { getSummary } = require("./utils/lint-result");

// Abort action on unhandled promise rejections
process.on("unhandledRejection", (err) => {
core.error(err);
throw new Error(`Exiting because of unhandled promise rejection`);
});

/**
* Parses the action configuration and runs all enabled linters on matching files
*/
Expand All @@ -25,7 +19,8 @@ async function runAction() {
const gitEmail = core.getInput("git_email", { required: true });
const commitMessage = core.getInput("commit_message", { required: true });
const checkName = core.getInput("check_name", { required: true });
const isPullRequest = context.eventName === "pull_request";
const isPullRequest =
context.eventName === "pull_request" || context.eventName === "pull_request_target";

// If on a PR from fork: Display messages regarding action limitations
if (isPullRequest && context.repository.hasFork) {
Expand Down Expand Up @@ -138,4 +133,7 @@ async function runAction() {
}
}

runAction();
runAction().catch((error) => {
core.debug(error.stack || "No error stack trace");
core.setFailed(error.message);
});

0 comments on commit 6df415b

Please sign in to comment.