Skip to content

Commit

Permalink
Update Bamboo CI source for compatibility with 7.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Natasha Spiridonova committed Jul 9, 2020
1 parent 924a88f commit b6e2f23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions source/ci_source/providers/Bamboo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ export class Bamboo implements CISource {
}

get isPR(): boolean {
const mustHave = ["bamboo_inject_prId", "bamboo_planRepository_repositoryUrl", "bamboo_buildPlanName"]
const mustBeInts = ["bamboo_inject_prId"]
const mustHave = ["bamboo_repository_pr_key", "bamboo_planRepository_repositoryUrl", "bamboo_buildPlanName"]
const mustBeInts = ["bamboo_repository_pr_key"]
return ensureEnvKeysExist(this.env, mustHave) && ensureEnvKeysAreInt(this.env, mustBeInts)
}

get pullRequestID(): string {
return `${this.env.bamboo_inject_prId}`
return `${this.env.bamboo_repository_pr_key}`
}

get repoSlug(): string {
//ssh://git@bt01.cliplister.com:7999/clfr30/bc3_complete.git
// bamboo_inject_slug="projects/CLFR30/repos/bc3_complete" \

const [, project, slug] = this.env.bamboo_planRepository_repositoryUrl.match(/\/(\w+)\/(\w+(?:.git)?)$/)
const [, project, slug] = this.env.bamboo_planRepository_repositoryUrl.match(/\/(\w+)\/([a-zA-Z0-9_\.-]+(?:.git)?)$/)

return `projects/${project}/repos/${slug.replace(/\.[^.]+$/, "")}`
}
Expand Down
16 changes: 13 additions & 3 deletions source/ci_source/providers/_tests/_bamboo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
bamboo_buildPlanName: "My Build Plan",
bamboo_inject_prId: "1234",
bamboo_repository_pr_key: "1234",
bamboo_planRepository_repositoryUrl: "ssh://git@bitbucket.mycompany.com:7999/my_project/my_repository.git",
}

const correctDotedRepoEnv = {
bamboo_buildPlanName: "My Build Plan",
bamboo_repository_pr_key: "1234",
bamboo_planRepository_repositoryUrl: "ssh://git@bitbucket.mycompany.com:7999/my_project/my.custom.repository.git",
}

describe("being found when looking for CI", () => {
it("finds Bamboo with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
Expand Down Expand Up @@ -48,7 +54,7 @@ describe(".isPR", () => {

it("needs to have a PR number", () => {
let env = Object.assign({}, correctEnv)
delete env["bamboo_inject_prId"]
delete env["bamboo_repository_pr_key"]
const pipelines = new Bamboo(env)
expect(pipelines.isPR).toBeFalsy()
})
Expand All @@ -57,7 +63,7 @@ describe(".isPR", () => {

describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const pipelines = new Bamboo({ bamboo_inject_prId: "800" })
const pipelines = new Bamboo({ bamboo_repository_pr_key: "800" })
expect(pipelines.pullRequestID).toEqual("800")
})
})
Expand All @@ -67,4 +73,8 @@ describe(".repoSlug", () => {
const pipelines = new Bamboo(correctEnv)
expect(pipelines.repoSlug).toEqual("projects/my_project/repos/my_repository")
})
it("derives it from the PR doted Url", () => {
const pipelines = new Bamboo(correctDotedRepoEnv)
expect(pipelines.repoSlug).toEqual("projects/my_project/repos/my.custom.repository")
})
})

0 comments on commit b6e2f23

Please sign in to comment.