Provide a DSL for registering and controlling the execution of rules in a given context
- Dominant language
- TypeScript
- Stars
- 5.5k
- Forks
- 381
- Avg merge
- 2h 8m
- Merged PRs (30d)
- 6
Description
## Overview
This is a proposal for an extension of Danger's DSL to also provide interfaces for the registration, reference to, and execution of rules defined in a Dangerfile. Right now, Dangerfiles are simply read and then [executed](https://github.com/danger/danger-js/blob/master/source/runner/runners/vm2.ts#L51) via a `vm2` sandbox.
## Proposed DSL
### DSL for rules
A DSL for defining a rule could look like:
```
interface DangerRule {
name: string
rule: function
}
```
Writing a rule in a Dangerfile could then be an instantiation of the `DangerRule`:
```
const myRule: DangerRule = {
name: "org.danger.pullRequest.description",
rule: function(){
const pr = danger.github.pr
if (pr.body === null || pr.body.length === 0) {
fail("Please add a description to your PR.")
}
}
}
```
This DSL could also provide greater extensibility and flexibility for sharing rules across multiple Dangerfiles (as in Peril with one or many org-defined Dangerfiles as well as per-repo Dangerfiles, these rules could be referred to by their `name` attribute. For example, suppose the above `DangerRule` is instantiated in one org-level Dangerfile as - a given repo's Dangerfile could reference this rule.
### DSL for rules execution
A DSL for the execution of rules in a given context might look like:
```
interface DangerRuleSet {
includeRules: [String],
excludeRules: [String]
}
```
And would be instantiated by:
```
const myRuleSet: DangerRuleset = {
includeRules: ["org.danger.pullRequest.description"]
}
```
The Danger runner could then:
- load all instantiated `DangerRules` and `DangerRuleSet`s from all included Dangerfiles
- resolve the inclusion and exclusions in all `DangerRuleSets` to build an execution plan (queue of rules to be executed)
- For all `DangerRules` in the execution plan, execute their `rule` functions as callbacks
For reference, check out how the `RuboCop` project's `Cops` [interface](https://github.com/bbatsov/rubocop/blob/master/manual/cops.md).
Contributor guide
Research direction
Start with source/runner/runners/vm2.ts, where Dangerfiles are currently executed in a vm2 sandbox, and trace how included Dangerfiles are loaded. Compare that behavior with the proposed DangerRule and DangerRuleSet interfaces; done means the project has a defined approach for registering named rules, resolving inclusions and exclusions, and executing the resulting callbacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100