Skip to content

Commit

Permalink
Add pull_request_review as a supported event type
Browse files Browse the repository at this point in the history
  • Loading branch information
boardfish committed Apr 23, 2021
1 parent fdb7991 commit 632e0b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions __tests__/get-action-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ test('getActionData should return a formatted object from comment', t => {
});
});

test('getActionData should fail when eventName is not issues or pull_request', t => {
test('getActionData should fail when eventName is not covered by action', t => {
const failingMockGithubContext = Object.assign({}, mockGithubContext);
const eventName = 'label';
failingMockGithubContext.eventName = eventName;

const error = t.throws(() => getActionData(failingMockGithubContext));

t.is(error.message, `Only pull requests, issues or comments allowed, received:\n${eventName}`);
t.is(error.message, `Only pull requests, reviews, issues, or comments allowed. Received:\n${eventName}`);
});
12 changes: 10 additions & 2 deletions src/get-action-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
*
* @param {object} githubContext - The current issue or pull request data
*/
const ACCEPTED_EVENT_TYPES = [
'pull_request',
'pull_request_target',
'pull_request_review',
'issues',
'issue_comment'
];

const getActionData = githubContext => {
const {eventName, payload} = githubContext;
if (eventName !== 'pull_request' && eventName !== 'pull_request_target' && eventName !== 'issues' && eventName !== 'issue_comment') {
throw new Error(`Only pull requests, issues or comments allowed, received:\n${eventName}`);
if (!ACCEPTED_EVENT_TYPES.includes(eventName)) {
throw new Error(`Only pull requests, reviews, issues, or comments allowed. Received:\n${eventName}`);
}

const githubData = eventName === 'issues' || eventName === 'issue_comment' ?
Expand Down

0 comments on commit 632e0b1

Please sign in to comment.