-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
065b2a5
commit be8de95
Showing
3 changed files
with
112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Env, CISource } from "../ci_source" | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers" | ||
|
||
/** | ||
* Concourse CI Integration | ||
* | ||
* https://concourse-ci.org/ | ||
*/ | ||
export class Concourse implements CISource { | ||
constructor(private readonly env: Env) {} | ||
|
||
get name(): string { | ||
return "Concourse" | ||
} | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ["CONCOURSE"]) | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ["PULL_REQUEST_ID", "REPO_SLUG"] | ||
const mustBeInts = ["PULL_REQUEST_ID"] | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts) | ||
} | ||
|
||
get pullRequestID(): string { | ||
return this.env.PULL_REQUEST_ID | ||
} | ||
|
||
get repoSlug(): string { | ||
return this.env.REPO_SLUG | ||
} | ||
|
||
get ciRunURL() { | ||
return this.env.BUILD_URL | ||
} | ||
} |
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,72 @@ | ||
import { Concourse } from "../Concourse" | ||
import { getCISourceForEnv } from "../../get_ci_source" | ||
|
||
const correctEnv = { | ||
CONCOURSE: "true", | ||
REPO_SLUG: "danger/danger-js", | ||
PULL_REQUEST_ID: "2", | ||
BUILD_URL: "https://github.com/danger/danger-js/blob/master", | ||
} | ||
|
||
describe("being found when looking for CI", () => { | ||
it("finds Concourse with the right ENV", () => { | ||
const ci = getCISourceForEnv(correctEnv) | ||
expect(ci).toBeInstanceOf(Concourse) | ||
}) | ||
}) | ||
|
||
describe(".isCI", () => { | ||
it("validates when all Concourse environment vars are set", () => { | ||
const concourse = new Concourse(correctEnv) | ||
expect(concourse.isCI).toBeTruthy() | ||
}) | ||
|
||
it("does not validate without env", () => { | ||
const concourse = new Concourse({}) | ||
expect(concourse.isCI).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".isPR", () => { | ||
it("validates when all Concourse environment vars are set", () => { | ||
const concourse = new Concourse(correctEnv) | ||
expect(concourse.isPR).toBeTruthy() | ||
}) | ||
|
||
it("does not validate outside of Concourse", () => { | ||
const concourse = new Concourse({}) | ||
expect(concourse.isPR).toBeFalsy() | ||
}) | ||
|
||
const envs = ["CONCOURSE", "REPO_SLUG", "PULL_REQUEST_ID"] | ||
envs.forEach((key: string) => { | ||
let env = Object.assign({}, correctEnv) | ||
env[key] = null | ||
|
||
it(`does not validate when ${key} is missing`, () => { | ||
const concourse = new Concourse({}) | ||
expect(concourse.isCI && concourse.isPR).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe("repo slug", () => { | ||
it("returns correct slug", () => { | ||
const concourse = new Concourse(correctEnv) | ||
expect(concourse.repoSlug).toEqual("danger/danger-js") | ||
}) | ||
}) | ||
|
||
describe("pull request id", () => { | ||
it("returns correct id", () => { | ||
const concourse = new Concourse(correctEnv) | ||
expect(concourse.pullRequestID).toEqual("2") | ||
}) | ||
}) | ||
|
||
describe("build url", () => { | ||
it("returns correct build url", () => { | ||
const concourse = new Concourse(correctEnv) | ||
expect(concourse.ciRunURL).toEqual("https://github.com/danger/danger-js/blob/master") | ||
}) | ||
}) | ||
}) |
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