Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed May 15, 2018
2 parents 077db14 + d86b1f0 commit 6105752
Show file tree
Hide file tree
Showing 20 changed files with 253 additions and 134 deletions.
18 changes: 10 additions & 8 deletions .travis.yml
Expand Up @@ -7,9 +7,10 @@ cache:

matrix:
include:
# Only normal CI test run :D
# Normal CI test runs :D
- node_js: '6'

- node_js: '10'

- node_js: '8'
after_script:
- rm -rf node_modules/@types/babel-*
Expand All @@ -35,13 +36,14 @@ matrix:
- yarn run link

# If the PR is odd then run using issue commenting, else use checks
- if [ $(($TRAVIS_PULL_REQUEST % 2)) -eq 0 ]
- |
if [ $(($TRAVIS_PULL_REQUEST % 2)) -eq 0 ];
then
echo "This is the real `danger ci` run on this repo, using issues"
DEBUG="*" danger ci --verbose
echo "This is the real `danger ci` run on this repo, using issues";
DEBUG="*" danger ci --verbose;
else
echo "This is the real `danger ci` run on this repo, using github checks"
DEBUG="*" DANGER_GITHUB_APP_ID=12229 danger ci --verbose
echo "This is the real `danger ci` run on this repo, using github checks";
DEBUG="*" DANGER_GITHUB_APP_ID=12229 danger ci --verbose;
fi

- echo "Validating that danger pr works as expected"
Expand All @@ -53,7 +55,7 @@ matrix:
- node_js: '7'
script:
- echo "This is only for Integration tests on two blank projects"
- yarn build
getReviewInfo = (): Promise<GitHubPRDSL> => this.api.getPullRequestInfo() - yarn build
- mkdir danger_blank_test
- cd danger_blank_test
- yarn init --yes
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,14 @@

* Adds support for the GH Checks API [notes to come][@orta][]
* JSON diffs use the JSON5 parser, so can now ignore comments in JSON etc [@orta][]
* Allows the synchronous execution of multiple dangerfiles in one single "danger run".

Not a particularly useful feature for Danger-JS, but it means Peril can combine many runs into a single execution
unit. This means people only get 1 message. [@orta][]

# 3.6.6

* Updates vm2 to be an npm published version [@orta][]

# 3.6.5

Expand Down Expand Up @@ -184,6 +192,7 @@
* Improvements to the Flow definition file. [@orta][]
* Improve path generator for danger-runner. [@Mifi][]
* Update the PR DSL to include bots. [@orta][]
* Add utility function to build tables in Markdown [@keplersj][]

## 3.1.7

Expand Down Expand Up @@ -1076,6 +1085,7 @@ Not usable for others, only stubs of classes etc. - [@orta][]
[@wizardishungry]: https://github.com/wizardishungry
[@hongrich]: https://github.com/hongrich
[@peterjgrainger]: https://github.com/peterjgrainger
[@keplersj]: https://github.com/keplersj
[@azz]: https://github.com/azz
[@mifi]: https://github.com/ionutmiftode
[@sunshinejr]: https://github.com/sunshinejr
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "3.6.5",
"version": "3.6.6",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down Expand Up @@ -138,7 +138,7 @@
"require-from-string": "^2.0.2",
"rfc6902": "^2.2.2",
"supports-hyperlinks": "^1.0.1",
"vm2": "patriksimek/vm2#custom_files",
"vm2": "^3.6.0",
"voca": "^1.4.0"
},
"optionalDependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-runner.ts
Expand Up @@ -47,7 +47,7 @@ const run = async (jsonString: string) => {
const context = await jsonToContext(jsonString, program)
runtimeEnv = await inline.createDangerfileRuntimeEnvironment(context)
d(`Evaluating ${dangerFile}`)
await inline.runDangerfileEnvironment(dangerFile, undefined, runtimeEnv)
await inline.runDangerfileEnvironment([dangerFile], [undefined], runtimeEnv)
}

// Wait till the end of the process to print out the results. Will
Expand Down
7 changes: 4 additions & 3 deletions source/dsl/DangerResults.ts
Expand Up @@ -208,9 +208,10 @@ export function sortResults(results: DangerResults): DangerResults {
}
}

export function isEmptyResults(results: DangerResults): boolean {
return [...results.fails, ...results.warnings, ...results.messages, ...results.markdowns].length === 0
}
export const emptyResults = (): DangerResults => ({ fails: [], markdowns: [], warnings: [], messages: [] })

export const isEmptyResults = (results: DangerResults): boolean =>
[...results.fails, ...results.warnings, ...results.messages, ...results.markdowns].length === 0

export function resultsIntoInlineResults(results: DangerResults): DangerInlineResults[] {
// Here we iterate through all keys ("fails", "warnings", "messages", "markdowns") and for each violation
Expand Down
4 changes: 4 additions & 0 deletions source/platforms/FakePlatform.ts
Expand Up @@ -11,6 +11,10 @@ export class FakePlatform implements Platform {
this.name = "Fake"
}

async getReviewInfo(): Promise<any> {
return {}
}

async getPlatformDSLRepresentation(): Promise<any> {
return {}
}
Expand Down
1 change: 1 addition & 0 deletions source/platforms/GitHub.ts
Expand Up @@ -37,6 +37,7 @@ export const GitHub = (api: GitHubAPI) => {
name: "GitHub",

api,
getReviewInfo: api.getPullRequestInfo,
getPlatformGitRepresentation: () => gitDSLForGitHub(api),

getPlatformDSLRepresentation: async () => {
Expand Down
4 changes: 4 additions & 0 deletions source/platforms/LocalGit.ts
Expand Up @@ -108,4 +108,8 @@ export class LocalGit implements Platform {
}

getFileContents = (path: string) => new Promise<string>(res => res(readFileSync(path, "utf8")))

async getReviewInfo(): Promise<any> {
return {}
}
}
2 changes: 1 addition & 1 deletion source/platforms/github/GitHubAPI.ts
Expand Up @@ -45,7 +45,7 @@ export class GitHubAPI {
getExternalAPI = (JWTForGithubApp?: string): GitHubNodeAPI => {
const host = process.env["DANGER_GITHUB_API_BASE_URL"] || undefined
const api = new GitHubNodeAPI({
host,
baseUrl: host,
headers: {
...this.additionalHeaders,
},
Expand Down
1 change: 1 addition & 0 deletions source/platforms/platform.ts
Expand Up @@ -36,6 +36,7 @@ export interface Platform extends PlatformCommunicator {
/** Mainly for logging and error reporting */
readonly name: string

getReviewInfo: () => Promise<any>
/** Pulls in the platform specific metadata for inspection */
getPlatformDSLRepresentation: () => Promise<any>
/** Pulls in the Code Review Diff, and offers a succinct user-API for it */
Expand Down
6 changes: 3 additions & 3 deletions source/runner/Executor.ts
Expand Up @@ -94,7 +94,7 @@ export class Executor {
// If an eval of the Dangerfile fails, we should generate a
// message that can go back to the CI
try {
results = await this.runner.runDangerfileEnvironment(file, undefined, runtime)
results = await this.runner.runDangerfileEnvironment([file], [undefined], runtime)
} catch (error) {
results = this.resultsForError(error)
}
Expand Down Expand Up @@ -359,12 +359,12 @@ export class Executor {
}

/**
* Takes an error (maybe a bad eval) and provides a DangerResults compatible object3ehguh.l;/////////////
* Takes an error (maybe a bad eval) and provides a DangerResults compatible object
* @param error Any JS error
*/
resultsForError(error: Error) {
// Need a failing error, otherwise it won't fail CI.
console.error(chalk.red("Danger has errored"))
console.error(chalk.red("Danger has failed to run"))
console.error(error)
return {
fails: [{ message: "Running your Dangerfile has Failed" }],
Expand Down
1 change: 1 addition & 0 deletions source/runner/_tests/fixtures/__DangerfileTypeScript.ts
@@ -1,3 +1,4 @@
// @ts-ignore
/* tslint-disable */

// This doesn't exist in JS-world
Expand Down
64 changes: 49 additions & 15 deletions source/runner/runners/_tests/vm2.test.ts
Expand Up @@ -70,7 +70,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileEmpty.js"),
[resolve(fixtures, "__DangerfileEmpty.js")],
undefined,
runtime
)
Expand All @@ -91,7 +91,7 @@ runners.forEach(run => {
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)

const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileFullMessages.js"),
[resolve(fixtures, "__DangerfileFullMessages.js")],
undefined,
runtime
)
Expand All @@ -108,7 +108,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileBadSyntax.js"),
[resolve(fixtures, "__DangerfileBadSyntax.js")],
undefined,
runtime
)
Expand All @@ -121,7 +121,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileImportRelative.js"),
[resolve(fixtures, "__DangerfileImportRelative.js")],
undefined,
runtime
)
Expand All @@ -131,7 +131,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileScheduled.js"),
[resolve(fixtures, "__DangerfileScheduled.js")],
undefined,
runtime
)
Expand All @@ -147,7 +147,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileMultiScheduled.js"),
[resolve(fixtures, "__DangerfileMultiScheduled.js")],
undefined,
runtime
)
Expand All @@ -163,7 +163,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileAsync.ts"),
[resolve(fixtures, "__DangerfileAsync.ts")],
undefined,
runtime
)
Expand All @@ -182,7 +182,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileAsync.js"),
[resolve(fixtures, "__DangerfileAsync.js")],
undefined,
runtime
)
Expand All @@ -201,7 +201,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileAsync.ts"),
[resolve(fixtures, "__DangerfileAsync.ts")],
undefined,
runtime
)
Expand All @@ -219,7 +219,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileCallback.js"),
[resolve(fixtures, "__DangerfileCallback.js")],
undefined,
runtime
)
Expand All @@ -234,7 +234,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileTypeScript.ts"),
[resolve(fixtures, "__DangerfileTypeScript.ts")],
undefined,
runtime
)
Expand All @@ -249,7 +249,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfilePlugin.js"),
[resolve(fixtures, "__DangerfilePlugin.js")],
undefined,
runtime
)
Expand All @@ -261,7 +261,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileThrows.js"),
[resolve(fixtures, "__DangerfileThrows.js")],
undefined,
runtime
)
Expand All @@ -274,7 +274,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileDefaultExport.js"),
[resolve(fixtures, "__DangerfileDefaultExport.js")],
undefined,
runtime
)
Expand All @@ -290,7 +290,7 @@ runners.forEach(run => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
resolve(fixtures, "__DangerfileDefaultExportAsync.js"),
[resolve(fixtures, "__DangerfileDefaultExportAsync.js")],
undefined,
runtime
)
Expand All @@ -301,6 +301,40 @@ runners.forEach(run => {
warnings: [{ message: "Asynchronous Warning" }],
})
})

it("handles running multiple local files", async () => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
[resolve(fixtures, "__DangerfileTypeScript.ts"), resolve(fixtures, "__DangerfileAsync.ts")],
undefined,
runtime
)

expect(results).toEqual({
fails: [],
markdowns: [],
messages: [{ message: "Honey, we got Types" }],
warnings: [{ message: "Async Function" }, { message: "After Async Function" }],
})
})

it("handles running multiple dangerfiles with passed in content", async () => {
const context = await setupDangerfileContext()
const runtime = await exec.runner.createDangerfileRuntimeEnvironment(context)
const results = await exec.runner.runDangerfileEnvironment(
[resolve(fixtures, "__MadeUpDangerfileOne.ts"), resolve(fixtures, "__MadeUpDangerfileTwo.ts")],
["markdown('hello')", "markdown('hello2')"],
runtime
)

expect(results).toEqual({
fails: [],
markdowns: [{ message: "hello" }, { message: "hello2" }],
messages: [],
warnings: [],
})
})
})
})
})

0 comments on commit 6105752

Please sign in to comment.