-
-
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.
Merge branch 'master' into 50-broken-dangerfile-fails-build
- Loading branch information
Showing
7 changed files
with
127 additions
and
6 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,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,39 @@ | ||
// @flow | ||
"use strict" | ||
|
||
import type { Env } from "./ci_source" | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "./ci_source_helpers" | ||
|
||
export default class Jenkins { | ||
env: Env | ||
|
||
constructor(env: Env) { | ||
this.env = env | ||
} | ||
|
||
get name(): string { | ||
return "Jenkins" | ||
} | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ["JENKINS_URL"]) | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ["JENKINS_URL", "ghprbPullId", "ghprbGhRepository"] | ||
const mustBeInts = ["ghprbPullId"] | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts) | ||
} | ||
|
||
get pullRequestID(): string { | ||
return this.env.ghprbPullId | ||
} | ||
|
||
get repoSlug(): string { | ||
return this.env.ghprbGhRepository | ||
} | ||
|
||
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,67 @@ | ||
import Jenkins from "../Jenkins" | ||
|
||
const correctEnv = { | ||
"ghprbGhRepository": "danger/danger-js", | ||
"ghprbPullId": "50", | ||
"JENKINS_URL": "https://danger.jenkins" | ||
} | ||
|
||
describe(".isCI", () => { | ||
it("validates when JENKINS_URL is present in environment", () => { | ||
const jenkins = new Jenkins(correctEnv) | ||
expect(jenkins.isCI).toBeTruthy() | ||
}) | ||
|
||
it("does not validate without JENKINS_URL", () => { | ||
const jenkins = new Jenkins({}) | ||
expect(jenkins.isCI).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".isPR", () => { | ||
it("validates when all Jenkins environment variables are set", () => { | ||
const jenkins = new Jenkins(correctEnv) | ||
expect(jenkins.isPR).toBeTruthy() | ||
}) | ||
|
||
it("does not validate with required environment variables", () => { | ||
const jenkins = new Jenkins({}) | ||
expect(jenkins.isPR).toBeFalsy() | ||
}) | ||
|
||
const envs = ["JENKINS_URL", "ghprbPullId", "ghprbGhRepository"] | ||
envs.forEach((key: string) => { | ||
const env = { | ||
...correctEnv, | ||
[key]: null | ||
} | ||
|
||
it(`does not validate when ${key} is missing`, () => { | ||
const jenkins = new Jenkins(env) | ||
expect(jenkins.isPR).toBeFalsy() | ||
}) | ||
}) | ||
|
||
it("needs to have a PR number", () => { | ||
const env = { | ||
...correctEnv, | ||
"ghprbPullId": "not a number" | ||
} | ||
const jenkins = new Jenkins(env) | ||
expect(jenkins.isPR).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".pullRequestID", () => { | ||
it("pulls it out of environment", () => { | ||
const jenkins = new Jenkins(correctEnv) | ||
expect(jenkins.pullRequestID).toEqual("50") | ||
}) | ||
}) | ||
|
||
describe(".repoSlug", () => { | ||
it("pulls it out of environment", () => { | ||
const jenkins = new Jenkins(correctEnv) | ||
expect(jenkins.repoSlug).toEqual("danger/danger-js") | ||
}) | ||
}) |
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