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 #915 from kristof0425/feat/add-buddy-works-ci
[Feature]: Add Buddy.works pipeline support
- Loading branch information
Showing
6 changed files
with
137 additions
and
3 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,48 @@ | ||
import { Env, CISource } from "../ci_source" | ||
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers" | ||
/** | ||
* ### CI Setup | ||
* | ||
* To make Danger run: | ||
* | ||
* - Create a new pipeline named, DangerJS, which is triggered on every push | ||
* - Add a NodeJS environment as an Action | ||
* - Go into it, head over to the bash editor and type the following | ||
* - `yarn install && yarn danger ci` | ||
* - or your npm script | ||
* - Set the `DANGER_GITHUB_API_TOKEN` at the Variables section | ||
* - You're done 🎉 | ||
* | ||
*/ | ||
export class BuddyWorks implements CISource { | ||
constructor(private readonly env: Env) {} | ||
|
||
get name(): string { | ||
return "Buddy.works" | ||
} | ||
|
||
get isCI(): boolean { | ||
return ensureEnvKeysExist(this.env, ["BUDDY_PIPELINE_ID"]) | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ["BUDDY_PIPELINE_ID", "BUDDY_EXECUTION_PULL_REQUEST_ID", "BUDDY_REPO_SLUG"] | ||
const mustBeInts = ["BUDDY_EXECUTION_PULL_REQUEST_ID"] | ||
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts) | ||
} | ||
|
||
get pullRequestID(): string { | ||
return this.env.BUDDY_EXECUTION_PULL_REQUEST_ID | ||
} | ||
|
||
get repoSlug(): string { | ||
return this.env.BUDDY_REPO_SLUG | ||
} | ||
|
||
get ciRunURL() { | ||
return this.env.BUDDY_EXECUTION_URL | ||
} | ||
} | ||
|
||
// Default ENV vars provided by Buddy.works | ||
// https://buddy.works/docs/pipelines/environment-variables#default-environment-variables |
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,82 @@ | ||
import { BuddyWorks } from "../BuddyWorks" | ||
import { getCISourceForEnv } from "../../get_ci_source" | ||
|
||
const correctEnv = { | ||
BUDDY_PIPELINE_ID: "170873", | ||
BUDDY_EXECUTION_PULL_REQUEST_ID: "1799", | ||
BUDDY_REPO_SLUG: "danger/dangerjs", | ||
BUDDY_EXECUTION_URL: | ||
"https://app.buddy.works/danger/dangerjs/pipelines/pipeline/170873/execution/5d6d49dbaab2cb6fdf975c71", | ||
} | ||
|
||
describe("being found when looking for CI", () => { | ||
it("finds Buddy.works with the right ENV", () => { | ||
const ci = getCISourceForEnv(correctEnv) | ||
expect(ci).toBeInstanceOf(BuddyWorks) | ||
}) | ||
}) | ||
|
||
describe(".isCI", () => { | ||
test("validates when all Buddy.works environment vars are set", () => { | ||
const buddyWorks = new BuddyWorks(correctEnv) | ||
expect(buddyWorks.isCI).toBeTruthy() | ||
}) | ||
|
||
test("does not validate without pipeline ID", () => { | ||
const buddyWorks = new BuddyWorks({}) | ||
expect(buddyWorks.isCI).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".isPR", () => { | ||
test("validates when all Buddy.works environment vars are set", () => { | ||
const buddyWorks = new BuddyWorks(correctEnv) | ||
expect(buddyWorks.isPR).toBeTruthy() | ||
}) | ||
|
||
test("does not validate without pipeline ID", () => { | ||
const buddyWorks = new BuddyWorks({}) | ||
expect(buddyWorks.isPR).toBeFalsy() | ||
}) | ||
|
||
const envs = ["BUDDY_EXECUTION_PULL_REQUEST_ID", "BUDDY_REPO_SLUG"] | ||
envs.forEach((key: string) => { | ||
const env = Object.assign({}, correctEnv) | ||
env[key] = null | ||
|
||
test(`does not validate when ${key} is missing`, () => { | ||
const buddyWorks = new BuddyWorks(env) | ||
expect(buddyWorks.isPR).toBeFalsy() | ||
}) | ||
}) | ||
|
||
it("needs to have a PR number", () => { | ||
const env = Object.assign({}, correctEnv) | ||
delete env.BUDDY_EXECUTION_PULL_REQUEST_ID | ||
const buddyWorks = new BuddyWorks(env) | ||
expect(buddyWorks.isPR).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".pullRequestID", () => { | ||
it("pulls it out of the env", () => { | ||
const buddyWorks = new BuddyWorks(correctEnv) | ||
expect(buddyWorks.pullRequestID).toEqual("1799") | ||
}) | ||
}) | ||
|
||
describe(".repoSlug", () => { | ||
it("pulls it out of the env", () => { | ||
const buddyWorks = new BuddyWorks(correctEnv) | ||
expect(buddyWorks.repoSlug).toEqual("danger/dangerjs") | ||
}) | ||
}) | ||
|
||
describe(".ciRunURL", () => { | ||
it("pulls it out of the env", () => { | ||
const buddyWorks = new BuddyWorks(correctEnv) | ||
expect(buddyWorks.ciRunURL).toEqual( | ||
"https://app.buddy.works/danger/dangerjs/pipelines/pipeline/170873/execution/5d6d49dbaab2cb6fdf975c71" | ||
) | ||
}) | ||
}) |
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