From 441d5865d48c4d0bceea1c1c94bfdbb6416c12ea Mon Sep 17 00:00:00 2001 From: Steven Peterson Date: Wed, 17 Apr 2019 12:46:54 -0500 Subject: [PATCH 01/11] Add support for Codefresh --- source/ci_source/providers/Codefresh.ts | 44 +++++++++++++++++++++++++ source/ci_source/providers/index.ts | 3 ++ 2 files changed, 47 insertions(+) create mode 100644 source/ci_source/providers/Codefresh.ts diff --git a/source/ci_source/providers/Codefresh.ts b/source/ci_source/providers/Codefresh.ts new file mode 100644 index 000000000..3f86e7c22 --- /dev/null +++ b/source/ci_source/providers/Codefresh.ts @@ -0,0 +1,44 @@ +import { Env, CISource } from "../ci_source" +import { ensureEnvKeysExist } from "../ci_source_helpers" + +/// Codefresh environment variables: https://codefresh.io/docs/docs/codefresh-yaml/variables/ + +export class Codefresh implements CISource { + constructor(private readonly env: Env) {} + + get name(): string { + return "Codefresh" + } + + get isCI(): boolean { + return ensureEnvKeysExist(this.env, ["CF_BUILD_ID"]) + } + + get isPR(): boolean { + return ensureEnvKeysExist(this.env, ["CF_PULL_REQUEST_NUMBER"]) + } + + get pullRequestID(): string { + if (this.env.CF_PULL_REQUEST_NUMBER) { + return this.env.CF_PULL_REQUEST_NUMBER + } else { + return "" + } + } + + get repoSlug(): string { + const owner = this.env.CF_REPO_OWNER + const reponame = this.env.CF_REPO_NAME + return owner && reponame ? `${owner}/${reponame}` : "" + } + + get repoURL(): string { + const owner = this.env.CF_REPO_OWNER + const reponame = this.env.CF_REPO_NAME + return owner && reponame ? `https://github.com/${owner}/${this.env.reponame}` : "" + } + + get ciRunURL() { + return this.env["CF_BUILD_URL"] + } +} diff --git a/source/ci_source/providers/index.ts b/source/ci_source/providers/index.ts index 88204abe9..fa7cd9581 100644 --- a/source/ci_source/providers/index.ts +++ b/source/ci_source/providers/index.ts @@ -3,6 +3,7 @@ import { BuddyBuild } from "./BuddyBuild" import { Buildkite } from "./Buildkite" import { Circle } from "./Circle" import { CodeBuild } from "./CodeBuild" +import { Codefresh } from "./Codefresh" import { Codeship } from "./Codeship" import { Concourse } from "./Concourse" import { DockerCloud } from "./DockerCloud" @@ -40,6 +41,7 @@ const providers = [ Concourse, Netlify, CodeBuild, + Codefresh, ] // Mainly used for Dangerfile linting @@ -62,6 +64,7 @@ const realProviders = [ Concourse, Netlify, CodeBuild, + Codefresh, ] export { providers, realProviders } From daacef48b62b5ea2e1a8f9977adb40b35e61ffa8 Mon Sep 17 00:00:00 2001 From: Steven Peterson Date: Fri, 19 Apr 2019 13:56:00 -0700 Subject: [PATCH 02/11] Update Codefresh.ts - Required PR number to be an integer - Remove unnecessary `repoURL()` implementation - Other cleanup - Add documenation for CI setup --- source/ci_source/providers/Codefresh.ts | 47 +++++++++++++++++++------ 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/source/ci_source/providers/Codefresh.ts b/source/ci_source/providers/Codefresh.ts index 3f86e7c22..e71e31f30 100644 --- a/source/ci_source/providers/Codefresh.ts +++ b/source/ci_source/providers/Codefresh.ts @@ -1,7 +1,35 @@ import { Env, CISource } from "../ci_source" -import { ensureEnvKeysExist } from "../ci_source_helpers" +import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers" -/// Codefresh environment variables: https://codefresh.io/docs/docs/codefresh-yaml/variables/ +/** + * ### CI Setup + * + * To set up Danger on Codefresh, create a freestyle step in your Codefresh yaml configuration: + * + * ```yml + * Danger: + * title: Run Danger + * image: node:latest + * working_directory: ${{main_clone}} + * entry_point: '/bin/bash' + * cmd: + * - '-ce' + * - | + * npm install -g yarn + * yarn add danger --dev + * yarn danger ci --failOnErrors + * when: + * steps: + * - name: main_clone + * on: + * - success + * ``` + * + * The `failOnErrors` option is required in order to ensure that the step fails properly when Danger fails. If you don't wnat this behavior, you can remove this option. + * + * Don't forget to add the `DANGER_GITHUB_API_TOKEN` variable to your pipeline settings so that Danger can properly post comments to your pull request. + * + */ export class Codefresh implements CISource { constructor(private readonly env: Env) {} @@ -11,11 +39,14 @@ export class Codefresh implements CISource { } get isCI(): boolean { - return ensureEnvKeysExist(this.env, ["CF_BUILD_ID"]) + return ensureEnvKeysExist(this.env, ["CF_BUILD_ID", "CF_BUILD_URL"]) } get isPR(): boolean { - return ensureEnvKeysExist(this.env, ["CF_PULL_REQUEST_NUMBER"]) + return ( + ensureEnvKeysExist(this.env, ["CF_PULL_REQUEST_NUMBER"]) && + ensureEnvKeysAreInt(this.env, ["CF_PULL_REQUEST_NUMBER"]) + ) } get pullRequestID(): string { @@ -32,13 +63,7 @@ export class Codefresh implements CISource { return owner && reponame ? `${owner}/${reponame}` : "" } - get repoURL(): string { - const owner = this.env.CF_REPO_OWNER - const reponame = this.env.CF_REPO_NAME - return owner && reponame ? `https://github.com/${owner}/${this.env.reponame}` : "" - } - get ciRunURL() { - return this.env["CF_BUILD_URL"] + return this.env.CF_BUILD_URL } } From 52da5fc1ee35547a4ab383c08575677c62ffa7d9 Mon Sep 17 00:00:00 2001 From: Steven Peterson Date: Fri, 19 Apr 2019 13:56:29 -0700 Subject: [PATCH 03/11] Add tests for Codefresh --- .../providers/_tests/_codefresh.test.ts | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 source/ci_source/providers/_tests/_codefresh.test.ts diff --git a/source/ci_source/providers/_tests/_codefresh.test.ts b/source/ci_source/providers/_tests/_codefresh.test.ts new file mode 100644 index 000000000..07d5f027b --- /dev/null +++ b/source/ci_source/providers/_tests/_codefresh.test.ts @@ -0,0 +1,80 @@ +import { Codefresh } from "../Codefresh" +import { getCISourceForEnv } from "../../get_ci_source" + +const correctEnv = { + CF_REPO_OWNER: "codefresh", + CF_REPO_NAME: "someproject", + CF_BUILD_ID: "1501", + CF_PULL_REQUEST_NUMBER: "800", + CF_BUILD_URL: "https://g.codefresh.io/build/1234", +} + +describe("being found when looking for CI", () => { + it("finds Codefresh with the right ENV", () => { + const ci = getCISourceForEnv(correctEnv) + expect(ci).toBeInstanceOf(Codefresh) + }) +}) + +describe(".isCI", () => { + it("validates when all Codefresh environment vars are set", () => { + const codefresh = new Codefresh(correctEnv) + expect(codefresh.isCI).toBeTruthy() + }) + + it("does not validate without env", () => { + const codefresh = new Codefresh({}) + expect(codefresh.isCI).toBeFalsy() + }) +}) + +describe(".isPR", () => { + it("validates when all Codefresh environment vars are set", () => { + const codefresh = new Codefresh(correctEnv) + expect(codefresh.isPR).toBeTruthy() + }) + + it("does not validate outside of Codefresh", () => { + const codefresh = new Codefresh({}) + expect(codefresh.isPR).toBeFalsy() + }) + + const envs = ["CF_REPO_OWNER", "CF_REPO_NAME", "CF_BUILD_ID", "CF_PULL_REQUEST_NUMBER", "CF_BUILD_URL"] + envs.forEach((key: string) => { + let env = { + CF_REPO_OWNER: "codefresh", + CF_REPO_NAME: "someproject", + CF_BUILD_ID: "1501", + CF_PULL_REQUEST_NUMBER: "800", + CF_BUILD_URL: "https://g.codefresh.io/build/1234", + } + env[key] = null + + it(`does not validate when ${key} is missing`, () => { + const codefresh = new Codefresh({}) + expect(codefresh.isPR).toBeFalsy() + }) + }) + + it("needs to have an integer PR number", () => { + let env = { + CF_PULL_REQUEST_NUMBER: "asdasd", + } + const codefresh = new Codefresh(env) + expect(codefresh.isPR).toBeFalsy() + }) +}) + +describe(".pullRequestID", () => { + it("pulls it out of the env", () => { + const codefresh = new Codefresh({ CF_PULL_REQUEST_NUMBER: "800" }) + expect(codefresh.pullRequestID).toEqual("800") + }) +}) + +describe(".repoSlug", () => { + it("derives it from the PR Url", () => { + const codefresh = new Codefresh(correctEnv) + expect(codefresh.repoSlug).toEqual("codefresh/someproject") + }) +}) From 75de9dace8c9810535a8c021a282750b7be8b62d Mon Sep 17 00:00:00 2001 From: Steven Peterson Date: Fri, 19 Apr 2019 13:57:10 -0700 Subject: [PATCH 04/11] Add Codefresh to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5bd7409a..4a9da1f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Cleans up the declarations a little bit - [@orta] +- Adds support for [Codefresh CI](https://codefresh.io) - [@stevenp] # 7.1.2 @@ -1619,6 +1620,7 @@ Not usable for others, only stubs of classes etc. - [@orta] [@sgtcoolguy]: https://github.com/sgtcoolguy [@sharkysharks]: https://github.com/sharkysharks [@stevemoser]: https://github.com/stevemoser +[@stevenp]: https://github.com/stevenp [@sunshinejr]: https://github.com/sunshinejr [@tychota]: https://github.com/tychota [@urkle]: https://github.com/urkle From c2fd854310fa84fa1b57350637077dbffe768919 Mon Sep 17 00:00:00 2001 From: Steven Peterson Date: Fri, 19 Apr 2019 13:57:56 -0700 Subject: [PATCH 05/11] Add Codefresh to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31737afb4..da527aa3c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ You can use Danger to codify your teams norms, leaving humans to think about har Danger JS works with GitHub or BitBucket Server for code review, then with: Travis CI, Circle CI, GitHub Actions, Semaphore, Jenkins, Docker Cloud, Bitrise, surf-build, Codeship, Drone, Buildkite, Nevercode, buddybuild, TeamCity, -Visual Studio Team Services, Screwdriver, Concourse, Netlify or CodeBuild. +Visual Studio Team Services, Screwdriver, Concourse, Netlify, CodeBuild or Codefresh. [![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) From 30cc3e36c48b6136987d28d9e984425b7cb72ffb Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 19 Apr 2019 17:18:29 -0400 Subject: [PATCH 06/11] Prepare for release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9da1f9d..17fc178d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ +# 7.1.3 + - Cleans up the declarations a little bit - [@orta] - Adds support for [Codefresh CI](https://codefresh.io) - [@stevenp] From e4b6cfa3cff49f07e1948686219a3919a1cbda85 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 19 Apr 2019 17:19:42 -0400 Subject: [PATCH 07/11] Release 7.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a23cb1c18..40bce4efd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "7.1.2", + "version": "7.1.3", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts", From 83ecefb24303ea4b03c52d072f4bbb17f39ec5c9 Mon Sep 17 00:00:00 2001 From: Jaume Salgado Date: Fri, 26 Apr 2019 23:33:21 +0200 Subject: [PATCH 08/11] Fix CHANGELOG.md documentation about "--failOnErrors" --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17fc178d6..a954addc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,9 +71,8 @@ # 7.0.18 -- Adds a CLI option `--fail-on-errors` so that you can force `danger ci` to return a failed exit code on any `fail`s in +- Adds a CLI option `--failOnErrors` so that you can force `danger ci` to return a failed exit code on any `fail`s in a Dangerfile [@f-meloni] -- Add a failOnErrors option to fail the build if there are error on the danger report [@f-meloni] # 7.0.17 From bc7ef42d8e06284eed81d1f17b3bde6b1e1d5af8 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Thu, 2 May 2019 13:25:12 +0100 Subject: [PATCH 09/11] Remove hard-coded artsy values --- source/platforms/github/GitHubUtils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/platforms/github/GitHubUtils.ts b/source/platforms/github/GitHubUtils.ts index d9dc98e73..977d74e7e 100644 --- a/source/platforms/github/GitHubUtils.ts +++ b/source/platforms/github/GitHubUtils.ts @@ -157,19 +157,19 @@ export const createOrUpdatePR = (pr: GitHubPRDSL | undefined, api: GitHub) => as d("Updating existing PR") return await api.pulls.update({ number: existingPR.number, - base: "source", - owner: "artsy", - repo: "artsy.github.io", + base: config.baseBranch, + owner, + repo, title: config.title, body: config.body, }) } else { d("Creating a new PR") return await api.pulls.create({ - base: "source", + base: config.baseBranch, head: config.newBranchName, - owner: "artsy", - repo: "artsy.github.io", + owner, + repo, title: config.title, }) } From 3be4477d8b0eee4d4d4b43c1ee578508cdd3ba93 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 2 May 2019 08:55:27 -0400 Subject: [PATCH 10/11] PRepare for release --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a954addc0..e1e57ca92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ +# 7.1.4 + +- Un-hardcodes the repo in `danger.github.utils.createOrUpdatePR`- [@ds300] + # 7.1.3 - Cleans up the declarations a little bit - [@orta] @@ -71,8 +75,8 @@ # 7.0.18 -- Adds a CLI option `--failOnErrors` so that you can force `danger ci` to return a failed exit code on any `fail`s in - a Dangerfile [@f-meloni] +- Adds a CLI option `--failOnErrors` so that you can force `danger ci` to return a failed exit code on any `fail`s in a + Dangerfile [@f-meloni] # 7.0.17 @@ -1628,3 +1632,4 @@ Not usable for others, only stubs of classes etc. - [@orta] [@wizardishungry]: https://github.com/wizardishungry [@dblandin]: https://github.com/dblandin [@paulmelnikow]: https://github.com/paulmelnikow +[@ds300]: https://github.com/ds300 From 78726f7c62f22f677fc44fd71b3b3d786b2b9d74 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Thu, 2 May 2019 08:57:06 -0400 Subject: [PATCH 11/11] Release 7.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40bce4efd..d1a05d713 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danger", - "version": "7.1.3", + "version": "7.1.4", "description": "Unit tests for Team Culture", "main": "distribution/danger.js", "typings": "distribution/danger.d.ts",