Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Buildkite #220

Merged
merged 3 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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 a lot of the simpler parts of [the Ruby version](http://danger.systems).
You can look at [Git](https://github.com/danger/danger-js/blob/master/source/dsl/GitDSL.ts) metadata, or [GitHub](https://github.com/danger/danger-js/blob/master/source/dsl/GitHubDSL.ts) metadata on Travis CI, Circle CI, Semaphore, Jenkins, Docker Cloud, surf-build, Codeship or Drone.
You can look at [Git](https://github.com/danger/danger-js/blob/master/source/dsl/GitDSL.ts) metadata, or [GitHub](https://github.com/danger/danger-js/blob/master/source/dsl/GitHubDSL.ts) metadata on Travis CI, Circle CI, Semaphore, Jenkins, Docker Cloud, surf-build, Codeship, Drone, or Buildkite.

Danger can fail your build, write a comment on GitHub, edit it as your PR changes and then delete it once you've passed review. Perfect.

Expand Down
5 changes: 3 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Master

* Adds a `diffTypes` option to `diffForFile` - alex3165
* Add Buildkite CI source - jacobwgillespie

### 0.15.0

Expand All @@ -11,8 +12,8 @@
### 0.14.2

* Updated jest-* dependencies to 19.x - orta
Updating the jest-* dependencies seems to be exhibiting strange behavior in tests for windows if you update, and

Updating the jest-* dependencies seems to be exhibiting strange behavior in tests for windows if you update, and
use windows, can you please confirm that everything is 👍

* Added type shapings to `JSONPatchForFile` - orta
Expand Down
30 changes: 30 additions & 0 deletions source/ci_source/providers/Buildkite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"

export class Buildkite implements CISource {
constructor(private readonly env: Env) {
}

get name(): string { return "Buildkite" }

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

get isPR(): boolean {
const mustHave = ["BUILDKITE_REPO"]
const mustBeInts = ["BUILDKITE_PULL_REQUEST"]
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts)
}

private _parseRepoURL(): string {
const repoURL = this.env.BUILDKITE_REPO
const regexp = new RegExp("([\/:])([^\/]+\/[^\/.]+)(?:.git)?$")
const matches = repoURL.match(regexp)
return matches ? matches[2] : ""
}

get pullRequestID(): string { return this.env.BUILDKITE_PULL_REQUEST }
get repoSlug(): string { return this._parseRepoURL() }
get supportedPlatforms(): string[] { return ["github"] }
}
79 changes: 79 additions & 0 deletions source/ci_source/providers/_tests/_buildkite.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {Buildkite} from "../Buildkite"
import {getCISourceForEnv} from "../../get_ci_source"

const correctEnv = {
"BUILDKITE": "true",
"BUILDKITE_PULL_REQUEST": "800",
"BUILDKITE_REPO": "https://github.com/artsy/eigen"
}

describe("being found when looking for CI", () => {
it("finds Buildkite with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(Buildkite)
})
})

describe(".isCI", () => {
it("validates when all Buildkite environment vars are set", () => {
const buildkite = new Buildkite(correctEnv)
expect(buildkite.isCI).toBeTruthy()
})

it("does not validate without env", () => {
const buildkite = new Buildkite({})
expect(buildkite.isCI).toBeFalsy()
})
})

describe(".isPR", () => {
it("validates when all buildkite environment vars are set", () => {
const buildkite = new Buildkite(correctEnv)
expect(buildkite.isPR).toBeTruthy()
})

it("does not validate outside of buildkite", () => {
const buildkite = new Buildkite({})
expect(buildkite.isPR).toBeFalsy()
})

const envs = ["BUILDKITE_PULL_REQUEST", "BUILDKITE_REPO", "BUILDKITE"]
envs.forEach((key: string) => {
let env = {
"BUILDKITE": "true",
"BUILDKITE_PULL_REQUEST": "800",
"BUILDKITE_REPO": "https://github.com/artsy/eigen"
}
env[key] = null

it(`does not validate when ${key} is missing`, () => {
const buildkite = new Buildkite({})
expect(buildkite.isPR).toBeFalsy()
})
})
})

describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const buildkite = new Buildkite({
"BUILDKITE_PULL_REQUEST": "800"
})
expect(buildkite.pullRequestID).toEqual("800")
})
})

describe(".repoSlug", () => {
it("derives it from the repo URL", () => {
const buildkite = new Buildkite(correctEnv)
expect(buildkite.repoSlug).toEqual("artsy/eigen")
})

it("derives it from the repo URL in SSH format", () => {
const env = {
...correctEnv,
"BUILDKITE_REPO": "git@github.com:artsy/eigen.git"
}
const buildkite = new Buildkite(env)
expect(buildkite.repoSlug).toEqual("artsy/eigen")
})
})
5 changes: 3 additions & 2 deletions source/ci_source/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {Surf} from "./Surf"
import {DockerCloud} from "./DockerCloud"
import {Codeship} from "./Codeship"
import {Drone} from "./Drone"
import {Buildkite} from "./Buildkite"

const providers = [Travis, Circle, Semaphore, Jenkins, FakeCI, Surf, DockerCloud, Codeship, Drone]
const providers = [Travis, Circle, Semaphore, Jenkins, FakeCI, Surf, DockerCloud, Codeship, Drone, Buildkite]

// Mainly used for Dangerfile linting
const realProviders = [Travis, Circle, Semaphore, Jenkins, Surf, DockerCloud, Codeship, Drone]
const realProviders = [Travis, Circle, Semaphore, Jenkins, Surf, DockerCloud, Codeship, Drone, Buildkite]

export {
providers,
Expand Down