Skip to content

Commit

Permalink
Adds back the Fake CI option
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Dec 14, 2016
1 parent b5225d2 commit 2000bc4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ If you create an [appropriately scoped temporary api token](http://danger.system
You can manually trigger danger against a pull request on the command line by setting the following environmental variables:

```bash
export DANGER_FAKE_CI="YEP"
export DANGER_GITHUB_API_TOKEN='xxxxxxxxxx' # a github api token
export DANGER_TEST_REPO='username/reponame'
```
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

// Add your own contribution below

### 0.6.10

* Brings back the ability to emulate a fake CI run locally via `danger` - orta

### 0.6.9

* Makes `babel-polyfill` a direct dependency, this is because it is actually an implicit dependency in the app. I'm not sure how I feel about this, I guess if we use a part of it in the babel translation of a user's Dangerfile them I'm OK with it. - orta
Expand Down
3 changes: 2 additions & 1 deletion source/ci_source/Fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict"

import type { Env } from "./ci_source"
import { ensureEnvKeysExist } from "./ci_source_helpers"

export default class FakeCI {
env: Env
Expand All @@ -15,7 +16,7 @@ export default class FakeCI {
}
get name(): string { return "Fake Testing CI" }

get isCI(): boolean { return true }
get isCI(): boolean { return ensureEnvKeysExist(this.env, ["DANGER_FAKE_CI"]) }
get isPR(): boolean { return true }

get pullRequestID(): string { return this.env.pr }
Expand Down
16 changes: 16 additions & 0 deletions source/ci_source/_tests/_ci_course.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow

import Fake from "../Fake"
import { getCISourceForEnv } from "../ci_source"

describe(".getCISourceForEnv", () => {
test("returns undefined if nothing is found", () => {
const ci = getCISourceForEnv({ })
expect(ci).toBeUndefined()
})

test("falls back to the fake if DANGER_FAKE_CI exists", () => {
const ci = getCISourceForEnv({ DANGER_FAKE_CI: "YES" })
expect(ci).toBeInstanceOf(Fake)
})
})
6 changes: 5 additions & 1 deletion source/ci_source/ci_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface CISource {
import Travis from "./Travis"
import Circle from "./Circle"
import Semaphore from "./Semaphore"
import Fake from "./Fake"

/**
* Gets a CI Source form the current environment, by asking all known
Expand All @@ -45,13 +46,16 @@ export function getCISourceForEnv(env: Env): ?CISource {
const travis = new Travis(env)
const circle = new Circle(env)
const semaphore = new Semaphore(env)
const fake = new Fake(env)

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

0 comments on commit 2000bc4

Please sign in to comment.