Skip to content

Commit

Permalink
feat: allow custom rules from configuration (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Oct 1, 2020
1 parent 74a320c commit 1acdde3
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 50 deletions.
38 changes: 30 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
# Configuration
The bot can be configured with a file located at `.github/in-solidarity.yml` in the target repo or at the same path in a repo named `.github` in the organization.
The bot can be configured with a file located at `.github/in-solidarity.yml` in the target repo or at the same path in a repo named `.github` within the organization. The JSON schema is located at [docs/schema.json](https://github.com/jpoehnelt/in-solidarity-bot/blob/main/docs/schema.json).

```yaml
rules:
master:
level: off
slave:
level: failure
foo:
regex:
- /foo/gi
- /foobar/gi
level: failure
ignore:
- ".github/in-solidarity.yml" # default
- "**/*.yml"
```
The possible levels are `['off', 'notice', 'warning', 'failure']`. These correspond to [annotation_level in the GitHub API](https://docs.github.com/en/rest/reference/checks#create-a-check-run).

The default configuration can be ignored with `ignoreDefaults: true` such as in the following.

```yaml
rules:
foo:
regex:
- /foo/gi
- /foobar/gi
level: failure
ignoreDefaults: true
```
This will only check the single rule.

> **Note**: The merging of defaults uses array replacement. This means any array provided by the configuration will be used and default elements ignored.

> **Note**: The bot uses the configuration from the default branch. Therefore any changes to the configuration in a pull request will not be used until merged.

Read more about configuration for organizations at [Probot best practices](https://github.com/probot/probot/blob/master/docs/best-practices.md#store-configuration-in-the-repository).

# Rules

The following are the current rules. Additional rules are welcome!

| rule | default level |
|---|---|
|[master](rules/master) | `warning` |
|[slave](rules/slave) | `warning` |
|[whitelist](rules/whitelist) | `warning` |
|[blacklist](rules/blacklist) | `warning` |
|[grandfathered](rules/grandfathered) | `warning` |
|[sanity_check](rules/sanity_check) | `warning` |
|[man_hours](rules/man_hours) | `warning` |
|[master](rules/master.md) | `warning` |
|[slave](rules/slave.md) | `warning` |
|[whitelist](rules/whitelist.md) | `warning` |
|[blacklist](rules/blacklist.md) | `warning` |
|[grandfathered](rules/grandfathered.md) | `warning` |
|[sanity_check](rules/sanity_check.md) | `warning` |
|[man_hours](rules/man_hours.md) | `warning` |

_This document is generated from a template using [rules.ts](https://github.com/jpoehnelt/in-solidarity-bot/blob/main/src/rules.ts) and [docs/index.ts](https://github.com/jpoehnelt/in-solidarity-bot/blob/main/docs/index.ts)._
210 changes: 210 additions & 0 deletions docs/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"definitions": {
"level": {
"type": "string",
"enum": [
"off",
"notice",
"warning",
"failure"
]
},
"regex": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"pattern": "^/.+/[giu]*$"
}
},
"alternatives": {
"type": "array",
"items": {
"type": "string",
"minLength": 2
}
}
},
"properties": {
"ignore": {
"type": "array",
"minitems": 1,
"items": {
"type": "string"
}
},
"ignoreDefaults": {
"type": "boolean"
},
"rules": {
"type": "object",
"properties": {
"master": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"slave": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"whitelist": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"blacklist": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"grandfathered": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"sanity_check": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
},
"man_hours": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
}
}
},
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
},
"required": [
"level",
"regex"
]
}
}
},
"if": {
"required": [
"ignoreDefaults"
],
"properties": {
"ignoreDefaults": true
}
},
"then": {
"required": [
"rules"
],
"properties": {
"rules": {
"type": "object",
"properties": {},
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"properties": {
"level": {
"$ref": "#/definitions/level"
},
"alternatives": {
"$ref": "#/definitions/alternatives"
},
"regex": {
"$ref": "#/definitions/regex"
}
},
"required": [
"level",
"regex"
]
}
}
}
}
}
3 changes: 3 additions & 0 deletions fixtures/in-solidarity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
rules:
master:
level: off
foo:
level: failure
regex: ["/foo/gi"]
ignore:
- ".github/in-solidarity.yml"
- "**/*.yml"
5 changes: 5 additions & 0 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"license": "Apache 2.0",
"author": "Justin Poehnelt <[email protected]>",
"scripts": {
"build": "tsc -p tsconfig.json && cp -r src/templates dist/src/templates",
"build": "rm -rf dist && tsc -p tsconfig.json && cp -avr src/templates/ dist/src/templates/",
"format": "eslint src/*.ts --fix",
"lint": "eslint src/*.ts",
"start": "probot run ./dist/src/index.js",
"test": "jest",
"test:update": "jest --updateSnapshot",
"docs": "node ./dist/src/docs/index.js"
"docs": "rm -rf docs && node ./dist/src/docs/index.js"
},
"jest": {
"testEnvironment": "node"
Expand All @@ -38,7 +38,8 @@
"handlebars": "^4.7.6",
"js-yaml": "^3.14.0",
"minimatch": "^3.0.4",
"probot": "^10.8.0"
"probot": "^10.8.0",
"regex-parser": "^2.2.11"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^9.0.0",
Expand Down
Loading

0 comments on commit 1acdde3

Please sign in to comment.