Skip to content

Commit

Permalink
Let the debug module use stdout instead of stderr during a hyper run
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed May 20, 2018
1 parent 4d1906b commit 0e57deb
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Master

# 3.7.2-3-4
# 3.7.2-5

* Improved debugging when using the GitHub OctoKit - orta

Expand Down
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": "3.7.3",
"version": "3.7.5",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions source/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as debug from "debug"
import { debug } from "../debug"
import * as node_fetch from "node-fetch"

const d = debug("danger:networking")
const d = debug("networking")
declare const global: any

/**
Expand Down
4 changes: 2 additions & 2 deletions source/commands/ci/reset-status.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import chalk from "chalk"
import * as debug from "debug"
import { debug } from "../../debug"

import { getPlatformForEnv } from "../../platforms/platform"
import { SharedCLI } from "../utils/sharedDangerfileArgs"
import getRuntimeCISource from "../utils/getRuntimeCISource"

import { RunnerConfig } from "./runner"

const d = debug("danger:reset-status")
const d = debug("reset-status")

export const runRunner = async (app: SharedCLI, config?: RunnerConfig) => {
d(`Starting sub-process run with ${app.args}`)
Expand Down
4 changes: 2 additions & 2 deletions source/commands/ci/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk"
import * as debug from "debug"
import { debug } from "../../debug"

import { getPlatformForEnv, Platform } from "../../platforms/platform"
import { Executor, ExecutorOptions } from "../../runner/Executor"
Expand All @@ -12,7 +12,7 @@ import { jsonDSLGenerator } from "../../runner/dslGenerator"
import dangerRunToRunnerCLI from "../utils/dangerRunToRunnerCLI"
import { CISource } from "../../ci_source/ci_source"

const d = debug("danger:process_runner")
const d = debug("process_runner")

export interface RunnerConfig {
source?: CISource
Expand Down
4 changes: 2 additions & 2 deletions source/commands/danger-pr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node

import * as program from "commander"
import * as debug from "debug"
import { debug } from "../debug"
import * as jsome from "jsome"

import { FakeCI } from "../ci_source/providers/Fake"
Expand All @@ -16,7 +16,7 @@ import { Platform, getPlatformForEnv } from "../platforms/platform"

// yarn build; cat source/_tests/fixtures/danger-js-pr-384.json | node --inspect --inspect-brk distribution/commands/danger-runner.js --text-only

const d = debug("danger:pr")
const d = debug("pr")
const log = console.log

interface App extends SharedCLI {
Expand Down
4 changes: 2 additions & 2 deletions source/commands/danger-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import getRuntimeCISource from "./utils/getRuntimeCISource"
import inlineRunner from "../runner/runners/inline"
import { jsonDSLGenerator } from "../runner/dslGenerator"

import * as debug from "debug"
const d = debug("danger:process")
import { debug } from "../debug"
const d = debug("process")

// Given the nature of this command, it can be tricky to test, so I use a command like this:
//
Expand Down
4 changes: 2 additions & 2 deletions source/commands/danger-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import setSharedArgs from "./utils/sharedDangerfileArgs"
import * as nodeCleanup from "node-cleanup"

import * as program from "commander"
import * as debug from "debug"
import { debug } from "../debug"
import * as getSTDIN from "get-stdin"
import chalk from "chalk"

import inline from "../runner/runners/inline"
import { dangerfilePath } from "./utils/file-utils"
import { jsonToContext } from "../runner/json-to-context"

const d = debug("danger:runner")
const d = debug("runner")

// Given the nature of this command, it can be tricky to test, so I use a command like this:
//
Expand Down
4 changes: 2 additions & 2 deletions source/commands/utils/runDangerSubprocess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as debug from "debug"
import { debug } from "../../debug"
import * as path from "path"
import { spawn } from "child_process"

Expand All @@ -7,7 +7,7 @@ import { Executor } from "../../runner/Executor"
import { jsonToDSL } from "../../runner/jsonToDSL"
import { markdownCode, resultsWithFailure, mergeResults } from "./reporting"

const d = debug("danger:runDangerSubprocess")
const d = debug("runDangerSubprocess")

// Sanitizes the DSL so for sending via STDOUT
export const prepareDangerDSL = (dangerDSL: DangerDSLJSONType) => {
Expand Down
11 changes: 11 additions & 0 deletions source/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as debugModule from "debug"

export const debug = (value: string) => {
const d = debugModule(`danger:${value}`)
// In Peril, when running inside Hyper, we don't get access to stderr
// so bind debug to use stdout
if (process.env.x_hyper_content_sha256) {
d.log = console.log.bind(console)
}
return d
}
4 changes: 2 additions & 2 deletions source/platforms/BitBucketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { BitBucketServerAPI } from "./bitbucket_server/BitBucketServerAPI"
import gitDSLForBitBucketServer from "./bitbucket_server/BitBucketServerGit"
import { Platform, Comment } from "./platform"

import * as debug from "debug"
import { debug } from "../debug"

/** Handles conforming to the Platform Interface for BitBucketServer, API work is handle by BitBucketServerAPI */

export class BitBucketServer implements Platform {
private readonly d = debug("danger:BitBucketServer")
private readonly d = debug("BitBucketServer")
name: string

constructor(public readonly api: BitBucketServerAPI) {
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/bitbucket_server/BitBucketServerAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as debug from "debug"
import { debug } from "../../debug"
import * as node_fetch from "node-fetch"
import * as v from "voca"

Expand Down Expand Up @@ -41,7 +41,7 @@ export function bitbucketServerRepoCredentialsFromEnv(env: Env): BitBucketRepoCr

export class BitBucketServerAPI {
fetch: typeof fetch
private readonly d = debug("danger:BitBucketServerAPI")
private readonly d = debug("BitBucketServerAPI")

private pr: BitBucketServerPRDSL

Expand Down
4 changes: 2 additions & 2 deletions source/platforms/bitbucket_server/BitBucketServerGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { BitBucketServerAPI } from "../bitbucket_server/BitBucketServerAPI"

import { GitJSONToGitDSLConfig, gitJSONToGitDSL, GitStructuredDiff } from "../git/gitJSONToGitDSL"

import * as debug from "debug"
const d = debug("danger:BitBucketServerGit")
import { debug } from "../../debug"
const d = debug("BitBucketServerGit")

/**
* Returns the response for the new comment
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/git/localGetCommits.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as debug from "debug"
import { debug } from "../../debug"
import * as JSON5 from "json5"

import { exec } from "child_process"
import { GitCommit } from "../../dsl/Commit"

const d = debug("danger:localGetDiff")
const d = debug("localGetDiff")

const sha = "%H"
const parents = "%p"
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/git/localGetDiff.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as debug from "debug"
import { debug } from "../../debug"
import { exec } from "child_process"

const d = debug("danger:localGetDiff")
const d = debug("localGetDiff")

export const localGetDiff = (base: string, head: string) =>
new Promise<string>(done => {
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/git/localGetFileAtSHA.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as debug from "debug"
import { debug } from "../../debug"
import { exec } from "child_process"

const d = debug("danger:localGetFileAtSHA")
const d = debug("localGetFileAtSHA")

export const localGetFileAtSHA = (path: string, _repo: string | undefined, sha: string) =>
new Promise<string>(done => {
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as GitHubNodeAPI from "@octokit/rest"
import * as debug from "debug"
import { debug } from "../../debug"
import * as node_fetch from "node-fetch"
import * as parse from "parse-link-header"
import * as v from "voca"
Expand All @@ -26,7 +26,7 @@ const limit = pLimit(25)
export class GitHubAPI {
fetch: typeof fetch
additionalHeaders: any
private readonly d = debug("danger:GitHubAPI")
private readonly d = debug("GitHubAPI")

private pr: GitHubPRDSL

Expand Down
4 changes: 2 additions & 2 deletions source/platforms/github/GitHubGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { GitHubAPI } from "../github/GitHubAPI"
import { diffToGitJSONDSL } from "../git/diffToGitJSONDSL"
import { GitJSONToGitDSLConfig, gitJSONToGitDSL } from "../git/gitJSONToGitDSL"

import * as debug from "debug"
const d = debug("danger:GitHubGit")
import { debug } from "../../debug"
const d = debug("GitHubGit")

/**
* Returns the response for the new comment
Expand Down
6 changes: 3 additions & 3 deletions source/platforms/github/comms/issueCommenter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GitDSL } from "../../../dsl/GitDSL"
import { GitHubAPI } from "../GitHubAPI"
import * as debug from "debug"
import { debug } from "../../../debug"
import { Comment } from "../../platform"

const d = debug("danger:GitHub::Issue")
const d = debug("GitHub::Issue")

/**
* Finds a position in given diff. This is needed for GitHub API, more on the position finder
Expand Down Expand Up @@ -46,7 +46,7 @@ export const findPositionForInlineComment = (git: GitDSL, line: number, path: st
* @param api
*/
export const GitHubIssueCommenter = (api: GitHubAPI) => {
const d = debug("danger:GitHub::Issue")
const d = debug("GitHub::Issue")

return {
supportsCommenting: () => true,
Expand Down
4 changes: 2 additions & 2 deletions source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from "./templates/bitbucketServerTemplate"
import exceptionRaisedTemplate from "./templates/exceptionRaisedTemplate"

import * as debug from "debug"
import { debug } from "../debug"
import chalk from "chalk"
import { sentence, href } from "./DangerUtils"
import { DangerRunner } from "./runners/runner"
Expand All @@ -50,7 +50,7 @@ export interface ExecutorOptions {
// This is still badly named, maybe it really should just be runner?

export class Executor {
private readonly d = debug("danger:executor")
private readonly d = debug("executor")

constructor(
public readonly ciSource: CISource,
Expand Down
4 changes: 2 additions & 2 deletions source/runner/runners/inline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs"

import * as debug from "debug"
import { debug } from "../../debug"
import * as _require from "require-from-string"

import { DangerResults, DangerRuntimeContainer } from "../../dsl/DangerResults"
Expand All @@ -12,7 +12,7 @@ import compile from "./utils/transpiler"
import cleanDangerfile from "./utils/cleanDangerfile"
import resultsForCaughtError from "./utils/resultsForCaughtError"

const d = debug("danger:inline_runner")
const d = debug("inline_runner")

/**
* Executes a Dangerfile at a specific path, with a context.
Expand Down
4 changes: 2 additions & 2 deletions source/runner/runners/utils/transpiler.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as fs from "fs"
import * as path from "path"
import * as JSON5 from "json5"
import * as debug from "debug"
import { debug } from "../../../debug"

let hasNativeTypeScript = false
let hasBabel = false
let hasBabelTypeScript = false
let hasFlow = false
let hasChecked = false

const d = debug("danger:transpiler:setup")
const d = debug("transpiler:setup")

// Yes, lots of linter disables, but I want to support TS/Babel/Neither correctly
export const checkForNodeModules = () => {
Expand Down

0 comments on commit 0e57deb

Please sign in to comment.