-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from danger/local
Add support for evaling and running Danger on CI
- Loading branch information
Showing
17 changed files
with
205 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
// @flow | ||
|
||
// import danger from "danger" | ||
import danger from "./source/danger" | ||
|
||
// warn on changes in Package.json and not in shrinkwrap | ||
|
||
// warn on changelog | ||
// console.log(danger) | ||
// console.log(danger.git) | ||
// console.log(danger.git.created_files) | ||
|
||
console.log("Eval'd:", danger.git) | ||
|
||
danger.git.created_files.join(" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +0,0 @@ | ||
// @flow | ||
"strict mode" | ||
|
||
import type { Env, CISource } from "./ci_source" | ||
import Travis from "./travis" | ||
|
||
/** Here is some docs for the function */ | ||
export function getCISourceForEnv(env: Env) : ?CISource { | ||
let travis = new Travis(env) | ||
return travis | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
"use strict" | ||
|
||
// import type { Platform } from "../platforms/platform" | ||
import type { GitDSL } from "../dsl/Git" | ||
|
||
export default class DangerDSL { | ||
git: GitDSL | ||
pr: any | ||
|
||
constructor(pr: any, git: GitDSL) { | ||
this.git = git | ||
this.pr = pr | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface GitDSL { | ||
modified_files: string[], | ||
created_files: string[], | ||
deleted_files: string[] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// https://nodejs.org/api/vm.html | ||
// https://60devs.com/executing-js-code-with-nodes-vm-module.html | ||
|
||
import fs from "fs" | ||
import vm from "vm" | ||
import DangerDSL from "../dsl/DangerDSL" | ||
|
||
export default class Dangerfile { | ||
dsl: DangerDSL | ||
constructor(dsl: DangerDSL) { this.dsl = dsl } | ||
|
||
run(file: string) { | ||
fs.readFile(file, "utf8", (err: Error, data: string) => { | ||
if (err) { return console.error(err.message) } | ||
|
||
// comment out imports of 'danger' | ||
// e.g `import danger from` | ||
// then user get typed data, and we fill it in | ||
// via the VM context | ||
|
||
const cleaned = data.replace(/import danger from/gi, "// import danger from") | ||
|
||
const script = new vm.Script(cleaned, { | ||
filename: file, | ||
lineOffset: 1, | ||
columnOffset: 1, | ||
displayErrors: true, | ||
timeout: 1000 // ms | ||
}) | ||
|
||
const context: any = { | ||
console, | ||
danger: this.dsl | ||
} | ||
|
||
script.runInNewContext(context) | ||
}) | ||
} | ||
} | ||
|
Oops, something went wrong.