Skip to content

Commit

Permalink
Add a CHANGELOG entry about the fixes to danger.github.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 27, 2017
1 parent 7b15835 commit 61982da
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

// ### Master

### 2.0.0-beta.2

- Fixes a bug with `danger.github.utils` in that it didn't work as of b1, and now it does :+1: - [@orta][]

### 2.0.0-beta.1

- Converts the command `danger` (and `danger run`) to use `danger process` under the hood. What does this do?
Expand Down
7 changes: 0 additions & 7 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// This means we can re-use the type infra from the app, without having to
// fake the import.

// console.log(global)
// console.log(require)
// console.log(require.extensions)

import { DangerDSLType } from "./source/dsl/DangerDSL"
declare var danger: DangerDSLType
// declare var results: any
Expand Down Expand Up @@ -72,10 +68,7 @@ if (missing.length) {
warn(`These providers are missing from the README: ${sentence(missing)}`)
}

console.log("before")
danger.github.utils.fileContents("scripts/run-fixtures.js").then(fixtures => {
console.log("after")
console.log(fixtures)
if (fixtures.includes("const writeResults = true")) {
fail("Fixtures test script is still in write mode, edit `scripts/run-fixtures.js`.")
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const chalk = require("chalk")
const expect = require("expect")

// Toggle this on to update the JSON files for each run
const writeResults = true
const writeResults = false
console.log("If this script fails, you probably want to update the fixtures - just edit script/run-fixtures.js")
const runnerFileJS = "distribution/commands/danger-runner.js"

Expand Down
24 changes: 23 additions & 1 deletion source/runner/runners/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs"

import * as _require from "require-from-string"

import { DangerResults } from "../../dsl/DangerResults"
import { DangerResults, DangerRuntimeContainer } from "../../dsl/DangerResults"
import { DangerContext } from "../../runner/Dangerfile"

import { DangerRunner } from "./runner"
Expand Down Expand Up @@ -66,6 +66,11 @@ export async function runDangerfileEnvironment(

_require(compiled, filename, {})

// Don't stop all current async code from breaking,
// however new code (without Peril support) can run
// without the scheduler
await runAllScheduledTasks(environment.results)

return environment.results
} catch (error) {
console.error("Unable to evaluate the Dangerfile")
Expand All @@ -74,6 +79,23 @@ export async function runDangerfileEnvironment(
}
}

const runAllScheduledTasks = async (results: DangerRuntimeContainer) => {
if (results.scheduled) {
await Promise.all(
results.scheduled.map((fnOrPromise: any) => {
if (fnOrPromise instanceof Promise) {
return fnOrPromise
}
if (fnOrPromise.length === 1) {
// callback-based function
return new Promise(res => fnOrPromise(res))
}
return fnOrPromise()
})
)
}
}

const defaultExport: DangerRunner = {
createDangerfileRuntimeEnvironment,
runDangerfileEnvironment,
Expand Down

0 comments on commit 61982da

Please sign in to comment.