Skip to content

Commit

Permalink
Project base
Browse files Browse the repository at this point in the history
  • Loading branch information
tlima-daitan committed Sep 22, 2021
0 parents commit 1382ae4
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
30 changes: 30 additions & 0 deletions Readme.md
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
```
16 changes: 16 additions & 0 deletions action.yml
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
29 changes: 29 additions & 0 deletions index.js
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));
176 changes: 176 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
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"
}
}

0 comments on commit 1382ae4

Please sign in to comment.