Skip to content

Commit

Permalink
Merge pull request #36 from danger/test-local
Browse files Browse the repository at this point in the history
Allows fakeci to run via DANGER_TEST_PR and DANGER_TEST_REPO env vars
  • Loading branch information
orta committed Dec 2, 2016
2 parents 4081832 + 2fe0ce9 commit 16f3454
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 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.

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.

Expand Down Expand Up @@ -45,11 +45,30 @@ 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). 👍


Notes:
Notes:

* The `Dangerfile.js` needs to be able to run on node without running through babel right now.
* The shape of the API is [`git`](https://github.com/danger/danger-js/blob/master/source/dsl/git.js) and [`pr`](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/github_api/pr_response.json)

#### Running/Testing manually against a repo

If you create an [appropriately scoped temporary api token](http://danger.systems/guides/getting_started.html#setting-up-an-access-token) for your github account, this can be a good way to see if danger is suitable for you before integrating it into your CI system.

You can manually trigger danger against a pull request on the command line by setting the following environmental variables:

```bash
export DANGER_GITHUB_API_TOKEN='xxxxxxxxxx' # a github api token
export DANGER_TEST_REPO='username/reponame'
```

Then you can run against a local branch that is attached to a pull-request, by running the following

```bash
git checkout branch-for-pr-1234
DANGER_TEST_PR='1234' npm run danger
```

assuming that your local filesystem matches up to that branch on github, this will be a good approximation of how danger will work when you integrate it into your ci system.

#### This thing is broken, I should help improve it!

Expand All @@ -61,7 +80,7 @@ cd danger-js

# if you don't have have yarn installed
npm install -g yarn

yarn install
```

Expand All @@ -71,13 +90,13 @@ You can then verify your install by running the tests, and the linters:
npm test
npm run lint
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.
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.

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Add your own contribution below

* The env vars `DANGER_TEST_REPO` and `DANGER_TEST_PR` will allow you initialize the FakeCI with a repo of your choice. See README.md for more info
* Improved error messaging around not including a `DANGER_GITHUB_API_TOKEN` in the ENV - nsfmc / orta

### 0.6.3
Expand Down
13 changes: 10 additions & 3 deletions source/ci_source/Fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import type { Env } from "./ci_source"

export default class FakeCI {
env: Env
constructor(env: Env) { this.env = env }
constructor(env: Env) {
const defaults = {
repo: env.DANGER_TEST_REPO || "artsy/emission",
pr: env.DANGER_TEST_PR || "327"
}

this.env = {...env, ...defaults}
}
get name(): string { return "Fake Testing CI" }

get isCI(): boolean { return true }
get isPR(): boolean { return true }

get pullRequestID(): string { return "327" }
get repoSlug(): string { return "artsy/emission" }
get pullRequestID(): string { return this.env.pr }
get repoSlug(): string { return this.env.repo }
get repoURL(): string { return "maybe not needed?" }
get supportedPlatforms(): string[] { return ["github"] }
}
3 changes: 2 additions & 1 deletion source/ci_source/ci_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ export function getCISourceForEnv(env: Env): ?CISource {
// Fake is what I'm using during dev for the minute
const travis = new Travis(env)
const circle = new Circle(env)
const fake = new Fake(env)

if (travis.isCI) {
return travis
} else if (circle.isCI) {
return circle
} else {
return new Fake()
return fake
}
}

0 comments on commit 16f3454

Please sign in to comment.