Skip to content

Commit

Permalink
Merge pull request #1319 from ivankatliarchuk/fix-gitlab-forks
Browse files Browse the repository at this point in the history
GitLab: Improve GitLab CI support for MRs from forks
  • Loading branch information
orta committed Oct 1, 2022
2 parents f5eeee0 + ba84b5f commit 6a216a1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Expand Up @@ -16,7 +16,8 @@

<!-- Your comment below this -->
- Append random string to danger-results.json and danger-dsl.json files to better support concurrent processes #1311

- GitLab: Improve support for MRs from forks [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
- GitLab: Added provider tests [#1319](https://github.com/danger/danger-js/pull/1319) [@ivankatliarchuk]
<!-- Your comment above this -->

## 11.1.2
Expand All @@ -28,7 +29,7 @@

- Bug fix for over-deleting inline comments #1287

## 11.1.0
## 11.1.0

- Adds support for the new [GitHub Job summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) API via:
- `danger.github.setSummaryMarkdown("[markdown]")` for the JavaScript DSL
Expand Down Expand Up @@ -57,7 +58,7 @@
# 11.0.0 -> 11.0.2

- *Breaking:* Upgrade @octokit/rest from ^16.43.1 to ^18.12.0 - [#1204](https://github.com/danger/danger-js/pull/1204) [@fbartho]

This is only likely to hit you if you use `danger.github.api` pretty extensively in your Dangerfiles, but better to keep an eye out.

# 10.8.1
Expand Down Expand Up @@ -1947,6 +1948,7 @@ Not usable for others, only stubs of classes etc. - [@orta]
[@hmschreiner]: https://github.com/hmschreiner
[@hongrich]: https://github.com/hongrich
[@igorbek]: https://github.com/igorbek
[@ivankatliarchuk]: https://github.com/ivankatliarchuk
[@iljadaderko]: https://github.com/IljaDaderko
[@imorente]: https://github.com/imorente
[@jamiebuilds]: https://github.com/jamiebuilds
Expand Down
2 changes: 1 addition & 1 deletion source/ci_source/providers/GitLabCI.ts
Expand Up @@ -23,7 +23,7 @@ export class GitLabCI implements CISource {
}

get repoSlug(): string {
return this.env.CI_PROJECT_PATH
return this.env.CI_MERGE_REQUEST_PROJECT_PATH || this.env.CI_PROJECT_PATH
}

get commitHash(): string {
Expand Down
47 changes: 47 additions & 0 deletions source/ci_source/providers/_tests/_gitlab.test.ts
@@ -0,0 +1,47 @@
import { GitLabCI } from "../GitLabCI"
import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
GITLAB_CI: "true",
CI_MERGE_REQUEST_IID: "27117",
CI_PROJECT_PATH: "gitlab-org/gitlab-foss",
}

describe("being found when looking for CI", () => {
it("finds GitLab with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(GitLabCI)
})
})

describe(".isCI", () => {
it("validates when all GitLab environment vars are set", async () => {
const result = new GitLabCI(correctEnv)
expect(result.isCI).toBeTruthy()
})

it("does not validate without env", async () => {
const result = new GitLabCI({})
expect(result.isCI).toBeFalsy()
})
})

describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const result = new GitLabCI(correctEnv)
expect(result.pullRequestID).toEqual("27117")
})
})

describe(".repoSlug", () => {
it("derives it from 'CI_PROJECT_PATH' env var", () => {
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss")
})

it("derives it form 'CI_MERGE_REQUEST_PROJECT_PATH' env var if set", () => {
correctEnv["CI_MERGE_REQUEST_PROJECT_PATH"] = "gitlab-org/release-tools"
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/release-tools")
})
})

0 comments on commit 6a216a1

Please sign in to comment.