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 dfba1bd commit c320382
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
1 change: 0 additions & 1 deletion source/commands/danger-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface App extends SharedCLI {

program
.usage("[options]")
.option("-b, --base [base]", "Choose the base commit to work against.")
// TODO: this option
// .option("-s, --staging", "Just use staged changes.")
.description("Runs danger without PR metadata, useful for git hooks.")
Expand Down
7 changes: 3 additions & 4 deletions source/platforms/git/localGetCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export const formatJSON = `{ "sha": "${sha}", "parents": "${parents}", ${author}

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)

const args = ["log", `${base}...${head}`, `--pretty=format:${formatJSON}`]
const child = spawn("git", args, { env: process.env })
d("> git", args.join(" "))
child.stdout.on("data", async data => {
data = data.toString()

Expand Down
22 changes: 12 additions & 10 deletions source/platforms/git/localGetDiff.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { debug } from "../../debug"
import { exec } from "child_process"
import { spawn } from "child_process"

const d = debug("localGetDiff")

export const localGetDiff = (base: string, head: string) =>
new Promise<string>(done => {
const call = `git diff ${base}...${head}`
d(call)
const args = ["diff", `${base}...${head}`]

exec(call, (err, stdout, _stderr) => {
if (err) {
console.error(`Could not get diff from git between ${base} and ${head}`)
console.error(err)
return
}
const child = spawn("git", args, { env: process.env })
d("> git", args.join(" "))

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

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

0 comments on commit c320382

Please sign in to comment.