Skip to content

Commit

Permalink
Merge pull request #6 from duckduckgo/david/improve-pr-notifications
Browse files Browse the repository at this point in the history
Notify Asana of PR reviews
  • Loading branch information
malmstein authored Dec 19, 2024
2 parents 7df2c43 + 8c07566 commit fc06010
Show file tree
Hide file tree
Showing 4 changed files with 1,963 additions and 1,852 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/pr-review-notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:

jobs:
pr-reviewed:
name: Pull Request Review Submitted
runs-on: ubuntu-latest
steps:
- name: Checkout actions repo # required so we can reference the actions locally
Expand All @@ -32,32 +33,40 @@ jobs:
id: post-comment-pr-approved
with:
action: 'post-comment-asana-task'
asanta-task-id: '${{ steps.find-asana-task-id.outputs.asanaTaskId }}'
asanta-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been approved.'
asana-pat: ${{ secrets.asana_pat }}
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been approved.'
asana-task-comment-pinned: true

- name: Add Changes Requested Comment to Asana Task
if: github.event.review.state == 'changes_requested'
uses: ./actions
id: post-comment-pr-changes-requested
with:
action: 'post-comment-asana-task'
asanta-task-id: '${{ steps.find-asana-task-id.outputs.asanaTaskId }}'
asanta-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has changed requested.'
asana-pat: ${{ secrets.asana_pat }}
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has changed requested.'
asana-task-comment-pinned: false

- name: Add Dismissed Comment to Asana Task
if: github.event.review.state == 'dismissed'
uses: ./actions
id: post-comment-pr-dismissed
with:
action: 'post-comment-asana-task'
asanta-task-id: '${{ steps.find-asana-task-id.outputs.asanaTaskId }}'
asanta-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been dismissed.'
asana-pat: ${{ secrets.asana_pat }}
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} review has been dismissed.'
asana-task-comment-pinned: false

- name: Add Review Comment to Asana Task
if: github.event.review.state == 'commented'
uses: ./actions
id: post-comment-pr-reviewed
with:
action: 'post-comment-asana-task'
asanta-task-id: '${{ steps.find-asana-task-id.outputs.asanaTaskId }}'
asanta-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been reviewed.'
asana-pat: ${{ secrets.asana_pat }}
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been reviewed.'
asana-task-comment-pinned: false
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ This action integrates asana with github.
* `create-asana-pr-task` to create a task in Asana based on the Github Pull Request
* `get-latest-repo-release` to find the latest release version of a Github Repository
* `create-asana-task` to create a task in Asana
* `get-asana-user-id` to return the Asana User Id of a given Github actor
* `find-asana-task-id` searches in the PR description for an Asana Task, given a prefix
* `post-comment-asana-task` to post a comment in an Asana task

### Create Asana task from Github Issue
When a Github Issue has been added, it will create an Asana task with the Issue title, description and link.
Expand Down Expand Up @@ -315,6 +318,70 @@ jobs:
asana-collaborators: '${{ steps.get-author-asana-id.outputs.asanaUserId }}'
```

### Find Asana task Id in PR description
Searches for an Asana URL in the PR description, given a prefix. Returns the Asana Task Id if found.

### `trigger-phrase`
**Required** Prefix before the task i.e ASANA TASK: https://app.asana.com/1/2/3/.

#### Example Usage

```yaml
on:
pull_request_review:
types: [submitted]
jobs:
test-job:
runs-on: ubuntu-latest
steps:
- name: Find Asana Task in PR description
uses: ./actions
id: find-asana-task-id
with:
action: 'find-asana-task-id'
trigger-phrase: 'Task/Issue URL:'
- name: Use Asana Task ID from above step
with:
asana-task-id: '${{ steps.find-asana-task-id.outputs.asanaTaskId }}'
```

### Post comment in Asana task
Posts a comment in a given Asana Task

### `asana-pat`
**Required** Asana public access token
### `asana-task-id`
**Required** Id of the task to write the comment on.
### `asana-task-comment`
**Required** Comment to be posted.
### `asana-task-comment-pinned`
**Required** Is the comment pinned or not.

#### Example Usage

```yaml
on:
pull_request_review:
types: [submitted]
jobs:
test-job:
runs-on: ubuntu-latest
steps:
- name: Add Approved Comment to Asana Task
if: github.event.review.state == 'approved'
uses: ./actions
id: post-comment-pr-approved
with:
action: 'post-comment-asana-task'
asana-pat: ${{ secrets.asana_pat }}
asana-task-id: ${{ steps.find-asana-task-id.outputs.asanaTaskId }}
asana-task-comment: 'PR: ${{ github.event.pull_request.html_url }} has been approved.'
asana-task-comment-pinned: true
```

## Building
Run once: `npm i -g @vercel/ncc`

Expand Down
2 changes: 1 addition & 1 deletion action.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ async function findAsanaTaskId(){
const foundTasks = findAsanaTasks()

if (foundTasks.length > 0) {
core.setOutput('asanaTaskId', foundTasks);
core.setOutput('asanaTaskId', foundTasks[0]);
} else {
core.setFailed(`Can't find an Asana task with the expected prefix`);
}
Expand Down
Loading

0 comments on commit fc06010

Please sign in to comment.