Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Buddy.works isPR because PR ids are not always ints #917

Merged
merged 4 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

<!-- Your comment below this -->

- Fix Buddy.works isPR because PR ids are not always ints - [@mmiszy]

<!-- Your comment above this -->

# 9.2.0
Expand Down
5 changes: 2 additions & 3 deletions source/ci_source/providers/BuddyWorks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Env, CISource } from "../ci_source"
import { ensureEnvKeysExist, ensureEnvKeysAreInt } from "../ci_source_helpers"
import { ensureEnvKeysExist } from "../ci_source_helpers"
/**
* ### CI Setup
*
Expand Down Expand Up @@ -27,8 +27,7 @@ export class BuddyWorks implements CISource {

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)
return ensureEnvKeysExist(this.env, mustHave)
}

get pullRequestID(): string {
Expand Down
6 changes: 3 additions & 3 deletions source/ci_source/providers/_tests/_buddyWorks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
BUDDY_PIPELINE_ID: "170873",
BUDDY_EXECUTION_PULL_REQUEST_ID: "1799",
BUDDY_EXECUTION_PULL_REQUEST_ID: "pull/1799",
BUDDY_REPO_SLUG: "danger/dangerjs",
BUDDY_EXECUTION_URL:
"https://app.buddy.works/danger/dangerjs/pipelines/pipeline/170873/execution/5d6d49dbaab2cb6fdf975c71",
Expand Down Expand Up @@ -50,7 +50,7 @@ describe(".isPR", () => {
})
})

it("needs to have a PR number", () => {
it("needs to have a PR id", () => {
const env = Object.assign({}, correctEnv)
delete env.BUDDY_EXECUTION_PULL_REQUEST_ID
const buddyWorks = new BuddyWorks(env)
Expand All @@ -61,7 +61,7 @@ describe(".isPR", () => {
describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const buddyWorks = new BuddyWorks(correctEnv)
expect(buddyWorks.pullRequestID).toEqual("1799")
expect(buddyWorks.pullRequestID).toEqual("pull/1799")
Copy link
Member

@orta orta Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need you to return the number "1799" - so I'd check maybe for "pull" in the string and extract the number out in the BuddyWorks class 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of that, it seemed to be working just fine. I'm almost certain there's another env variable which holds just the number. I'll update the PR in a few hours @orta
Thanks for review!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated now @orta

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I was wondering if it made sense to change the return type of get pullRequestID to number? :) This way it would be clear just by looking at the definition that a number is required.

Copy link
Member

@orta orta Sep 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it was being set from somewhere else? The GitHub API takes strings for the pull ID - likely legacy on their side, but I'm open to making them numbest so long as it's parsed back into a string in the API layers

})
})

Expand Down