Skip to content

Commit

Permalink
Imprve the logging around the JSON being sent across processes
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 8, 2018
1 parent 1e722ef commit 0b78db4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ matrix:

- echo "Validating that danger pr works as expected"
- DEBUG="*" danger pr https://github.com/danger/danger-js/pull/465 --dangerfile dangerfile.circle.js --verbose

- echo "Validating that danger local works as expected"
- git fetch origin master
- git diff master...HEAD
- DEBUG="*" danger local --dangerfile source/platforms/git/_tests/local_dangerfile_example.ts

# Create some fake projects at runtime
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

## Master

# 3.7.20

* Logging / verification improvements for the subprocess - [@orta][]

# 3.7.19

* Convert the `exec` in `danger local` to a `spawn` hopefully unblocking large diffs from going through it -
Expand Down
4 changes: 2 additions & 2 deletions docs/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If this is a support request, e.g:

* How do I ...?
* Does Danger support ...?
* Is there a pluging for ...?
* Is there a plugin for ...?

Please use https://spectrum.chat/danger

Expand All @@ -15,4 +15,4 @@ If this issue feels like:
* I didn't expect that Danger would ...
* Should I create a PR for ...

Then you're in the right place :+1:
Then you're in the right place :+1:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "3.7.19",
"version": "3.7.20",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion source/commands/danger-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import chalk from "chalk"
import inline from "../runner/runners/inline"
import { dangerfilePath } from "./utils/file-utils"
import { jsonToContext } from "../runner/json-to-context"
import { DangerResults } from "../dsl/DangerResults"

const d = debug("runner")

Expand Down Expand Up @@ -54,9 +55,15 @@ const run = async (jsonString: string) => {
// only post the results when the process has succeeded, leaving the
// host process to create a message from the logs.
nodeCleanup((exitCode: number, signal: string) => {
const results: DangerResults = runtimeEnv.results
d(`Process has finished with ${exitCode} ${signal}, sending the results back to the host process`)
d(
`Got md ${results.markdowns.length} w ${results.warnings.length} f ${results.fails.length} m ${
results.messages.length
}`
)
if (foundDSL) {
process.stdout.write(JSON.stringify(runtimeEnv.results, null, 2))
process.stdout.write(JSON.stringify(results, null, 2))
}
})

Expand Down
10 changes: 8 additions & 2 deletions source/commands/utils/runDangerSubprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ const runDangerSubprocess = (subprocessName: string[], dslJSON: DangerDSLJSONTyp
child.stdout.on("data", async data => {
data = data.toString()
const trimmed = data.trim()
if (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.includes("markdowns")) {
d("Got JSON results from STDOUT")
if (
trimmed.startsWith("{") &&
trimmed.endsWith("}") &&
trimmed.includes("markdowns") &&
trimmed.includes("fails") &&
trimmed.includes("warnings")
) {
d("Got JSON results from STDOUT, results: \n" + trimmed)
results = JSON.parse(trimmed)
} else {
console.log(`${data}`)
Expand Down
6 changes: 2 additions & 4 deletions source/dsl/DangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export function validateResults(results: DangerResults) {
const officialAPI = ["message", "line", "file"]
const keys = Object.keys(v).filter(f => !officialAPI.includes(f))
if (keys.length) {
console.warn(
`Recieved unexpected key in Violation, expected only ${officialAPI} but recieved ${Object.keys(v)}`
)
console.warn(`Received unexpected key in Violation, expected only ${officialAPI} but got ${Object.keys(v)}`)
}
})
})
Expand All @@ -116,7 +114,7 @@ export function inlineResults(results: DangerResults): DangerResults {
}
}

/** Returns only the main-comment commentsviolations from Danger results */
/** Returns only the main-comment comments violations from Danger results */
export function regularResults(results: DangerResults): DangerResults {
return {
fails: results.fails.filter(m => !isInline(m)),
Expand Down

0 comments on commit 0b78db4

Please sign in to comment.