Skip to content

Commit

Permalink
Improves logging
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Dec 30, 2016
1 parent 14064de commit d2e0a70
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
10 changes: 7 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,7 +19,9 @@
},
"console": "internalConsole",
"sourceMaps": true,
"outDir": "${workspaceRoot}/distribution"
"outFiles": [
"${workspaceRoot}/distribution"
]
},
{
"name": "Launch Local",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
})

Expand Down
2 changes: 2 additions & 0 deletions env/development.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
20 changes: 19 additions & 1 deletion source/api/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"`)
}
}
Expand All @@ -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
})
}
8 changes: 6 additions & 2 deletions source/commands/danger-run.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// @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) {
console.log("Error: ", reason)
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")
Expand Down
1 change: 1 addition & 0 deletions source/runner/_tests/DangerRunner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ describe("cleaning Dangerfiles", () => {
expect(cleanDangerfile(before)).toEqual("// import danger from 'danger'")
})
})

0 comments on commit d2e0a70

Please sign in to comment.