From 91d30caed720191b72685a95defc3f35e8b7d6e3 Mon Sep 17 00:00:00 2001
From: Stefan <5585744+casdevs@users.noreply.github.com>
Date: Tue, 19 Jan 2021 09:36:27 +0100
Subject: [PATCH] fix: fetch changelog from self-hosted gitlab independent from
 url (#8336)

---
 .../__snapshots__/gitlab.spec.ts.snap         | 43 +++++++++++++++++++
 lib/workers/pr/changelog/gitlab.spec.ts       | 17 ++++++++
 lib/workers/pr/changelog/index.ts             |  6 ++-
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/lib/workers/pr/changelog/__snapshots__/gitlab.spec.ts.snap b/lib/workers/pr/changelog/__snapshots__/gitlab.spec.ts.snap
index e2150863d8..be55515daa 100644
--- a/lib/workers/pr/changelog/__snapshots__/gitlab.spec.ts.snap
+++ b/lib/workers/pr/changelog/__snapshots__/gitlab.spec.ts.snap
@@ -190,6 +190,49 @@ Object {
 }
 `;
 
+exports[`workers/pr/changelog/gitlab getChangeLogJSON supports self-hosted gitlab changelog 1`] = `
+Object {
+  "hasReleaseNotes": false,
+  "project": Object {
+    "apiBaseUrl": "https://git.test.com/api/v4/",
+    "baseUrl": "https://git.test.com/",
+    "depName": "renovate",
+    "gitlab": "meno/dropzone",
+    "repository": "https://git.test.com/meno/dropzone/",
+  },
+  "versions": Array [
+    Object {
+      "changes": Array [],
+      "compare": Object {},
+      "date": undefined,
+      "releaseNotes": null,
+      "version": "5.6.1",
+    },
+    Object {
+      "changes": Array [],
+      "compare": Object {},
+      "date": "2020-02-13T15:37:00.000Z",
+      "releaseNotes": null,
+      "version": "5.6.0",
+    },
+    Object {
+      "changes": Array [],
+      "compare": Object {},
+      "date": undefined,
+      "releaseNotes": null,
+      "version": "5.5.0",
+    },
+    Object {
+      "changes": Array [],
+      "compare": Object {},
+      "date": "2018-08-24T14:23:00.000Z",
+      "releaseNotes": null,
+      "version": "5.4.0",
+    },
+  ],
+}
+`;
+
 exports[`workers/pr/changelog/gitlab getChangeLogJSON uses GitLab tags 1`] = `
 Object {
   "hasReleaseNotes": true,
diff --git a/lib/workers/pr/changelog/gitlab.spec.ts b/lib/workers/pr/changelog/gitlab.spec.ts
index ea83bb6913..1ba89095e1 100644
--- a/lib/workers/pr/changelog/gitlab.spec.ts
+++ b/lib/workers/pr/changelog/gitlab.spec.ts
@@ -189,5 +189,22 @@ describe(getName(__filename), () => {
         })
       ).toMatchSnapshot();
     });
+    it('supports self-hosted gitlab changelog', async () => {
+      httpMock.scope('https://git.test.com').persist().get(/.*/).reply(200, []);
+      hostRules.add({
+        hostType: PLATFORM_TYPE_GITLAB,
+        baseUrl: 'https://git.test.com/',
+        token: 'abc',
+      });
+      process.env.GITHUB_ENDPOINT = '';
+      expect(
+        await getChangeLogJSON({
+          ...upgrade,
+          platform: PLATFORM_TYPE_GITLAB,
+          sourceUrl: 'https://git.test.com/meno/dropzone/',
+          endpoint: 'https://git.test.com/api/v4/',
+        })
+      ).toMatchSnapshot();
+    });
   });
 });
diff --git a/lib/workers/pr/changelog/index.ts b/lib/workers/pr/changelog/index.ts
index c6b45557c2..efb383a005 100644
--- a/lib/workers/pr/changelog/index.ts
+++ b/lib/workers/pr/changelog/index.ts
@@ -27,7 +27,11 @@ export async function getChangeLogJSON(
 
     let res: ChangeLogResult | null = null;
 
-    if (args.sourceUrl?.includes('gitlab')) {
+    if (
+      args.sourceUrl?.includes('gitlab') ||
+      (args.platform === 'gitlab' &&
+        new URL(args.sourceUrl).hostname === new URL(args.endpoint).hostname)
+    ) {
       res = await sourceGitlab.getChangeLogJSON({ ...args, releases });
     } else {
       res = await sourceGithub.getChangeLogJSON({ ...args, releases });
-- 
GitLab