From 26cb91c9771cb3c43287dfbd75f0ec8c7a69856c Mon Sep 17 00:00:00 2001
From: Mariano Wahlmann <dichoso@gmail.com>
Date: Fri, 11 Feb 2022 02:57:49 -0600
Subject: [PATCH] fix(datasource/go): Remove version from repository URL for
 Gitlab (#14163)

Co-authored-by: Mariano Wahlmann <mariano.wahlmann@cbinsights.com>
---
 lib/datasource/go/base.spec.ts | 17 +++++++++++++++++
 lib/datasource/go/base.ts      |  6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/datasource/go/base.spec.ts b/lib/datasource/go/base.spec.ts
index 97ae551952..cfec055597 100644
--- a/lib/datasource/go/base.spec.ts
+++ b/lib/datasource/go/base.spec.ts
@@ -166,6 +166,23 @@ describe('datasource/go/base', () => {
         });
       });
 
+      it('supports GitLab deps with version', async () => {
+        httpMock
+          .scope('https://gitlab.com')
+          .get('/group/subgroup/v2?go-get=1')
+          .reply(200, loadFixture('go-get-gitlab.html'));
+
+        const res = await BaseGoDatasource.getDatasource(
+          'gitlab.com/group/subgroup/v2'
+        );
+
+        expect(res).toEqual({
+          datasource: GitlabTagsDatasource.id,
+          lookupName: 'group/subgroup',
+          registryUrl: 'https://gitlab.com',
+        });
+      });
+
       it('supports GitLab EE deps', async () => {
         hostRules.find.mockReturnValue({ token: 'some-token' });
         httpMock
diff --git a/lib/datasource/go/base.ts b/lib/datasource/go/base.ts
index c148aee9d8..3b84220bab 100644
--- a/lib/datasource/go/base.ts
+++ b/lib/datasource/go/base.ts
@@ -13,10 +13,10 @@ import type { DataSource } from './types';
 // TODO: figure out class hierarchy (#10532)
 export class BaseGoDatasource {
   private static readonly gitlabHttpsRegExp = regEx(
-    /^(?<httpsRegExpUrl>https:\/\/[^/]*gitlab\.[^/]*)\/(?<httpsRegExpName>.+?)[/]?$/
+    /^(?<httpsRegExpUrl>https:\/\/[^/]*gitlab\.[^/]*)\/(?<httpsRegExpName>.+?)(?:\/v\d+)?[/]?$/
   );
   private static readonly gitlabRegExp = regEx(
-    /^(?<regExpUrl>gitlab\.[^/]*)\/(?<regExpPath>.+?)[/]?$/
+    /^(?<regExpUrl>gitlab\.[^/]*)\/(?<regExpPath>.+?)(?:\/v\d+)?[/]?$/
   );
 
   private static readonly id = 'go';
@@ -89,7 +89,6 @@ export class BaseGoDatasource {
           ?.httpsRegExpName;
       const gitlabModuleName =
         BaseGoDatasource.gitlabRegExp.exec(goModule)?.groups?.regExpPath;
-
       if (gitlabUrl && gitlabUrlName) {
         if (gitlabModuleName?.startsWith(gitlabUrlName)) {
           if (gitlabModuleName.includes('.git')) {
@@ -108,6 +107,7 @@ export class BaseGoDatasource {
             lookupName: gitlabModuleName,
           };
         }
+
         return {
           datasource: GitlabTagsDatasource.id,
           registryUrl: gitlabUrl,
-- 
GitLab