Skip to content

Commit

Permalink
Merge pull request #915 from kristof0425/feat/add-buddy-works-ci
Browse files Browse the repository at this point in the history
[Feature]: Add Buddy.works pipeline support
  • Loading branch information
orta committed Sep 8, 2019
2 parents c3eecbd + 9705c53 commit 77325ea
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@

<!-- Your comment below this -->

- Add Buddy.works Pipelines support - [@kristof0425]
- Added flag to bypass Jira/Issues - [@orieken]
- Improve docs for GitHub Actions - [@nguyenhuy]

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -21,8 +21,8 @@ You can use Danger to codify your teams norms, leaving humans to think about har

Danger JS works with GitHub, BitBucket Server, BitBucket Cloud for code review, then with: Travis CI, GitLab CI,
Semaphore, Circle CI, GitHub Actions, Jenkins, Docker Cloud, Bitrise, surf-build, Codeship, Drone, Buildkite, Nevercode,
buddybuild, TeamCity, Visual Studio Team Services, Screwdriver, Concourse, Netlify, CodeBuild, Codefresh, AppCenter, or
BitBucket Pipelines.
buddybuild, Buddy.works, TeamCity, Visual Studio Team Services, Screwdriver, Concourse, Netlify, CodeBuild, Codefresh,
AppCenter, or BitBucket Pipelines.

[![npm](https://img.shields.io/npm/v/danger.svg)](https://www.npmjs.com/package/danger)
[![Build Status](https://travis-ci.org/danger/danger-js.svg?branch=master)](https://travis-ci.org/danger/danger-js)
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "9.1.8",
"version": "9.2.0",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
48 changes: 48 additions & 0 deletions source/ci_source/providers/BuddyWorks.ts
@@ -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
82 changes: 82 additions & 0 deletions source/ci_source/providers/_tests/_buddyWorks.test.ts
@@ -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"
)
})
})
3 changes: 3 additions & 0 deletions source/ci_source/providers/index.ts
@@ -1,6 +1,7 @@
import { AppCenter } from "./AppCenter"
import { Bitrise } from "./Bitrise"
import { BuddyBuild } from "./BuddyBuild"
import { BuddyWorks } from "./BuddyWorks"
import { Buildkite } from "./Buildkite"
import { Circle } from "./Circle"
import { CodeBuild } from "./CodeBuild"
Expand Down Expand Up @@ -38,6 +39,7 @@ const providers = [
Drone,
Buildkite,
BuddyBuild,
BuddyWorks,
VSTS,
Bitrise,
TeamCity,
Expand Down Expand Up @@ -65,6 +67,7 @@ const realProviders = [
Drone,
Buildkite,
BuddyBuild,
BuddyWorks,
VSTS,
TeamCity,
Screwdriver,
Expand Down

0 comments on commit 77325ea

Please sign in to comment.