Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gomod): support .git indicator on private ee gitlab #17105

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta name="go-import" content="my.custom.domain/golang/subgroup git https://my.custom.domain/golang/subgroup.git" />
<meta name="go-source"
content="my.custom.domain/golang/subgroup https://my.custom.domain/golang/subgroup https://my.custom.domain/golang/subgroup/-/tree/master{/dir} https://my.custom.domain/golang/subgroup/-/blob/master{/dir}/{file}#L{line}" />
</head>

<body>go get https://my.custom.domain/golang/subgroup</body>

</html>
35 changes: 35 additions & 0 deletions lib/modules/datasource/go/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ describe('modules/datasource/go/base', () => {
});
});

it('does not fail for names containing .git', async () => {
httpMock
.scope('https://gitlab.com')
.get('/group/subgroup/my.git.module?go-get=1')
.reply(200, Fixtures.get('go-get-gitlab.html'));

const res = await BaseGoDatasource.getDatasource(
'gitlab.com/group/subgroup/my.git.module'
);

expect(res).toEqual({
datasource: GitlabTagsDatasource.id,
packageName: 'group/subgroup/my.git.module',
registryUrl: 'https://gitlab.com',
});
});

it('supports GitLab with URL mismatch', async () => {
const mismatchingResponse = Fixtures.get('go-get-github.html').replace(
'https://github.com/golang/text/',
Expand Down Expand Up @@ -238,6 +255,24 @@ describe('modules/datasource/go/base', () => {
});
});

it('supports GitLab EE deps in private subgroup with vcs indicator', async () => {
hostRules.find.mockReturnValue({ token: 'some-token' });
httpMock
.scope('https://my.custom.domain')
.get('/golang/subgroup/myrepo.git/v2?go-get=1')
.reply(200, Fixtures.get('go-get-gitlab-ee-private-subgroup.html'));

const res = await BaseGoDatasource.getDatasource(
'my.custom.domain/golang/subgroup/myrepo.git/v2'
);

expect(res).toEqual({
datasource: GitlabTagsDatasource.id,
packageName: 'golang/subgroup/myrepo',
registryUrl: 'https://my.custom.domain',
});
});

it('supports GitLab EE monorepo deps in subgroup', async () => {
hostRules.find.mockReturnValue({ token: 'some-token' });
httpMock
Expand Down
21 changes: 16 additions & 5 deletions lib/modules/datasource/go/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class BaseGoDatasource {
private static readonly gitlabRegExp = regEx(
/^(?<regExpUrl>gitlab\.[^/]*)\/(?<regExpPath>.+?)(?:\/v\d+)?[/]?$/
);
private static readonly gitVcsRegexp = regEx(
/^(?:[^/]+)\/(?<module>.*)\.git(?:$|\/)/
);

private static readonly id = 'go';
private static readonly http = new Http(BaseGoDatasource.id);
Expand Down Expand Up @@ -112,14 +115,12 @@ export class BaseGoDatasource {
BaseGoDatasource.gitlabRegExp.exec(goModule)?.groups?.regExpPath;
if (gitlabUrl && gitlabUrlName) {
if (gitlabModuleName?.startsWith(gitlabUrlName)) {
if (gitlabModuleName.includes('.git')) {
const vcsIndicatedModule = BaseGoDatasource.gitVcsRegexp.exec(goModule);
if (vcsIndicatedModule?.groups?.module) {
return {
datasource: GitlabTagsDatasource.id,
registryUrl: gitlabUrl,
packageName: gitlabModuleName.substring(
0,
gitlabModuleName.indexOf('.git')
),
packageName: vcsIndicatedModule.groups?.module,
};
}
return {
Expand Down Expand Up @@ -149,6 +150,16 @@ export class BaseGoDatasource {

const registryUrl = `${parsedUrl.protocol}//${parsedUrl.host}`;

// a .git path indicates a concrete git repository, which can be different from metadata returned by gitlab
const vcsIndicatedModule = BaseGoDatasource.gitVcsRegexp.exec(goModule);
if (vcsIndicatedModule?.groups?.module) {
return {
datasource: GitlabTagsDatasource.id,
registryUrl,
packageName: vcsIndicatedModule.groups?.module,
};
}

return {
datasource: GitlabTagsDatasource.id,
registryUrl,
Expand Down