From dafdb028d0e520b81474511f6b3f6d6f04b96906 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 1 Oct 2022 11:40:59 +0100 Subject: [PATCH 1/5] fix: added provider gitlab tests --- source/ci_source/providers/GitLabCI.ts | 1 + .../providers/_tests/_gitlab.test.ts | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 source/ci_source/providers/_tests/_gitlab.test.ts diff --git a/source/ci_source/providers/GitLabCI.ts b/source/ci_source/providers/GitLabCI.ts index cf7fc8adf..26f4a952f 100644 --- a/source/ci_source/providers/GitLabCI.ts +++ b/source/ci_source/providers/GitLabCI.ts @@ -23,6 +23,7 @@ export class GitLabCI implements CISource { } get repoSlug(): string { + // return this.env.CI_MERGE_REQUEST_PROJECT_PATH || this.env.CI_PROJECT_PATH return this.env.CI_PROJECT_PATH } 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..e9c677ab2 --- /dev/null +++ b/source/ci_source/providers/_tests/_gitlab.test.ts @@ -0,0 +1,44 @@ +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", + // DANGER_GITLAB_API_TOKEN: "gitlab_dummy_a829-07bd7559eecb" +} + +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() + }) +}) + +// missed + +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 the PR Url", () => { + const result = new GitLabCI(correctEnv) + expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss") + }) +}) From 47d2085a17cf32609119ecd4f54fd12f1cc80570 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 1 Oct 2022 11:46:58 +0100 Subject: [PATCH 2/5] changelog: update --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 From 3367329ebcb33ea406c1606a9dd412fcb121d32f Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 1 Oct 2022 11:55:05 +0100 Subject: [PATCH 3/5] added forked mr url --- source/ci_source/providers/GitLabCI.ts | 3 +-- source/ci_source/providers/_tests/_gitlab.test.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/ci_source/providers/GitLabCI.ts b/source/ci_source/providers/GitLabCI.ts index 26f4a952f..6b6832116 100644 --- a/source/ci_source/providers/GitLabCI.ts +++ b/source/ci_source/providers/GitLabCI.ts @@ -23,8 +23,7 @@ export class GitLabCI implements CISource { } get repoSlug(): string { - // return this.env.CI_MERGE_REQUEST_PROJECT_PATH || this.env.CI_PROJECT_PATH - 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 index e9c677ab2..7ac0f207c 100644 --- a/source/ci_source/providers/_tests/_gitlab.test.ts +++ b/source/ci_source/providers/_tests/_gitlab.test.ts @@ -5,7 +5,6 @@ const correctEnv = { GITLAB_CI: "true", CI_MERGE_REQUEST_IID: "27117", CI_PROJECT_PATH: "gitlab-org/gitlab-foss", - // DANGER_GITLAB_API_TOKEN: "gitlab_dummy_a829-07bd7559eecb" } describe("being found when looking for CI", () => { @@ -27,8 +26,6 @@ describe(".isCI", () => { }) }) -// missed - describe(".pullRequestID", () => { it("pulls it out of the env", () => { const result = new GitLabCI(correctEnv) @@ -41,4 +38,10 @@ describe(".repoSlug", () => { const result = new GitLabCI(correctEnv) expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss") }) + + it("derives it form forked PR Url", () => { + correctEnv["CI_MERGE_REQUEST_PROJECT_PATH"] = "gitlab-org/release-tools" + const result = new GitLabCI(correctEnv) + expect(result.repoSlug).toEqual("gitlab-org/release-tools") + }) }) From 15c00e06a33fb22fdaff3819b31c157bff439541 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 1 Oct 2022 11:58:00 +0100 Subject: [PATCH 4/5] rename tests --- source/ci_source/providers/_tests/_gitlab.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/ci_source/providers/_tests/_gitlab.test.ts b/source/ci_source/providers/_tests/_gitlab.test.ts index 7ac0f207c..003cfe26d 100644 --- a/source/ci_source/providers/_tests/_gitlab.test.ts +++ b/source/ci_source/providers/_tests/_gitlab.test.ts @@ -34,12 +34,12 @@ describe(".pullRequestID", () => { }) describe(".repoSlug", () => { - it("derives it from the PR Url", () => { + it("derives it 'CI_PROJECT_PATH' env var", () => { const result = new GitLabCI(correctEnv) expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss") }) - it("derives it form forked PR Url", () => { + 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") From ba84b5f70568f0b469e550822a3e90b25ceadce9 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 1 Oct 2022 12:00:09 +0100 Subject: [PATCH 5/5] spell check --- source/ci_source/providers/_tests/_gitlab.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ci_source/providers/_tests/_gitlab.test.ts b/source/ci_source/providers/_tests/_gitlab.test.ts index 003cfe26d..f76f157fb 100644 --- a/source/ci_source/providers/_tests/_gitlab.test.ts +++ b/source/ci_source/providers/_tests/_gitlab.test.ts @@ -34,7 +34,7 @@ describe(".pullRequestID", () => { }) describe(".repoSlug", () => { - it("derives it 'CI_PROJECT_PATH' env var", () => { + it("derives it from 'CI_PROJECT_PATH' env var", () => { const result = new GitLabCI(correctEnv) expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss") })