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/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",
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)
)