Skip to content

Commit

Permalink
Take commit hash from CircleCI
Browse files Browse the repository at this point in the history
Similar to the support of Jenkins commit hash. Fixes the same problem as
fixed in 73d1439:

> 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.
  • Loading branch information
valscion committed Apr 16, 2020
1 parent f58ee85 commit dbac25a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/ci_source/providers/Circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
16 changes: 16 additions & 0 deletions source/ci_source/providers/_tests/_circle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit dbac25a

Please sign in to comment.