Skip to content

Commit 9b4fc81

Browse files
committed
Updates the process docs, exposes a duplicate danger-js command and prepares for release
1 parent 2ea1ca9 commit 9b4fc81

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
## Master
1515

16+
# 6.1.3
17+
1618
- Add support for personal tokens of BitBucket Server - [@langovoi][]
19+
- Ships a command `danger-js` which means other languages could also use the command danger and they won't conflict with
20+
the JS version - [@orta][]
1721

1822
# 6.1.2
1923

docs/usage/danger-process.html.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2830
You can preview the DSL which will be sent to your process via `danger pr` with the `--js` and `--json` flags, for
2931
example:
@@ -32,19 +34,22 @@ example:
3234
danger 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
3941
danger pr https://github.com/danger/danger-js/pull/395 --json > danger-js-395.dsl.json
4042
```
4143

4244
This 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

4954
A runner can output anything during the process to STDOUT, and it will be logged to the user. However, Danger JS is
5055
listening 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

7475
require 'json'
7576
dsl_json = STDIN.tty? ? 'Cannot read from STDIN' : $stdin.read
76-
danger = JSON.parse(dsl_json)
77+
danger = JSON.parse(dsl_json).danger
7778
results = { warnings: [], messages:[], fails: [], markdowns: [] }
7879

7980
if danger.github.pr.body.include? "Hello world"
@@ -97,7 +98,7 @@ to be honest - what you're probably looking to do.
9798

9899
require 'json'
99100
dsl_json = STDIN.tty? ? 'Cannot read from STDIN' : $stdin.read
100-
danger = JSON.parse(dsl_json)
101+
danger = JSON.parse(dsl_json).danger
101102
results = { warnings: [], messages:[], fails: [], markdowns: [] }
102103
filename = "Dangerfile"
103104

@@ -170,6 +171,8 @@ To show you how this process works, Danger Swift takes a [JSON][swift-json] docu
170171
and 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

175178
At 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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"typings": "distribution/danger.d.ts",
77
"bin": {
88
"danger": "distribution/commands/danger.js",
9+
"danger-js": "distribution/commands/danger.js",
910
"danger-pr": "distribution/commands/danger-pr.js",
1011
"danger-runner": "distribution/commands/danger-runner.js",
1112
"danger-process": "distribution/commands/danger-process.js",

0 commit comments

Comments
 (0)