From 1813011282b82db1c90c3706e9551d3b0aaf9ff3 Mon Sep 17 00:00:00 2001 From: saad Date: Tue, 21 Jan 2020 18:29:01 +0100 Subject: [PATCH 1/4] Add an environment variable for gitlab project ID. Use gitlab project id. when not defined. use project name instead. Add doc about gitlab project id. Update gitlabApi unit tests, and repo slug documentation. --- docs/usage/gitlab.html.md | 4 ++++ source/danger-incoming-process-schema.json | 2 +- source/platforms/gitlab/_tests/_gitlab_api.test.ts | 12 ++++++------ source/platforms/platform.ts | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/usage/gitlab.html.md b/docs/usage/gitlab.html.md index 822d295c8..0ca762d63 100644 --- a/docs/usage/gitlab.html.md +++ b/docs/usage/gitlab.html.md @@ -11,6 +11,10 @@ variable on your CI system: - `DANGER_GITLAB_API_TOKEN` = An access token for the account which will post comments +You will need also to add an environment variable for your gitlab project id: + +- `DANGER_GITLAB_PROJECT_ID` = Gitlab project id can be found in (Settings -> General). if not defined, project name will be used instead + If you are using a GitLab version prior to 11.7 you will also need to define the following environment variable: - `DANGER_GITLAB_HOST` = Defaults to `https://gitlab.com` but you can use it for your own url diff --git a/source/danger-incoming-process-schema.json b/source/danger-incoming-process-schema.json index 660ddc495..2f6fab144 100644 --- a/source/danger-incoming-process-schema.json +++ b/source/danger-incoming-process-schema.json @@ -1189,7 +1189,7 @@ "type": "string" }, "repoSlug": { - "description": "A path like \"artsy/eigen\"", + "description": "Project ID \"624\" or a path like \"artsy/eigen\"", "type": "string" } }, diff --git a/source/platforms/gitlab/_tests/_gitlab_api.test.ts b/source/platforms/gitlab/_tests/_gitlab_api.test.ts index cc2fb45ac..031108fbc 100644 --- a/source/platforms/gitlab/_tests/_gitlab_api.test.ts +++ b/source/platforms/gitlab/_tests/_gitlab_api.test.ts @@ -6,7 +6,7 @@ import { readFileSync } from "fs" const nockBack = nock.back nockBack.fixtures = __dirname + "/fixtures" -// We're testing https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27117 +// We're testing https://gitlab.com/456/merge_requests/27117 // This has been chosen because it is already merged and publicly available, it's unlikely to change /** Returns a fixture. */ @@ -27,7 +27,7 @@ describe("GitLab API", () => { beforeEach(() => { api = new GitLabAPI( - { pullRequestID: "27117", repoSlug: "gitlab-org/gitlab-ce" }, + { pullRequestID: "27117", repoSlug: "456" }, getGitLabAPICredentialsFromEnv({ DANGER_GITLAB_HOST: "gitlab.com", DANGER_GITLAB_API_TOKEN: "FAKE_DANGER_GITLAB_API_TOKEN", @@ -37,22 +37,22 @@ describe("GitLab API", () => { it("configures host from CI_API_V4_URL", () => { api = new GitLabAPI( - { pullRequestID: "27117", repoSlug: "gitlab-org/gitlab-ce" }, + { pullRequestID: "27117", repoSlug: "456" }, getGitLabAPICredentialsFromEnv({ CI_API_V4_URL: "https://testciapiv4url.com/api/v4", DANGER_GITLAB_API_TOKEN: "FAKE_DANGER_GITLAB_API_TOKEN", }) ) - expect(api.projectURL).toBe("https://testciapiv4url.com/gitlab-org/gitlab-ce") + expect(api.projectURL).toBe("https://testciapiv4url.com/456") }) it("projectURL is defined", () => { - expect(api.projectURL).toBe("https://gitlab.com/gitlab-org/gitlab-ce") + expect(api.projectURL).toBe("https://gitlab.com/456") }) it("mergeRequestURL is defined", () => { - expect(api.mergeRequestURL).toBe("https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27117") + expect(api.mergeRequestURL).toBe("https://gitlab.com/456/merge_requests/27117") }) const sanitizeUserResponse = (nocks: NockDefinition[]): NockDefinition[] => { diff --git a/source/platforms/platform.ts b/source/platforms/platform.ts index 1b4d34528..df0e5a270 100644 --- a/source/platforms/platform.ts +++ b/source/platforms/platform.ts @@ -132,10 +132,11 @@ export function getPlatformForEnv(env: Env, source: CISource): Platform { // GitLab if (env["DANGER_GITLAB_API_TOKEN"] || env["DANGER_PR_PLATFORM"] === GitLab.name) { + const repoSlug = env["DANGER_GITLAB_PROJECT_ID"] ? env["DANGER_GITLAB_PROJECT_ID"] : source.repoSlug const api = new GitLabAPI( { pullRequestID: source.pullRequestID, - repoSlug: source.repoSlug, + repoSlug: repoSlug, }, getGitLabAPICredentialsFromEnv(env) ) From 7fa2aeb4011892986ea72240db42f9dadaa44a21 Mon Sep 17 00:00:00 2001 From: saad Date: Tue, 21 Jan 2020 19:08:13 +0100 Subject: [PATCH 2/4] Update gitlab api fixtures following gitlab project id use. --- .../gitlab/_tests/fixtures/getMergeRequestChanges.json | 9 +++++++-- .../gitlab/_tests/fixtures/getMergeRequestCommits.json | 4 ++-- .../gitlab/_tests/fixtures/getMergeRequestInfo.json | 2 +- .../_tests/fixtures/getMergeRequestInlineNotes.json | 4 ++-- .../gitlab/_tests/fixtures/getMergeRequestNotes.json | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/source/platforms/gitlab/_tests/fixtures/getMergeRequestChanges.json b/source/platforms/gitlab/_tests/fixtures/getMergeRequestChanges.json index 8a378ad5e..2d7bb8c7c 100644 --- a/source/platforms/gitlab/_tests/fixtures/getMergeRequestChanges.json +++ b/source/platforms/gitlab/_tests/fixtures/getMergeRequestChanges.json @@ -2,7 +2,7 @@ { "scope": "https://gitlab.com:443", "method": "GET", - "path": "/api/v4/projects/gitlab-org%2Fgitlab-ce/merge_requests/27117/changes", + "path": "/api/v4/projects/456/merge_requests/27117/changes", "body": "", "status": 200, "response": { @@ -58,7 +58,12 @@ ], "source_project_id": 13083, "target_project_id": 13083, - "labels": ["Danger bot", "Plan", "backend", "backstage"], + "labels": [ + "Danger bot", + "Plan", + "backend", + "backstage" + ], "work_in_progress": false, "milestone": { "id": 655280, diff --git a/source/platforms/gitlab/_tests/fixtures/getMergeRequestCommits.json b/source/platforms/gitlab/_tests/fixtures/getMergeRequestCommits.json index 1171fda03..4dc9dd8a6 100644 --- a/source/platforms/gitlab/_tests/fixtures/getMergeRequestCommits.json +++ b/source/platforms/gitlab/_tests/fixtures/getMergeRequestCommits.json @@ -2,7 +2,7 @@ { "scope": "https://gitlab.com:443", "method": "GET", - "path": "/api/v4/projects/gitlab-org%2Fgitlab-ce/merge_requests/27117/commits", + "path": "/api/v4/projects/456/merge_requests/27117/commits", "body": "", "status": 200, "response": [ @@ -51,7 +51,7 @@ "Etag", "W/\"478bcb3a3b56ea7180c04159ff3adea5\"", "Link", - "; rel=\"first\", ; rel=\"last\"", + "; rel=\"first\", ; rel=\"last\"", "Vary", "Origin", "X-Content-Type-Options", diff --git a/source/platforms/gitlab/_tests/fixtures/getMergeRequestInfo.json b/source/platforms/gitlab/_tests/fixtures/getMergeRequestInfo.json index ae25daf87..33dd5f46d 100644 --- a/source/platforms/gitlab/_tests/fixtures/getMergeRequestInfo.json +++ b/source/platforms/gitlab/_tests/fixtures/getMergeRequestInfo.json @@ -2,7 +2,7 @@ { "scope": "https://gitlab.com:443", "method": "GET", - "path": "/api/v4/projects/gitlab-org%2Fgitlab-ce/merge_requests/27117", + "path": "/api/v4/projects/456/merge_requests/27117", "body": "", "status": 200, "response": { diff --git a/source/platforms/gitlab/_tests/fixtures/getMergeRequestInlineNotes.json b/source/platforms/gitlab/_tests/fixtures/getMergeRequestInlineNotes.json index 07891dd80..c2fb0028d 100644 --- a/source/platforms/gitlab/_tests/fixtures/getMergeRequestInlineNotes.json +++ b/source/platforms/gitlab/_tests/fixtures/getMergeRequestInlineNotes.json @@ -2,7 +2,7 @@ { "scope": "https://gitlab.com:443", "method": "GET", - "path": "/api/v4/projects/gitlab-org%2Fgitlab-ce/merge_requests/27117/notes", + "path": "/api/v4/projects/456/merge_requests/27117/notes", "body": "", "status": 200, "response": [ @@ -356,7 +356,7 @@ "Etag", "W/\"edab8aad8eea37dd376785c34c7c250f\"", "Link", - "; rel=\"first\", ; rel=\"last\"", + "; rel=\"first\", ; rel=\"last\"", "Vary", "Origin", "X-Content-Type-Options", diff --git a/source/platforms/gitlab/_tests/fixtures/getMergeRequestNotes.json b/source/platforms/gitlab/_tests/fixtures/getMergeRequestNotes.json index e44aa2c3f..fc28055ea 100644 --- a/source/platforms/gitlab/_tests/fixtures/getMergeRequestNotes.json +++ b/source/platforms/gitlab/_tests/fixtures/getMergeRequestNotes.json @@ -2,7 +2,7 @@ { "scope": "https://gitlab.com:443", "method": "GET", - "path": "/api/v4/projects/gitlab-org%2Fgitlab-ce/merge_requests/27117/notes", + "path": "/api/v4/projects/456/merge_requests/27117/notes", "body": "", "status": 200, "response": [ @@ -356,7 +356,7 @@ "Etag", "W/\"edab8aad8eea37dd376785c34c7c250f\"", "Link", - "; rel=\"first\", ; rel=\"last\"", + "; rel=\"first\", ; rel=\"last\"", "Vary", "Origin", "X-Content-Type-Options", From 84ced7a64c9b6d60fe3b4aeb4d6706293cb58989 Mon Sep 17 00:00:00 2001 From: Saad El Oulladi Date: Fri, 21 Feb 2020 10:52:09 +0100 Subject: [PATCH 3/4] Update docs/usage/gitlab.html.md Minor update to documentation comment following review. Co-Authored-By: Orta --- docs/usage/gitlab.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/gitlab.html.md b/docs/usage/gitlab.html.md index 0ca762d63..113d7c7ef 100644 --- a/docs/usage/gitlab.html.md +++ b/docs/usage/gitlab.html.md @@ -11,7 +11,7 @@ variable on your CI system: - `DANGER_GITLAB_API_TOKEN` = An access token for the account which will post comments -You will need also to add an environment variable for your gitlab project id: +You may need also to add an environment variable for your Gitlab project id: - `DANGER_GITLAB_PROJECT_ID` = Gitlab project id can be found in (Settings -> General). if not defined, project name will be used instead From 3981e722b62f550c9f7be24d2469436fb225c32a Mon Sep 17 00:00:00 2001 From: saad Date: Thu, 12 Mar 2020 11:19:03 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Revert=C2=A084ced7a64c9b6d60fe3b4aeb4d67062?= =?UTF-8?q?93cb58989?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/usage/gitlab.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/gitlab.html.md b/docs/usage/gitlab.html.md index 113d7c7ef..0ca762d63 100644 --- a/docs/usage/gitlab.html.md +++ b/docs/usage/gitlab.html.md @@ -11,7 +11,7 @@ variable on your CI system: - `DANGER_GITLAB_API_TOKEN` = An access token for the account which will post comments -You may need also to add an environment variable for your Gitlab project id: +You will need also to add an environment variable for your gitlab project id: - `DANGER_GITLAB_PROJECT_ID` = Gitlab project id can be found in (Settings -> General). if not defined, project name will be used instead