Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for the fixtures #405

Merged
merged 2 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ matrix:
include:
# Only normal CI test run :D
- node_js: '6'

- node_js: '8'
after_script:
- rm -rf node_modules/@types/babel-*
- rm -rf node_modules/@types/babylon
- yarn docs
- yarn add dtslint@0.1.2
- yarn dts-lint

# Checks every example dangerfile can run in `danger runner`.
- node_js: '8.4'
Expand Down Expand Up @@ -56,10 +63,6 @@ script:
- yarn lint
- yarn add jest
- yarn jest
- rm -rf node_modules/@types/babel-*
- rm -rf node_modules/@types/babylon
- yarn docs
- if [[ $TRAVIS_NODE_VERSION == "8" ]]; then yarn add dtslint; yarn dts-lint; fi

notifications:
slack: dangergem:9FOZou9EGBV9xO1Ol4bxRPz9
Expand Down
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
12 changes: 7 additions & 5 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 All @@ -21,7 +17,7 @@ import * as fs from "fs"

schedule(async () => {
// Request a CHANGELOG entry if not declared #trivial
const hasChangelog = danger.git.modified_files.includes("changelog.md")
const hasChangelog = danger.git.modified_files.includes("CHANGELOG.md")
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes("#trivial")
const isGreenkeeper = danger.github.pr.user.login === "greenkeeper"

Expand Down Expand Up @@ -71,3 +67,9 @@ const missing = names.filter(n => !readme.includes(n))
if (missing.length) {
warn(`These providers are missing from the README: ${sentence(missing)}`)
}

danger.github.utils.fileContents("scripts/run-fixtures.js").then(fixtures => {
if (fixtures.includes("const writeResults = true")) {
fail("Fixtures test script is still in write mode, edit `scripts/run-fixtures.js`.")
}
})
4 changes: 2 additions & 2 deletions scripts/run-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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"

// Get all the fixtures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"name": "tsconfig.json",
"path": "tsconfig.json",
"sha": "90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"size": 153,
"url": "https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=98f3e73f5e419f3af9ab928c86312f28a3c87475",
"html_url": "https://github.com/artsy/emission/blob/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json",
"git_url": "https://api.github.com/repos/artsy/emission/git/blobs/90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"download_url": "https://raw.githubusercontent.com/artsy/emission/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json",
"type": "file",
"content": "ewogICAgImNvbXBpbGVyT3B0aW9ucyI6IHsKICAgICAgICAiYWxsb3dKcyI6\nIHRydWUKICAgIH0sCiAgICAiZXhjbHVkZSI6IFsKICAgICAgICAibm9kZV9t\nb2R1bGVzIiwKICAgICAgICAiUG9kL0Fzc2V0cyIsCiAgICAgICAgIkV4YW1w\nbGUvQnVpbGQiCiAgICBdCn0K\n",
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=98f3e73f5e419f3af9ab928c86312f28a3c87475",
"git": "https://api.github.com/repos/artsy/emission/git/blobs/90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"html": "https://github.com/artsy/emission/blob/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json"
"data": {
"name": "tsconfig.json",
"path": "tsconfig.json",
"sha": "90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"size": 153,
"url":
"https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=98f3e73f5e419f3af9ab928c86312f28a3c87475",
"html_url": "https://github.com/artsy/emission/blob/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json",
"git_url": "https://api.github.com/repos/artsy/emission/git/blobs/90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"download_url":
"https://raw.githubusercontent.com/artsy/emission/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json",
"type": "file",
"content":
"ewogICAgImNvbXBpbGVyT3B0aW9ucyI6IHsKICAgICAgICAiYWxsb3dKcyI6\nIHRydWUKICAgIH0sCiAgICAiZXhjbHVkZSI6IFsKICAgICAgICAibm9kZV9t\nb2R1bGVzIiwKICAgICAgICAiUG9kL0Fzc2V0cyIsCiAgICAgICAgIkV4YW1w\nbGUvQnVpbGQiCiAgICBdCn0K\n",
"encoding": "base64",
"_links": {
"self":
"https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=98f3e73f5e419f3af9ab928c86312f28a3c87475",
"git": "https://api.github.com/repos/artsy/emission/git/blobs/90aabbabf81ac4fbc81ef1e8f40de99972b7e2ac",
"html": "https://github.com/artsy/emission/blob/98f3e73f5e419f3af9ab928c86312f28a3c87475/tsconfig.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"name": "tsconfig.json",
"path": "tsconfig.json",
"sha": "c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"size": 175,
"url": "https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"html_url": "https://github.com/artsy/emission/blob/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json",
"git_url": "https://api.github.com/repos/artsy/emission/git/blobs/c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"download_url": "https://raw.githubusercontent.com/artsy/emission/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json",
"type": "file",
"content": "ewogICAgImNvbXBpbGVyT3B0aW9ucyI6IHsKICAgICAgICAiYWxsb3dKcyI6\nIHRydWUKICAgIH0sCiAgICAiZXhjbHVkZSI6IFsKICAgICAgICAibm9kZV9t\nb2R1bGVzIiwKICAgICAgICAiUG9kL0Fzc2V0cyIsCiAgICAgICAgIkV4YW1w\nbGUvQnVpbGQiLAogICAgICAgICJleHRlcm5hbHMvIgogICAgXQp9Cg==\n",
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"git": "https://api.github.com/repos/artsy/emission/git/blobs/c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"html": "https://github.com/artsy/emission/blob/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json"
"data": {
"name": "tsconfig.json",
"path": "tsconfig.json",
"sha": "c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"size": 175,
"url":
"https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"html_url": "https://github.com/artsy/emission/blob/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json",
"git_url": "https://api.github.com/repos/artsy/emission/git/blobs/c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"download_url":
"https://raw.githubusercontent.com/artsy/emission/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json",
"type": "file",
"content":
"ewogICAgImNvbXBpbGVyT3B0aW9ucyI6IHsKICAgICAgICAiYWxsb3dKcyI6\nIHRydWUKICAgIH0sCiAgICAiZXhjbHVkZSI6IFsKICAgICAgICAibm9kZV9t\nb2R1bGVzIiwKICAgICAgICAiUG9kL0Fzc2V0cyIsCiAgICAgICAgIkV4YW1w\nbGUvQnVpbGQiLAogICAgICAgICJleHRlcm5hbHMvIgogICAgXQp9Cg==\n",
"encoding": "base64",
"_links": {
"self":
"https://api.github.com/repos/artsy/emission/contents/tsconfig.json?ref=cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75",
"git": "https://api.github.com/repos/artsy/emission/git/blobs/c7f3c3d35c0a051b874c043b5ee8d072f3c1434b",
"html": "https://github.com/artsy/emission/blob/cfa8fb80d2b65f4c4fa0b54d25352a3a0ff58f75/tsconfig.json"
}
}
}
11 changes: 5 additions & 6 deletions source/platforms/github/GitHubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ const utils = (pr: GitHubPRDSL, api: GitHub): GitHubUtilsDSL => {
repoSlug = pr.head.repo.full_name
ref = pr.head.ref
}

const data = await api.repos.getContent({
const opts = {
ref,
path,
repo: repoSlug.split("/")[1],
owner: repoSlug.split("/")[0],
})

if (data && data.type === "file") {
const buffer = new Buffer(data.content, data.encoding)
}
const response = await api.repos.getContent(opts)
if (response && response.data && response.data.type === "file") {
const buffer = new Buffer(response.data.content, response.data.encoding)
return buffer.toString()
} else {
return ""
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