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(datasource/go): private repositories on azure #26984

Merged
merged 8 commits into from Feb 29, 2024
30 changes: 13 additions & 17 deletions lib/modules/datasource/go/base.spec.ts
Expand Up @@ -16,12 +16,14 @@ const hostRules = mocked(_hostRules);
describe('modules/datasource/go/base', () => {
describe('simple cases', () => {
it.each`
module | datasource | packageName
${'gopkg.in/foo'} | ${'github-tags'} | ${'go-foo/foo'}
${'gopkg.in/foo/bar'} | ${'github-tags'} | ${'foo/bar'}
${'github.com/foo/bar'} | ${'github-tags'} | ${'foo/bar'}
${'bitbucket.org/foo/bar'} | ${'bitbucket-tags'} | ${'foo/bar'}
${'code.cloudfoundry.org/lager'} | ${'github-tags'} | ${'cloudfoundry/lager'}
module | datasource | packageName
${'gopkg.in/foo'} | ${'github-tags'} | ${'go-foo/foo'}
${'gopkg.in/foo/bar'} | ${'github-tags'} | ${'foo/bar'}
${'github.com/foo/bar'} | ${'github-tags'} | ${'foo/bar'}
${'bitbucket.org/foo/bar'} | ${'bitbucket-tags'} | ${'foo/bar'}
${'code.cloudfoundry.org/lager'} | ${'github-tags'} | ${'cloudfoundry/lager'}
${'dev.azure.com/foo/bar/_git/baz.git'} | ${'git-tags'} | ${'https://dev.azure.com/foo/bar/_git/baz'}
${'dev.azure.com/foo/bar/baz.git'} | ${'git-tags'} | ${'https://dev.azure.com/foo/bar/_git/baz'}
jsperling-schwarz marked this conversation as resolved.
Show resolved Hide resolved
`(
'$module -> $datasource: $packageName',
async ({ module, datasource, packageName }) => {
Expand Down Expand Up @@ -345,23 +347,17 @@ describe('modules/datasource/go/base', () => {
});
});

it('handles go-import with azure devops source', async () => {
const meta =
'<meta name="go-import" content="dev.azure.com/my-organization/my-project/_git/my-repo.git git https://dev.azure.com/my-organization/my-project/_git/my-repo.git" />';
it('returns null for invalid azure devops source', async () => {
httpMock
.scope('https://dev.azure.com')
.get('/my-organization/my-project/_git/my-repo.git?go-get=1')
.reply(200, meta);
.get('/foo/bar.git?go-get=1')
.reply(200);
rarkins marked this conversation as resolved.
Show resolved Hide resolved

const res = await BaseGoDatasource.getDatasource(
'dev.azure.com/my-organization/my-project/_git/my-repo.git',
'dev.azure.com/foo/bar.git',
);

expect(res).toEqual({
datasource: GitTagsDatasource.id,
packageName:
'https://dev.azure.com/my-organization/my-project/_git/my-repo',
});
expect(res).toBeNull();
});

it('handles uncommon imports', async () => {
Expand Down
20 changes: 20 additions & 0 deletions lib/modules/datasource/go/base.ts
Expand Up @@ -71,6 +71,26 @@ export class BaseGoDatasource {
};
}

if (goModule.startsWith('dev.azure.com/')) {
const split = goModule.split('/');
jsperling-schwarz marked this conversation as resolved.
Show resolved Hide resolved
if ((split.length > 4 && split[3] === '_git') || split.length > 3) {
const packageName =
'https://dev.azure.com/' +
split[1] +
'/' +
split[2] +
'/_git/' +
(split[3] === '_git' ? split[4] : split[3]).replace(
regEx(/\.git$/),
'',
);
return {
datasource: GitTagsDatasource.id,
packageName,
};
}
}

return await BaseGoDatasource.goGetDatasource(goModule);
}

Expand Down