diff --git a/lib/modules/datasource/go/__fixtures__/go-get-submodule-gitlab.html b/lib/modules/datasource/go/__fixtures__/go-get-submodule-gitlab.html new file mode 100644 index 00000000000000..42c532d935f343 --- /dev/null +++ b/lib/modules/datasource/go/__fixtures__/go-get-submodule-gitlab.html @@ -0,0 +1,8 @@ + + + + + + + go get https://gitlab.com/example/module + diff --git a/lib/modules/datasource/go/base.spec.ts b/lib/modules/datasource/go/base.spec.ts index b03aced9ddc73a..df89482641ce3a 100644 --- a/lib/modules/datasource/go/base.spec.ts +++ b/lib/modules/datasource/go/base.spec.ts @@ -117,6 +117,23 @@ describe('modules/datasource/go/base', () => { }); }); + it('supports Go submodules in GitLab repo', async () => { + httpMock + .scope('https://gitlab.com') + .get('/example/module/submodule?go-get=1') + .reply(200, Fixtures.get('go-get-submodule-gitlab.html')); + + const res = await BaseGoDatasource.getDatasource( + 'gitlab.com/example/module/submodule', + ); + + expect(res).toEqual({ + datasource: GitlabTagsDatasource.id, + packageName: 'example/module', + registryUrl: 'https://gitlab.com', + }); + }); + it('supports GitLab deps', async () => { httpMock .scope('https://gitlab.com') @@ -163,7 +180,7 @@ describe('modules/datasource/go/base', () => { expect(res).toEqual({ datasource: GitlabTagsDatasource.id, - packageName: 'group/subgroup/my.git.module', + packageName: 'group/subgroup', registryUrl: 'https://gitlab.com', }); }); diff --git a/lib/modules/datasource/go/base.ts b/lib/modules/datasource/go/base.ts index 9a2087a200f010..fc9a3cd906b83e 100644 --- a/lib/modules/datasource/go/base.ts +++ b/lib/modules/datasource/go/base.ts @@ -21,9 +21,6 @@ export class BaseGoDatasource { private static readonly gitlabHttpsRegExp = regEx( /^(?https:\/\/[^/]*gitlab\.[^/]*)\/(?.+?)(?:\/v\d+)?[/]?$/, ); - private static readonly gitlabRegExp = regEx( - /^(?gitlab\.[^/]*)\/(?.+?)(?:\/v\d+)?[/]?$/, - ); private static readonly gitVcsRegexp = regEx( /^(?:[^/]+)\/(?.*)\.git(?:$|\/)/, ); @@ -154,30 +151,18 @@ export class BaseGoDatasource { }; } - const gitlabUrl = - BaseGoDatasource.gitlabHttpsRegExp.exec(metadataUrl)?.groups - ?.httpsRegExpUrl; - const gitlabUrlName = - BaseGoDatasource.gitlabHttpsRegExp.exec(metadataUrl)?.groups - ?.httpsRegExpName; - const gitlabModuleName = - BaseGoDatasource.gitlabRegExp.exec(goModule)?.groups?.regExpPath; const vcsIndicatedModule = BaseGoDatasource.gitVcsRegexp.exec(goModule)?.groups?.module; - if (gitlabUrl && gitlabUrlName) { - if (gitlabModuleName?.startsWith(gitlabUrlName)) { - const packageName = vcsIndicatedModule ?? gitlabModuleName; - return { - datasource: GitlabTagsDatasource.id, - registryUrl: gitlabUrl, - packageName, - }; - } + const metadataUrlMatchGroups = + BaseGoDatasource.gitlabHttpsRegExp.exec(metadataUrl)?.groups; + if (metadataUrlMatchGroups) { + const { httpsRegExpUrl, httpsRegExpName } = metadataUrlMatchGroups; + const packageName = vcsIndicatedModule ?? httpsRegExpName; return { datasource: GitlabTagsDatasource.id, - registryUrl: gitlabUrl, - packageName: gitlabUrlName, + registryUrl: httpsRegExpUrl, + packageName, }; }