Skip to content

Commit

Permalink
feat: add pr-assign-author
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Apr 13, 2023
1 parent 4da661d commit b458c5c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This is a collection of reusable composite actions for GitHub Actions workflows.
- [compare-branches](#compare-branches)
- [GitHub](#github)
- [get-github-token](#get-github-token)
- [pr-assign-author](#pr-assign-author)
- [Miscellaneous](#miscellaneous)
- [bundlewatch](#bundlewatch)
- [cache-nx](#cache-nx)
Expand Down Expand Up @@ -623,6 +624,35 @@ Meant for use within other actions, because obviously you could just use the `to
| ------- | ----------------- | ------- |
| `token` | The GitHub token. | `***` |

#### pr-assign-author

[Source](pr-assign-author/action.yml)

Assign the author of a pull request to the pull request. For use with the `pull_request` event.

##### Example

```yaml
- uses: myparcelnl/actions/pr-assign-author@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}

# Or, if you want to use a GitHub app:

- uses: myparcelnl/actions/pr-assign-author@v3
with:
app-id: ${{ secrets.GITHUB_APP_ID }}
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
```

##### Inputs

| Required | Name | Description | Example | Default |
| -------- | ------------- | ------------------------------------------------------------------------------------------------ | -------------------------------- | ------- |
| false | `token` | GitHub token to use. If passed, takes precedence over the `app-id` and `app-private-key` inputs. | `${{ secrets.GITHUB_TOKEN }}` ||
| false | `app-id` | The app ID of the app. | `${{ secrets.APP_ID }}` ||
| false | `private-key` | The private key of the app. | `${{ secrets.APP_PRIVATE_KEY }}` ||

### Miscellaneous

#### bundlewatch
Expand Down
41 changes: 41 additions & 0 deletions pr-assign-author/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Auto assign author'
description: 'Automatically assign the author of a pull request to the pull request.'

inputs:
token:
description: 'GitHub token to use. If passed, takes precedence over the `app-id` and `app-private-key` inputs.'

app-id:
description: 'The app ID of the app.'

private-key:
description: 'The private key of the app.'

runs:
using: composite
steps:
- uses: actions/checkout@v3

- uses: ./get-github-token
id: token
with:
token: ${{ inputs.token }}
app-id: ${{ inputs.app-id }}
private-key: ${{ inputs.private-key }}

- name: 'Assign author if none are assigned'
uses: actions/github-script@v6
with:
token: ${{ steps.token.outputs.token }}
script: |
if (context.payload.pull_request.assignees.length > 0) {
return;
}
const author = context.payload.pull_request.user.login;
github.rest.issues.addAssignees({
...context.repo,
issue_number: context.payload.pull_request.number,
assignees: [author],
});

0 comments on commit b458c5c

Please sign in to comment.