-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1382ae4
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## PR Approver | ||
|
||
Github action to auto-approve PRs based on labels. | ||
|
||
## How to use | ||
|
||
- Create a github actions workflow in your project | ||
- Define a job that runs on `ubuntu-latest` | ||
- Use this repo's latest release as a reference | ||
- Add the variables `token`, `label-list` and optionally `label-exclusion-list` | ||
|
||
Example: | ||
``` | ||
# <project>/.github/workflows/<action_name.yml> | ||
name: <name> | ||
on: | ||
pull_request: | ||
types: [opened] | ||
jobs: | ||
<job_name>: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: <name> | ||
uses: nrccua/pr_approver@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
label-list: sync | ||
label-exclusion-list: conflict,error | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: PR Approver | ||
description: Github action to auto-approve PRs based on labels | ||
author: NRCCUA | ||
inputs: | ||
token: | ||
description: "Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}" | ||
required: true | ||
label-list: | ||
description: "Comma-separated list of labels that enable a PR approval. Example: test,demo,prep" | ||
required: true | ||
label-exclusion-list: | ||
description: "Comma-separated list of labels that block a PR approval. Example: conflicts,error,temp" | ||
required: false | ||
runs: | ||
using: node12 | ||
main: dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const github = require('@actions/github'); | ||
const core = require('@actions/core'); | ||
|
||
const main = async () => { | ||
const token = core.getInput('token'); | ||
const approvalLabelsString = core.getInput('label-list'); | ||
const exclusionLabelsString = core.getInput('label-exclusion-list'); | ||
const octokit = github.getOctokit(token); | ||
|
||
const { pull_request } = github.context.payload; | ||
const { number, labels } = pull_request; | ||
|
||
const prLabels = labels.map(label => label.name); | ||
const approvalLabels = approvalLabelsString.split(','); | ||
const exclusionLabels = (exclusionLabelsString && exclusionLabelsString.split(',')) || []; | ||
|
||
if ( | ||
exclusionLabels.filter(exclusionLabel => prLabels.includes(exclusionLabel)).length === 0 | ||
&& approvalLabels.filter(approvalLabel => prLabels.includes(approvalLabel)).length > 0 | ||
) { | ||
await octokit.rest.pulls.createReview({ | ||
...github.context.repo, | ||
pull_number: number, | ||
event: 'APPROVE' | ||
}); | ||
} | ||
}; | ||
|
||
main().catch(err => core.setFailed(err.message)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "pr-approver", | ||
"version": "1.0.0", | ||
"description": "Github action to auto-approve PRs based on labels", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rm -rf ./dist && rm -rf ./node_modules", | ||
"build": "npm run clean && npm ci && ncc build index.js -o dist" | ||
}, | ||
"author": "NRCCUA", | ||
"contributors": [ | ||
"Thiago L. Lima <[email protected]>", | ||
"Fabricio Montagnani <[email protected]>" | ||
], | ||
"dependencies": { | ||
"@actions/core": "1.5.0", | ||
"@actions/github": "5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@vercel/ncc": "0.31.1" | ||
} | ||
} |