From d2e0a70281c1633843134b80bd40f9f12c0249c2 Mon Sep 17 00:00:00 2001 From: orta Date: Fri, 30 Dec 2016 16:02:09 -0500 Subject: [PATCH] Improves logging --- .vscode/launch.json | 10 +++++++--- changelog.md | 8 ++++---- dangerfile.js | 3 +-- env/development.env.example | 2 ++ package.json | 2 +- source/api/fetch.js | 20 +++++++++++++++++++- source/commands/danger-run.js | 8 ++++++-- source/runner/_tests/DangerRunner.test.js | 1 + 8 files changed, 41 insertions(+), 13 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c21b4cc1e..0bd6102cb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,7 @@ "name": "Launch Run", "type": "node", "request": "launch", - "program": "${workspaceRoot}/source/commands/danger-run.js", + "program": "${workspaceRoot}/distribution/commands/danger-run.js", "stopOnEntry": false, "args": [], "envFile": "${workspaceRoot}/env/development.env", @@ -19,7 +19,9 @@ }, "console": "internalConsole", "sourceMaps": true, - "outDir": "${workspaceRoot}/distribution" + "outFiles": [ + "${workspaceRoot}/distribution" + ] }, { "name": "Launch Local", @@ -39,7 +41,9 @@ }, "console": "internalConsole", "sourceMaps": true, - "outDir": "${workspaceRoot}/distribution" + "outFiles": [ + "${workspaceRoot}/distribution" + ], }, { "name": "Run Tests With Debugger (slower, use npm run watch for normal work)", "type": "node", diff --git a/changelog.md b/changelog.md index f62134e13..1a4eda7be 100644 --- a/changelog.md +++ b/changelog.md @@ -2,12 +2,12 @@ // Add your own contribution below -### 0.7.4 +* Adds `--verbose` to `danger`, which for now will echo out all the URLs Danger has requested - orta +* A failing network request will raise an error - orta -* Fix Dangerfile parsing which broke due to Peril related changes - orta - -### 0.7.3 +### 0.7.3-4 +* Fix Dangerfile parsing which broke due to Peril related changes - orta * Tweak the npmignore, ship less random stuff to others - orta ### 0.7.2 diff --git a/dangerfile.js b/dangerfile.js index ca8b45c04..948cdbdab 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -2,7 +2,6 @@ // import { danger, warn } from "danger" import fs from "fs" -console.log("Hello world") // Request a CHANGELOG entry const hasChangelog = danger.git.modified_files.includes("changelog.md") @@ -21,7 +20,7 @@ const jsFiles = danger.git.created_files.filter(path => path.endsWith("js")) // but exclude tests from being flow-ey const unFlowedFiles = jsFiles.filter(path => !path.endsWith("test.js")) .filter(filepath => { - const content = fs.readFileSync(filepath) + const content = fs.readFileSync(filepath).toString() return !content.includes("@flow") }) diff --git a/env/development.env.example b/env/development.env.example index 51bf15b97..b867eaa60 100644 --- a/env/development.env.example +++ b/env/development.env.example @@ -2,3 +2,5 @@ DANGER_FAKE_CI="sure" DANGER_TEST_REPO="artsy/emission" DANGER_TEST_PR="327" DANGER_GITHUB_API_TOKEN="123456789123456789123456789" +DANGER_VERBOSE="aye" +DANGER_VERBOSE_SHOW_TOKEN="yep" diff --git a/package.json b/package.json index bbcd4c98f..605a097aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "0.7.3", + "version": "0.7.4", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "bin": { diff --git a/source/api/fetch.js b/source/api/fetch.js index ef9807f5a..9f572da56 100644 --- a/source/api/fetch.js +++ b/source/api/fetch.js @@ -15,9 +15,17 @@ export default function api(url: string | fetch.Request, init?: fetch.RequestIni output.push(`-X ${init.method}`) } + const showToken = process.env["DANGER_VERBOSE_SHOW_TOKEN"] + const token = process.env["DANGER_GITHUB_API_TOKEN"] + if (init.headers) { for (const prop in init.headers) { if (init.headers.hasOwnProperty(prop)) { + // Don't show the token for normal verbose usage + if (init.headers[prop].includes(token) && !showToken) { + output.push("-H", `"${prop}: [API TOKEN]"`) + continue + } output.push("-H", `"${prop}: ${init.headers[prop]}"`) } } @@ -32,8 +40,18 @@ export default function api(url: string | fetch.Request, init?: fetch.RequestIni output.push(url) } - console.log(output.join(" ")) // tslint:disable-line + console.log(output.join(" ")) } return fetch(url, init) + .then(response => { + // Handle failing errors + if (!response.ok) { + process.exitCode = 1 + console.error(`Request failed: ${response}`) + var msg = response.status === 0 ? "Network Error" : response.statusText + throw new Error(response.status, msg, {response: response}) + } + return response + }) } diff --git a/source/commands/danger-run.js b/source/commands/danger-run.js index 782bafd49..f0b76b49e 100755 --- a/source/commands/danger-run.js +++ b/source/commands/danger-run.js @@ -1,14 +1,14 @@ // @flow import "babel-polyfill" -var program = require("commander") +var program: any = require("commander") import { getCISourceForEnv } from "../ci_source/ci_source" import { getPlatformForEnv } from "../platforms/platform" import Executor from "../runner/Executor" program - .option("-f, --fail-on-errors", "TODO: Fail on errors") + .option("-v, --verbose", "Verbose output of files") .parse(process.argv) process.on("unhandledRejection", function(reason: string, p: any) { @@ -16,6 +16,10 @@ process.on("unhandledRejection", function(reason: string, p: any) { process.exitCode = 1 }) +if (process.env["DANGER_VERBOSE"] || program.verbose) { + global.verbose = true +} + const source = getCISourceForEnv(process.env) if (!source) { console.log("Could not find a CI source for this run") diff --git a/source/runner/_tests/DangerRunner.test.js b/source/runner/_tests/DangerRunner.test.js index bcdaa83d7..4f8dde4fa 100644 --- a/source/runner/_tests/DangerRunner.test.js +++ b/source/runner/_tests/DangerRunner.test.js @@ -93,3 +93,4 @@ describe("cleaning Dangerfiles", () => { expect(cleanDangerfile(before)).toEqual("// import danger from 'danger'") }) }) +