diff --git a/CHANGELOG.md b/CHANGELOG.md index 34cf3f247..28c6ecc45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ - 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] ## 11.1.2 @@ -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 @@ -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 @@ -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 diff --git a/source/ci_source/providers/GitLabCI.ts b/source/ci_source/providers/GitLabCI.ts index cf7fc8adf..6b6832116 100644 --- a/source/ci_source/providers/GitLabCI.ts +++ b/source/ci_source/providers/GitLabCI.ts @@ -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 { diff --git a/source/ci_source/providers/_tests/_gitlab.test.ts b/source/ci_source/providers/_tests/_gitlab.test.ts new file mode 100644 index 000000000..f76f157fb --- /dev/null +++ b/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") + }) +})