Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/danger/danger-js into com…
Browse files Browse the repository at this point in the history
…mits
  • Loading branch information
orta committed Jan 8, 2017
2 parents dcdfd4b + 5ddce59 commit a6bc8cf
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 189 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ Danger on Node, wonder what's going on? see [VISION.md](VISION.md)

*Welcome!*

So, what's the deal? Well, right now Danger JS does the MVP of [the Ruby version](http://danger.systems). You can look at [Git](https://github.com/danger/danger-js/blob/master/source/dsl/GitDSL.js) metadata, or [GitHub](https://github.com/danger/danger-js/blob/master/source/dsl/GitHubDSL.js) metadata on Travis CI.
So, what's the deal? Well, right now Danger JS does a lot of the simpler parts of [the Ruby version](http://danger.systems).
You can look at [Git](https://github.com/danger/danger-js/blob/master/source/dsl/GitDSL.js) metadata, or [GitHub](https://github.com/danger/danger-js/blob/master/source/dsl/GitHubDSL.js) metadata on Travis CI.

Danger can fail your build, write a comment on GitHub, edit it as your build changes and then delete it once you've passed review.

To install:

```sh
npm install danger --save-dev
yarn add dev danger
```
Then add a run command to your `Package.json`

Expand Down Expand Up @@ -48,6 +49,13 @@ if (unFlowedFiles.length > 0) {
Then you add `npm run danger` to the end of your CI run, and Danger will run. Here's [an example](https://github.com/artsy/emission/pull/385). 👍


Want to see some existing examples? Check out:

* **Apps** - [Artsy/Emission][emiss] and [Artsy/metaphysics][meta].
* **Libraries** - [Facebook/Jest][fbj] and [styled-components/styled-components][sc].

I'd love PRs adding more.

Notes:

* The `Dangerfile.js` needs to be able to run on node without running through babel right now.
Expand Down Expand Up @@ -100,22 +108,16 @@ npm run flow

### Dev Life

We use quite a few semi-bleeding edge features of JS in Danger. Please see the [glossary for an overview](docs/js_glossary.md). Notably Flow, Interfaces, Async/Await and Typealiases.

You'll have a nicer experience as a developer if you use VS Code with Flow enabled, and if you install flow-typed.

``` sh
npm install -g flow-typed
flow-typed install
```

( and maybe `flow-typed install jest`)

Tips:

* You can run the `danger` command globally from your dev build by running `npm run link`.
* If you're using VS Code, press Run to start an example run, should go through most of the process with a debugger attatched. Either use breakpoints, or add `debugger` to get a repl and context.
* You can run the `danger` command globally from your dev build by running `yarn run link`.
* If you're using VS Code, press Run to start an example run, should go through most of the process with a debugger attached. Either use breakpoints, or add `debugger` to get a repl and context.

### What is the TODO?

Check the issues, I try and keep my short term perspective there. Long term is in the [VISION.md](VISION.md).

[emiss]: https://github.com/artsy/emission/blob/master/dangerfile.js
[meta]: https://github.com/artsy/metaphysics/blob/master/dangerfile.js
[fbj]: https://github.com/facebook/jest/blob/master/dangerfile.js
[sc]: https://github.com/styled-components/styled-components/blob/master/dangerfile.js
12 changes: 9 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
### master

// Add your own contribution below
* Support `danger run -ci` to specify external CI provider -kwonoj
* Allow debug dump output via `DEBUG=danger:*` environment variable - kwonoj
* Adds surf-build ci provider - kwonoj
* Forward environment variable to external module constructor - kwonoj

### 0.8.0

* Support `danger run -ci` to specify external CI provider - kwonoj
* 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
* Migrate codebase into TypeScript from flow - kwonoj
* Handle removing all sorts of import types for Danger in the Dangerfile - orta

### 0.7.3-4
### 0.7.3-4-5

* A failing network request will raise an error - orta
* Fix Dangerfile parsing which broke due to Peril related changes - orta
* Tweak the npmignore, ship less random stuff to others - orta

Expand Down
150 changes: 0 additions & 150 deletions docs/js_glossary.md

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "0.7.4",
"version": "0.8.0",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down Expand Up @@ -73,6 +73,7 @@
"homepage": "https://github.com/danger/danger-js#readme",
"devDependencies": {
"@types/commander": "^2.3.31",
"@types/debug": "0.0.29",
"@types/es6-promise": "0.0.32",
"@types/jest": "^16.0.3",
"@types/node-fetch": "^1.6.6",
Expand All @@ -84,7 +85,7 @@
"babel-preset-stage-3": "^6.17.0",
"husky": "^0.12.0",
"in-publish": "^2.0.0",
"jest": "^18.0.0",
"jest": "^18.1.0",
"lint-staged": "^3.2.5",
"madge": "^1.4.4",
"shx": "^0.2.1",
Expand All @@ -96,6 +97,7 @@
"dependencies": {
"babel-polyfill": "^6.20.0",
"commander": "^2.9.0",
"debug": "^2.6.0",
"jest-runtime": "^18.0.0",
"lodash.find": "^4.6.0",
"lodash.includes": "^4.3.0",
Expand Down
4 changes: 2 additions & 2 deletions source/ci_source/get_ci_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getCISourceForEnv(env: Env): CISource | undefined {
* @param {string} modulePath relative path to CI provider
* @returns {?CISource} a CI source if module loaded successfully, undefined otherwise
*/
export function getCISourceForExternal(_env: Env, modulePath: string): CISource | undefined {
export function getCISourceForExternal(env: Env, modulePath: string): CISource | undefined {
const path = resolve(process.cwd(), modulePath)

try {
Expand All @@ -33,7 +33,7 @@ export function getCISourceForExternal(_env: Env, modulePath: string): CISource
if (exist) {
const externalModule = require(path) //tslint:disable-line:no-require-imports
const moduleConstructor = externalModule.default || externalModule
return new moduleConstructor()
return new moduleConstructor(env)
}
} catch (e) {
console.error(`could not load CI provider at ${modulePath} due to ${e}`)
Expand Down
32 changes: 32 additions & 0 deletions source/ci_source/providers/Surf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"

export class Surf implements CISource {
constructor(private readonly env: Env) {
}

get name(): string {
return "surf-build"
}

get isCI(): boolean {
return ensureEnvKeysExist(this.env, ["SURF_REPO", "SURF_NWO"])
}

get isPR(): boolean {
return this.isCI
}

get pullRequestID(): string {
const key = "SURF_PR_NUM"
return ensureEnvKeysAreInt(this.env, [key]) ? this.env[key] : ""
}

get repoSlug(): string {
return this.env["SURF_NWO"]
}

get supportedPlatforms(): string[] {
return ["github"]
}
}
3 changes: 2 additions & 1 deletion source/ci_source/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {Circle} from "./Circle"
import {Semaphore} from "./Semaphore"
import {Jenkins} from "./Jenkins"
import {FakeCI} from "./Fake"
import {Surf} from "./Surf"

const providers: Array<any> = [Travis, Circle, Semaphore, Jenkins, FakeCI]
const providers: Array<any> = [Travis, Circle, Semaphore, Jenkins, FakeCI, Surf]
export {
providers
};
6 changes: 5 additions & 1 deletion source/commands/danger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
// import app from "./app"
import { version } from "../../package.json"
import * as program from "commander"
import * as debug from "debug"

// Provides the root node to the command-line architecture
const d = debug("danger:runner")

d(`argv: ${process.argv}`)

// Provides the root node to the command-line architecture
program
.version(version)
.command("run", "Runs danger on your local system", {isDefault: true})
Expand Down
9 changes: 7 additions & 2 deletions source/runner/DangerfileRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ export function updateDangerfile(filename: Path) {
fs.writeFileSync(filename, cleanDangerfile(contents))
}

// https://regex101.com/r/dUq4yB/1
const requirePattern = /^.* require\(('|")danger('|")\);?$/gm
// https://regex101.com/r/dUq4yB/2
const es6Pattern = /^.* from ('|")danger('|");?$/gm

/**
* Updates a Dangerfile to remove the import for Danger
* @param {string} contents the file path for the dangerfile
* @returns {string} the revised Dangerfile
*/
export function cleanDangerfile(contents: string): string {
return contents
.replace(/import danger /gi, "// import danger ")
.replace(/import { danger/gi, "// import { danger")
.replace(es6Pattern, "// Removed import")
.replace(requirePattern, "// Removed require")
}
Loading

0 comments on commit a6bc8cf

Please sign in to comment.