Skip to content

Commit

Permalink
Adds support for getting the results back from the STDOUT of the process
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Aug 26, 2017
1 parent 2d3846f commit 5ab2e8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions scripts/danger_runner.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env ruby

puts 'Hello world'

str = STDIN.tty? ? 'Cannot read from STDIN' : $stdin.read
puts str
exit(1) unless str

# Have a dumb fake response
require 'json'
results = { fails: [], warnings: [], messages: [], markdowns: [] }.to_json

STDOUT.write(results)
11 changes: 10 additions & 1 deletion source/commands/danger-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,28 @@ async function run(): Promise<any> {
// Remove this to reduce STDOUT spam
if (dangerDSL.github && dangerDSL.github.api) {
delete dangerDSL.github.api
// Add an API token?
}

const dslJSONString = JSON.stringify(dangerDSL, null, " ") + "\n"
if (!subprocessName) {
// Just pipe it out to the CLI
process.stdout.write(dslJSONString)
} else {
const child = spawn(subprocessName)

child.stdin.write(dslJSONString)
child.stdin.end()

child.stdout.on("data", data => {
child.stdout.on("data", async data => {
console.log(`stdout: ${data}`)

data = data.toString()
const trimmed = data.trim()
if (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.includes("markdowns")) {
const results = JSON.parse(trimmed)
await exec.handleResults(results)
}
})

child.stderr.on("data", data => {
Expand Down

0 comments on commit 5ab2e8c

Please sign in to comment.