Skip to content

Commit

Permalink
Add pull request review event type (#62)
Browse files Browse the repository at this point in the history
* Add pull_request_review as a supported event type

* Update compatible event types in README
  • Loading branch information
boardfish authored and Alex Page committed Apr 23, 2021
1 parent fdb7991 commit 4230e39
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
automate-project-columns:
runs-on: ubuntu-latest
steps:
- uses: alex-page/github-project-automation-plus@v0.3.0
- uses: alex-page/github-project-automation-plus@v0.6.0
with:
project: Backlog
column: Triage
Expand All @@ -51,7 +51,7 @@ jobs:
automate-project-columns:
runs-on: ubuntu-latest
steps:
- uses: alex-page/github-project-automation-plus@v0.3.0
- uses: alex-page/github-project-automation-plus@v0.6.0
with:
project: Backlog
column: To do
Expand All @@ -64,8 +64,8 @@ Change these options in the workflow `.yml` file to meet your GitHub project nee

| Setting | Description | Values |
| --- | --- | --- |
| `on` | When the automation is ran | `issues` `pull_request` `issue_comment` |
| `types` | The types of activity that will trigger a workflow run. | `opened`, `assigned`, `edited` |
| `on` | When the automation is ran | `issues` `pull_request` `issue_comment` `pull_request_target` `pull_request_review` |
| `types` | The types of activity that will trigger a workflow run. | `opened`, `assigned`, `edited`: [See GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) for more |
| `project` | The name of the project | `Backlog` |
| `column` | The column to create or move the card to | `Triage` |
| `repo-token` | The personal access token | `${{ secrets.GITHUB_TOKEN }}` |
Expand Down Expand Up @@ -128,6 +128,7 @@ To set up the action for local development and testing:
## Release History
- v0.6.0 - Add support for `pull_request_target` and `pull_request_review`
- v0.5.1 - Fix get event data from issue_coment
- v0.5.0 - Add option to `delete` card
- v0.4.0 - Add `issue_comment` event
Expand Down
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}`);
});
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-project-automation-plus",
"version": "0.5.0",
"version": "0.6.0",
"description": "🤖 Automate GitHub Project cards with any webhook event",
"private": true,
"main": "dist/index.js",
Expand Down
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 4230e39

Please sign in to comment.