Skip to content

Commit

Permalink
Use spawn in danger local
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jun 22, 2018
1 parent e33a079 commit dfba1bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

## Master

* Convert the `exec` in `danger local` to a `spawn` hopefully unblocking large diffs from going through it - [@orta][]

# 3.7.18

* Report the error in a commit status update when in verbose - [@orta][]
Expand Down
20 changes: 12 additions & 8 deletions source/platforms/git/localGetCommits.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { debug } from "../../debug"
import * as JSON5 from "json5"

import { exec } from "child_process"
import { spawn } from "child_process"
import { GitCommit } from "../../dsl/Commit"

const d = debug("localGetDiff")
Expand All @@ -24,20 +24,24 @@ export const localGetCommits = (base: string, head: string) =>
new Promise<GitCommit[]>(done => {
const call = `git log ${base}...${head} --pretty=format:'${formatJSON}'`
d(call)
const child = spawn(call)

child.stdout.on("data", async data => {
data = data.toString()

exec(call, (err, stdout, _stderr) => {
if (err) {
console.error(`Could not get commits from git between ${base} and ${head}`)
console.error(err)
return
}
// remove trailing comma, and wrap into an array
const asJSONString = `[${stdout.substring(0, stdout.length - 1)}]`
const asJSONString = `[${data.substring(0, data.length - 1)}]`
const commits = JSON5.parse(asJSONString)
const realCommits = commits.map((c: any) => ({
...c,
parents: c.parents.split(" "),
}))

done(realCommits)
})

child.stderr.on("data", data => {
console.error(`Could not get commits from git between ${base} and ${head}`)
throw new Error(data.toString())
})
})

0 comments on commit dfba1bd

Please sign in to comment.