Skip to content

Commit

Permalink
Pass danger DSL to results handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinejr committed Feb 25, 2018
1 parent 7236c02 commit 127fa2d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
6 changes: 2 additions & 4 deletions source/commands/ci/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as debug from "debug"

import { getPlatformForEnv, Platform } from "../../platforms/platform"
import { Executor, ExecutorOptions } from "../../runner/Executor"
import runDangerSubprocess, { prepareDangerDSL } from "../utils/runDangerSubprocess"
import runDangerSubprocess from "../utils/runDangerSubprocess"
import { SharedCLI } from "../utils/sharedDangerfileArgs"
import getRuntimeCISource from "../utils/getRuntimeCISource"

Expand Down Expand Up @@ -50,13 +50,11 @@ export const runRunner = async (app: SharedCLI, config?: RunnerConfig) => {
dangerID: app.id || "default",
}

const processInput = prepareDangerDSL(dangerJSONDSL)

const runnerCommand = dangerRunToRunnerCLI(process.argv)
d(`Preparing to run: ${runnerCommand}`)

const exec = new Executor(source, platform, inlineRunner, config)
runDangerSubprocess(runnerCommand, processInput, exec)
runDangerSubprocess(runnerCommand, dangerJSONDSL, exec)
}
}
}
5 changes: 2 additions & 3 deletions source/commands/danger-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ getRuntimeCISource(app).then(source => {
}

jsonDSLGenerator(platform).then(dangerJSONDSL => {
const processInput = prepareDangerDSL(dangerJSONDSL)

if (!subprocessName) {
// Just pipe it out to the CLI
const processInput = prepareDangerDSL(dangerJSONDSL)
process.stdout.write(processInput)
} else {
const exec = new Executor(source, platform, inlineRunner, config)
runDangerSubprocess([subprocessName], processInput, exec)
runDangerSubprocess([subprocessName], dangerJSONDSL, exec)
}
})
}
Expand Down
7 changes: 5 additions & 2 deletions source/commands/utils/runDangerSubprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { spawn } from "child_process"

import { DangerDSLJSONType, DangerJSON } from "../../dsl/DangerDSL"
import { Executor } from "../../runner/Executor"
import { jsonToDSL } from "../../runner/jsonToDSL"
import { markdownCode, resultsWithFailure, mergeResults } from "./reporting"

const d = debug("danger:runDangerSubprocess")
Expand All @@ -19,13 +20,14 @@ export const prepareDangerDSL = (dangerDSL: DangerDSLJSONType) => {
}

// Runs the Danger process, can either take a simpl
const runDangerSubprocess = (subprocessName: string[], dslJSONString: string, exec: Executor) => {
const runDangerSubprocess = (subprocessName: string[], dslJSON: DangerDSLJSONType, exec: Executor) => {
let processName = subprocessName[0]
let args = subprocessName
let results = {} as any
args.shift() // mutate and remove the first element

const processDisplayName = path.basename(processName)
const dslJSONString = prepareDangerDSL(dslJSON)
d(`Running subprocess: ${processDisplayName} - ${args}`)
const child = spawn(processName, args, { env: process.env })
let allLogs = ""
Expand Down Expand Up @@ -65,7 +67,8 @@ const runDangerSubprocess = (subprocessName: string[], dslJSONString: string, ex
results = failResults
}
}
await exec.handleResults(results)
const danger = await jsonToDSL(dslJSON)
await exec.handleResults(results, danger)
})
}

Expand Down
4 changes: 0 additions & 4 deletions source/runner/Dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ export interface DangerContext {
* @param {DangerDSLType} dsl The DSL which is turned into `danger`
* @returns {DangerContext} a DangerContext-like API
*/
/// PULL DO WZOROWANIA SIE: https://github.com/danger/danger-js/pull/99/files
/// DOKUMENTACJA: https://danger.systems/js/usage/danger-process.html
/// TU JESTES. POTRZEBUJESZ TESTÓW KTÓRE SPRAWDZAJA CZY PARSUJE SIE CONTEXT Z NOWYMI MODELAMI VIOLATION
/// POTEM ROBISZ TEST ZE JAK DOSTAJESZ JSONA Z NOWYM MODELEM TO SIE PARSUJE I DODAJE NA GITHUBA
export function contextForDanger(dsl: DangerDSLType): DangerContext {
const results: DangerRuntimeContainer = {
fails: [],
Expand Down
10 changes: 5 additions & 5 deletions source/runner/Executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { contextForDanger, DangerContext } from "./Dangerfile"
import { DangerDSL } from "../dsl/DangerDSL"
import { DangerDSL, DangerDSLType } from "../dsl/DangerDSL"
import { CISource } from "../ci_source/ci_source"
import { Platform } from "../platforms/platform"
import { DangerResults } from "../dsl/DangerResults"
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Executor {
results = this.resultsForError(error)
}

await this.handleResults(results)
await this.handleResults(results, runtime.danger)
return results
}

Expand All @@ -96,12 +96,12 @@ export class Executor {
*
* @param {DangerResults} results a JSON representation of the end-state for a Danger run
*/
async handleResults(results: DangerResults) {
async handleResults(results: DangerResults, danger: DangerDSLType) {
this.d(`Got Results back, current settings`, this.options)
if (this.options.stdoutOnly || this.options.jsonOnly) {
this.handleResultsPostingToSTDOUT(results)
} else {
this.handleResultsPostingToPlatform(results)
this.handleResultsPostingToPlatform(results, danger)
}
}
/**
Expand Down Expand Up @@ -161,7 +161,7 @@ export class Executor {
*
* @param {DangerResults} results a JSON representation of the end-state for a Danger run
*/
async handleResultsPostingToPlatform(results: DangerResults) {
async handleResultsPostingToPlatform(results: DangerResults, danger: DangerDSLType) {
// Delete the message if there's nothing to say
const { fails, warnings, messages, markdowns } = results

Expand Down

0 comments on commit 127fa2d

Please sign in to comment.