-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
Patrick Camacho
committed
Jan 30, 2017
1 parent
80ab229
commit 391cb70
Showing
6 changed files
with
133 additions
and
8 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,47 @@ | ||
import { Env, CISource } from "../ci_source" | ||
import { ensureEnvKeysExist } from "../ci_source_helpers" | ||
|
||
export class DockerCloud implements CISource { | ||
constructor(private readonly env: Env) { | ||
} | ||
|
||
get name(): string { return "Docker Cloud" } | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ["DOCKER_REPO"]) | ||
} | ||
|
||
get isPR(): boolean { | ||
if (ensureEnvKeysExist(this.env, ["PULL_REQUEST_URL"])) { | ||
return true | ||
} | ||
|
||
const mustHave = ["SOURCE_REPOSITORY_URL", "PULL_REQUEST_URL"] | ||
return ensureEnvKeysExist(this.env, mustHave) | ||
} | ||
|
||
private _prParseURL(): {owner?: string, reponame?: string, id?: string} { | ||
const prUrl = this.env.PULL_REQUEST_URL || "" | ||
const splitSlug = prUrl.split("/") | ||
if (splitSlug.length === 7) { | ||
const owner = splitSlug[3] | ||
const reponame = splitSlug[4] | ||
const id = splitSlug[6] | ||
return {owner, reponame, id} | ||
}; | ||
return {} | ||
} | ||
|
||
get pullRequestID(): string { | ||
const {id} = this._prParseURL() | ||
return id || "" | ||
} | ||
|
||
get repoSlug(): string { | ||
const {owner, reponame} = this._prParseURL() | ||
return (owner && reponame) ? `${owner}/${reponame}` : "" | ||
} | ||
|
||
get repoURL(): string { return this.env.SOURCE_REPOSITORY_URL } | ||
get supportedPlatforms(): string[] { return ["github"] } | ||
} |
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,62 @@ | ||
import {DockerCloud} from "../DockerCloud" | ||
|
||
const correctEnv = { | ||
"DOCKER_REPO": "someproject", | ||
"PULL_REQUEST_URL": "https://github.com/artsy/eigen/pull/800", | ||
"SOURCE_REPOSITORY_URL": "https://github.com/artsy/eigen" | ||
} | ||
|
||
describe(".isCI", () => { | ||
it("validates when all DockerCloud environment vars are set", () => { | ||
const dockerCloud = new DockerCloud(correctEnv) | ||
expect(dockerCloud.isCI).toBeTruthy() | ||
}) | ||
|
||
it("does not validate without env", () => { | ||
const dockerCloud = new DockerCloud({}) | ||
expect(dockerCloud.isCI).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".isPR", () => { | ||
it("validates when all dockerCloud environment vars are set", () => { | ||
const dockerCloud = new DockerCloud(correctEnv) | ||
expect(dockerCloud.isPR).toBeTruthy() | ||
}) | ||
|
||
it("does not validate outside of dockerCloud", () => { | ||
const dockerCloud = new DockerCloud({}) | ||
expect(dockerCloud.isPR).toBeFalsy() | ||
}) | ||
|
||
const envs = ["PULL_REQUEST_URL", "SOURCE_REPOSITORY_URL", "DOCKER_REPO"] | ||
envs.forEach((key: string) => { | ||
let env = { | ||
"DOCKER_REPO": "someproject", | ||
"PULL_REQUEST_URL": "https://github.com/artsy/eigen/pull/800", | ||
"SOURCE_REPOSITORY_URL": "https://github.com/artsy/eigen" | ||
} | ||
env[key] = null | ||
|
||
it(`does not validate when ${key} is missing`, () => { | ||
const dockerCloud = new DockerCloud({}) | ||
expect(dockerCloud.isPR).toBeFalsy() | ||
}) | ||
}) | ||
}) | ||
|
||
describe(".pullRequestID", () => { | ||
it("pulls it out of the env", () => { | ||
const dockerCloud = new DockerCloud({ | ||
"PULL_REQUEST_URL": "https://github.com/artsy/eigen/pull/800" | ||
}) | ||
expect(dockerCloud.pullRequestID).toEqual("800") | ||
}) | ||
}) | ||
|
||
describe(".repoSlug", () => { | ||
it("derives it from the PR Url", () => { | ||
const dockerCloud = new DockerCloud(correctEnv) | ||
expect(dockerCloud.repoSlug).toEqual("artsy/eigen") | ||
}) | ||
}) |
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