@@ -8,22 +8,24 @@ blurb: How to use `danger process` to create a Danger runner for any language.
88
99## Danger Process
1010
11- In version 2.0.0 and above, Danger comes with a new command: ` danger process ` . This command should have all the same
12- parameters as ` danger ` and is meant to be an optional replacement. It's idea is that the responsibilities of Danger can
13- be split into three steps:
11+ In version 6.0.0 and above, Danger's commands comes with an optional new argument: ` --process ` . This argument allows
12+ another app to handle the evaluation of a Dangerfile.
13+
14+ The core idea is that the responsibilities of Danger can be split into three steps:
1415
1516- Dangerfile DSL setup.
1617- Evaluation of a Dangerfile.
1718- Handling the results of the Dangerfile run.
1819
19- Danger JS will handle the first and the last steps, and another process will handle the second. This means most of the
20- really tricky work stays inside Danger, and the other process can only has to worry about translating the DSL into
21- something that feels natural in the environment of your app.
20+ Danger JS will always handle the first and the last steps, and another process will handle the second. In normal Danger
21+ JS, this will create a sub-process which calls ` danger runner ` , but there is the ability for another process to handle
22+ the work instead. This means most of the ** really** tricky work stays inside Danger, and the other process only has to
23+ worry about translating the DSL into something that feels natural in the environment of your app.
2224
2325### Implementing a Danger Process Runner
2426
25- ` danger process` expects one argument, the command to trigger the process for Danger JS to run. This command should
26- expect the Danger DSL as JSON in STDIN, and it is expected that it would post results to STDOUT via JSON.
27+ Your sub- process command should expect the Danger DSL to come in as JSON to STDIN, and it is expected that it would post
28+ results out to STDOUT via JSON or a filepath .
2729
2830You can preview the DSL which will be sent to your process via ` danger pr ` with the ` --js ` and ` --json ` flags, for
2931example:
@@ -32,19 +34,22 @@ example:
3234danger pr https://github.com/danger/danger-js/pull/395 --js
3335```
3436
35- This shows you DSL as a JavaScript object - this is easier to read and syntax highlighted. If you'd like a data fixture,
36- use ` --json ` :
37+ This shows you the DSL as a JavaScript object - this is easier to read and syntax highlighted. If you'd like a data
38+ fixture, use ` --json ` :
3739
3840``` sh
3941danger pr https://github.com/danger/danger-js/pull/395 --json > danger-js-395.dsl.json
4042```
4143
4244This will work for any open repo, and if you've set up your local shell to include ` DANGER_GITHUB_API_TOKEN ` then you
43- can use this with any private repository too. You can see the [ incoming] [ ] and [ outgoing] [ ] JSON schema is documented in
44- Danger JS's repo, or you can see the types as (incoming to your process) [ DangerJSONDSLType] [ ] and (coming out from your
45- process) [ DangerResults] [ ] , I plan to add a full reference for this, similar to the reference for the user's DSL in the
46- future in these docs. _ Note:_ The JSON will include your access token, so you probably want to sanitize that before
47- commiting it to the repo. I accidentally shipped 2 tokens in writing the feature.
45+ can use this with any private repository too.
46+
47+ The JSON is documented using JSON Schema: [ incoming] [ ] and [ outgoing] [ ] , these live in Danger JS's repo, or you can see
48+ the types (incoming to your process) [ DangerJSONDSLType] [ ] and (coming out from your process) [ DangerResults] [ ] ,
49+
50+ I plan to add a full reference for this, similar to the reference for the user's DSL in the future in these docs.
51+ _ Note:_ The JSON ** will include** your access token, so you probably want to sanitize that before commiting it to the
52+ repo. I accidentally shipped 2 tokens in writing the feature.
4853
4954A runner can output anything during the process to STDOUT, and it will be logged to the user. However, Danger JS is
5055listening for a JSON response in this format:
@@ -58,10 +63,6 @@ listening for a JSON response in this format:
5863}
5964```
6065
61- _ Note:_ ` "markdowns" ` is a string array, everything else is an object with message. I think this will change eventually.
62- When Danger supports inline messages, then ` "file" ` and ` "line" ` will also be supported in the violation. _ Note:_ I'd
63- like to add some sort of versioning to this.
64-
6566### Some Examples
6667
6768### Tiny, and maybe too simple
@@ -73,7 +74,7 @@ The simplest example I can give you, ironically, is a runner using Ruby.
7374
7475require ' json'
7576dsl_json = STDIN .tty? ? ' Cannot read from STDIN' : $stdin .read
76- danger = JSON .parse(dsl_json)
77+ danger = JSON .parse(dsl_json).danger
7778results = { warnings: [], messages: [], fails: [], markdowns: [] }
7879
7980if danger.github.pr.body.include? " Hello world"
@@ -97,7 +98,7 @@ to be honest - what you're probably looking to do.
9798
9899require ' json'
99100dsl_json = STDIN .tty? ? ' Cannot read from STDIN' : $stdin .read
100- danger = JSON .parse(dsl_json)
101+ danger = JSON .parse(dsl_json).danger
101102results = { warnings: [], messages: [], fails: [], markdowns: [] }
102103filename = " Dangerfile"
103104
@@ -170,6 +171,8 @@ To show you how this process works, Danger Swift takes a [JSON][swift-json] docu
170171and evaluates] [ swift-eval ] a [ Swift file] [ swift-dangerfile ] and then passes the results back to ` danger process ` via
171172[ STDOUT] [ swift-stdout ] .
172173
174+ There is also [ danger-rust] [ ] as a reference work.
175+
173176### Things You Probably Have To Do
174177
175178At least to make it shine:
@@ -206,3 +209,4 @@ Finally, let me ([@orta][]) know! I want to keep track of them all on the Danger
206209[ dangerresults ] : https://github.com/danger/danger-js/blob/master/source/dsl/DangerResults.ts
207210[ incoming ] : https://github.com/danger/danger-js/blob/master/source/danger-incoming-process-schema.json
208211[ outgoing ] : https://github.com/danger/danger-js/blob/master/source/danger-outgoing-process-schema.json
212+ [ danger-rust ] : https://github.com/danger/rust
0 commit comments