Skip to content

Commit

Permalink
Merge pull request #601 from danger/add_update_issue
Browse files Browse the repository at this point in the history
Add update issue
  • Loading branch information
orta authored May 21, 2018
2 parents 5c35282 + 0ead1bb commit 3c64123
Show file tree
Hide file tree
Showing 32 changed files with 232 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ matrix:
# DEBUG="*" danger ci --verbose;
# else
# echo "This is the real `danger ci` run on this repo, using github checks with a custom app";
# DEBUG="*" DANGER_GITHUB_APP_ID=12229 danger ci --verbose;
# DEBUG="*" DANGER_GITHUB_APP_ID=12482 danger ci --verbose;
#
# echo "This is the real `danger ci` run on this repo, using github checks with the danger app";
# DEBUG="*" DANGER_JS_APP_INSTALL_ID=177994 danger ci --verbose;
# fi

- DEBUG="*" DANGER_GITHUB_APP_ID=12229 danger ci --verbose;
- DEBUG="*" DANGER_GITHUB_APP_ID=12482 danger ci --verbose;

- echo "Validating that danger pr works as expected"
- DEBUG="*" danger pr https://github.com/danger/danger-js/pull/465 --dangerfile dangerfile.circle.js --verbose
Expand Down
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@

## Master

# 3.7.2
# 3.7.2-11

* Debugging when using the GitHub OctoKit - orta
* Improved debugging when using the GitHub OctoKit - [@orta][]
* Added `danger.github.utils.createUpdatedIssueWithID` which can be used to have danger continually update a single
issue in a repo, for example:

```ts
await danger.github.utils.createUpdatedIssueWithID("TestID", "Hello World", {
title: "My First Issue",
open: true,
repo: "sandbox",
owner: "PerilTest",
})
```

Will first create, then update that issue with a new body. - [@orta][]

# 3.7.1

Expand Down
24 changes: 17 additions & 7 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// This means we can re-use the type infra from the app, without having to
// fake the import.

import yarn from "danger-plugin-yarn"
import jest from "danger-plugin-jest"

import { DangerDSLType } from "./source/dsl/DangerDSL"
declare var danger: DangerDSLType
// declare var results: any
Expand All @@ -13,7 +16,7 @@ declare function warn(message: string, file?: string, line?: number): void
// declare function schedule(promise: () => Promise<any | void>): void
// declare function schedule(callback: (resolve: any) => void): void

const checkREADME = async () => {
export default async () => {
if (!danger.github) {
return
}
Expand All @@ -31,14 +34,21 @@ const checkREADME = async () => {
warn("Please add your GitHub name to the changelog entry, so we can attribute you correctly.")
}
}
}
checkREADME()

import yarn, { message } from "danger-plugin-yarn"
yarn()
// Some libraries
await yarn()
await jest()

import jest from "danger-plugin-jest"
jest()
// The thing I'm testing
await danger.github.utils.createUpdatedIssueWithID("TestID", "Hello World 32", {
title: "My First Issue",
open: true,
repo: "sandbox",
owner: "PerilTest",
})
}

warn("I should be in the checks")

// Re-run the git push hooks
import "./dangerfile.lite"
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.2",
"version": "3.7.11",
"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
19 changes: 18 additions & 1 deletion source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ declare module "danger" {

/**
* When running a task, the data passed in when the task
* was originally scheduled.
* was originally scheduled, you can also get this as the first
* argument in a default function.
*/
data?: any
}
Expand Down Expand Up @@ -728,6 +729,22 @@ declare module "danger" {
* @param {string} ref An optional reference to a branch/sha
*/
fileContents(path: string, repoSlug?: string, ref?: string): Promise<string>

/**
* An API for creating, updating and closing an issue. Basically
* this is really useful for reporting back via a separate
* issue that you may want to keep up to date at all times.
*
* @param {string} id The unique ID for the message to create, close
* @param {string} content the content of the message
* @param {any} config settings for the issue
* @returns {string} A HTML string of <a>'s built as a sentence.
*/
createUpdatedIssueWithID: (
id: string,
content: string,
config: { title: string; open: boolean; owner: string; repo: string }
) => Promise<string>
}

/**
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
}
3 changes: 2 additions & 1 deletion source/dsl/DangerDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export interface PerilDSL {

/**
* When running a task, the data passed in when the task
* was originally scheduled.
* was originally scheduled, you can also get this as the first
* argument in a default function.
*/
data?: any
}
Expand Down
16 changes: 16 additions & 0 deletions source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ export interface GitHubUtilsDSL {
* @param {string} ref An optional reference to a branch/sha
*/
fileContents(path: string, repoSlug?: string, ref?: string): Promise<string>

/**
* An API for creating, updating and closing an issue. Basically
* this is really useful for reporting back via a separate
* issue that you may want to keep up to date at all times.
*
* @param {string} id The unique ID for the message to create, close
* @param {string} content the content of the message
* @param {any} config settings for the issue
* @returns {string} A HTML string of <a>'s built as a sentence.
*/
createUpdatedIssueWithID: (
id: string,
content: string,
config: { title: string; open: boolean; owner: string; repo: string }
) => Promise<string>
}

/**
Expand Down
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
Loading

0 comments on commit 3c64123

Please sign in to comment.