Skip to content

Commit

Permalink
feat: add dangerjs (#1793)
Browse files Browse the repository at this point in the history
* feat: add dangerjs

* test: add .sol file to test

* refactor: better naming for the CI

* fix: check all files

* fix: check if review is approved

* refactor: delete test file
  • Loading branch information
rafaelugolini authored Aug 31, 2023
1 parent 4c80f7f commit 67fa12a
Show file tree
Hide file tree
Showing 4 changed files with 938 additions and 187 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Danger CI

on:
pull_request:
types: [opened, reopened, synchronize, edited]

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Node.js 16x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: yarn danger ci
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { warn, danger, message } from "danger";

const MINIMUM_REVIEWERS = 2;

const files = [
...danger.git.modified_files,
...danger.git.created_files,
...danger.git.deleted_files,
];
const hasContractChanges = files.some((file) => file.endsWith(".sol"));

if (hasContractChanges) {
const reviewers = danger.github.reviews.filter(
(review) => review.state === "APPROVED"
).length;

if (reviewers < MINIMUM_REVIEWERS) {
warn(`:eyes: This PR needs at least ${MINIMUM_REVIEWERS} reviewers`);
} else {
message(`:tada: This PR has ${reviewers} approved reviews`);
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
},
"engines": {
"node": "16"
},
"devDependencies": {
"danger": "^11.2.8"
}
}
Loading

0 comments on commit 67fa12a

Please sign in to comment.