Skip to content

Commit

Permalink
Use commit URL to calculate the repo slug
Browse files Browse the repository at this point in the history
When building a fork, `CF_REPO_OWNER` refers to the forked repo instead of the target repo. The only environment variable currently available to derive the correct slug is `CF_COMMIT_URL`.
  • Loading branch information
stevenp committed Jun 14, 2019
1 parent 5274d29 commit 8b42987
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 7 additions & 3 deletions source/ci_source/providers/Codefresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export class Codefresh implements CISource {
}

get repoSlug(): string {
const owner = this.env.CF_REPO_OWNER
const reponame = this.env.CF_REPO_NAME
return owner && reponame ? `${owner}/${reponame}` : ""
const splitSlug = this.env.CF_COMMIT_URL.split("/")
if (splitSlug.length === 7) {
const owner = splitSlug[3]
const reponame = splitSlug[4]
return owner && reponame ? `${owner}/${reponame}` : ""
}
return ""
}

get ciRunURL() {
Expand Down
8 changes: 3 additions & 5 deletions source/ci_source/providers/_tests/_codefresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Codefresh } from "../Codefresh"
import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
CF_REPO_OWNER: "codefresh",
CF_REPO_NAME: "someproject",
CF_COMMIT_URL: "https://github.com/codefresh/someproject/commit/123456",
CF_BUILD_ID: "1501",
CF_PULL_REQUEST_NUMBER: "800",
CF_BUILD_URL: "https://g.codefresh.io/build/1234",
Expand Down Expand Up @@ -39,11 +38,10 @@ describe(".isPR", () => {
expect(codefresh.isPR).toBeFalsy()
})

const envs = ["CF_REPO_OWNER", "CF_REPO_NAME", "CF_BUILD_ID", "CF_PULL_REQUEST_NUMBER", "CF_BUILD_URL"]
const envs = ["CF_COMMIT_URL", "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_COMMIT_URL: "https://github.com/codefresh/someproject/commit/123456",
CF_BUILD_ID: "1501",
CF_PULL_REQUEST_NUMBER: "800",
CF_BUILD_URL: "https://g.codefresh.io/build/1234",
Expand Down

0 comments on commit 8b42987

Please sign in to comment.