Skip to content

Commit

Permalink
Created CLI for config validation (paritytech#46)
Browse files Browse the repository at this point in the history
Created a very simple CLI which can validate a `review-bot.yml` config
file and produce errors if it finds any.

Also added a step to evaluate the config file in the CI

This resolves paritytech#45
  • Loading branch information
Bullrich authored Aug 10, 2023
1 parent e390843 commit e7fde62
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/javascript-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile
- run: yarn run test

evaluate-config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use node 18
uses: actions/setup-node@v3
with:
node-version: 18
- uses: c-hive/gha-yarn-cache@v2
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Evaluates config file
run: yarn run cli ".github/review-bot.yml"
3 changes: 2 additions & 1 deletion .github/workflows/review-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
private_key: ${{ secrets.TEAM_APP_KEY }}
# !This must always point to main.
# Change it for the PRs but remember to change it back
- uses: paritytech/review-bot@main
- name: "Evaluates PR reviews and assigns reviewers"
uses: paritytech/review-bot@main
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
team-token: ${{ steps.team_token.outputs.token }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules
/dist
/dist*
.env

# Editor directories and files
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
[![Publish package to GitHub Packages](https://github.com/paritytech/review-bot/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/paritytech/review-bot/actions/workflows/publish.yml)

Have custom review rules for PRs with auto assignment.

## Evaluating config

If you want to evaluate the config, we have a simple `cli` to do so.

```bash
yarn run cli ".github/review-bot.yml" # set the parameter as the location of the config
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "node dist",
"build": "ncc build --license LICENSE",
"cli": "ncc build src/cli.ts -o dist-cli && node dist-cli",
"test": "jest",
"fix": "eslint --fix '{src,test}/**/*'",
"lint": "eslint '{src,test}/**/*'"
Expand Down
25 changes: 25 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { readFileSync } from "fs";
import { parse } from "yaml";

import { ConfigurationFile } from "./file/types";
import { validateConfig, validateRegularExpressions } from "./file/validator";

const fileLocation = process.argv[2];

if (!fileLocation) {
throw new Error("Missing file location! Write the path as a parameter. (More info in the README)");
}

console.log("Looking for config in", fileLocation);
const configTxt = readFileSync(fileLocation, "utf8");
console.log("Found config file");
const config = parse(configTxt) as ConfigurationFile;

const configFile = validateConfig(config);

const [result, error] = validateRegularExpressions(configFile, console);
if (!result) {
throw new Error(`Regular expression is invalid: ${error}`);
}

console.log("Config is valid!");

0 comments on commit e7fde62

Please sign in to comment.