From dbac25a9510180984572752b59d97a1b36c93b79 Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Thu, 16 Apr 2020 12:57:50 +0300 Subject: [PATCH] Take commit hash from CircleCI Similar to the support of Jenkins commit hash. Fixes the same problem as fixed in 73d14395582362224d6458e31bce74f6e5a3d4ee: > Danger doesn't currently have a way to understand on which commit is > running. To get the current commit it asks to the platform the list of > commits on the PR and assumes that is running on the last one. This > creates few problems when you push a new commit before Danger runs on > the CI for the previous commit, because it will assume is running on > the last one, but that is actually not true, and that means that both > the status update and the commit hash in the Danger comment signature > will be wrong. --- source/ci_source/providers/Circle.ts | 4 ++++ .../ci_source/providers/_tests/_circle.test.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/source/ci_source/providers/Circle.ts b/source/ci_source/providers/Circle.ts index ab7b0a072..e85520e7c 100644 --- a/source/ci_source/providers/Circle.ts +++ b/source/ci_source/providers/Circle.ts @@ -96,4 +96,8 @@ export class Circle implements CISource { get ciRunURL() { return this.env["CIRCLE_BUILD_URL"] } + + get commitHash(): string { + return this.env.CIRCLE_SHA1 + } } diff --git a/source/ci_source/providers/_tests/_circle.test.ts b/source/ci_source/providers/_tests/_circle.test.ts index cb8342e5a..34b252eed 100644 --- a/source/ci_source/providers/_tests/_circle.test.ts +++ b/source/ci_source/providers/_tests/_circle.test.ts @@ -97,3 +97,19 @@ describe(".repoSlug", () => { expect(circle.repoSlug).toEqual("artsy/eigen") }) }) + +describe("commit hash", () => { + it("returns correct commit hash when present", () => { + const env = { + ...correctEnv, + CIRCLE_SHA1: "1234abc", + } + const circle = new Circle(env) + expect(circle.commitHash).toEqual("1234abc") + }) + + it("returns no commit hash when not present", () => { + const circle = new Circle(correctEnv) + expect(circle.commitHash).toBeUndefined() + }) +})