Skip to content

Commit

Permalink
Add CI integration for Concourse
Browse files Browse the repository at this point in the history
  • Loading branch information
cwright017 committed Sep 4, 2018
1 parent 065b2a5 commit be8de95
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
37 changes: 37 additions & 0 deletions source/ci_source/providers/Concourse.ts
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
}
}
72 changes: 72 additions & 0 deletions source/ci_source/providers/_tests/_concourse.test.ts
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")
})
})
})
3 changes: 3 additions & 0 deletions source/ci_source/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BuddyBuild } from "./BuddyBuild"
import { Buildkite } from "./Buildkite"
import { Circle } from "./Circle"
import { Codeship } from "./Codeship"
import { Concourse } from "./Concourse"
import { DockerCloud } from "./DockerCloud"
import { Drone } from "./Drone"
import { FakeCI } from "./Fake"
Expand Down Expand Up @@ -32,6 +33,7 @@ const providers = [
Bitrise,
TeamCity,
Screwdriver,
Concourse,
]

// Mainly used for Dangerfile linting
Expand All @@ -50,6 +52,7 @@ const realProviders = [
VSTS,
TeamCity,
Screwdriver,
Concourse,
]

export { providers, realProviders }

0 comments on commit be8de95

Please sign in to comment.