-
-
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.
Merge pull request #658 from Cwright017/master
Add CI integration for Concourse
- Loading branch information
Showing
6 changed files
with
155 additions
and
17 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
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,60 @@ | ||
import { Env, CISource } from "../ci_source" | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers" | ||
|
||
/** | ||
* Concourse CI Integration | ||
* | ||
* https://concourse-ci.org/ | ||
* | ||
* ### CI Setup | ||
* | ||
* With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs. | ||
* | ||
* ``` shell | ||
* build: | ||
* image: golang | ||
* commands: | ||
* - ... | ||
* - yarn danger ci | ||
* ``` | ||
* | ||
* ### Environment Variable Setup | ||
* | ||
* As this is self-hosted, you will need to add the `CONCOURSE` environment variable `export CONCOURSE=true` to your build environment, | ||
* as well as setting environment variables for `PULL_REQUEST_ID` and `REPO_SLUG`. Assuming you are using the github pull request resource | ||
* https://github.com/jtarchie/github-pullrequest-resource the id of the PR can be accessed from `git config --get pullrequest.id`. | ||
* | ||
* ### Token Setup | ||
* | ||
* Once again as this is self-hosted, you will need to add `DANGER_GITHUB_API_TOKEN` environment variable to the build environment. | ||
* The suggested method of storing the token is within the vault - https://concourse-ci.org/creds.html | ||
*/ | ||
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