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

Add pull request review event type #62

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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