Skip to content

Commit

Permalink
fix(datasource/go): private repositories on azure (#26984)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
jsperling-schwarz and rarkins committed Feb 29, 2024
1 parent 73cc089 commit 88860db
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
40 changes: 26 additions & 14 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'}
`(
'$module -> $datasource: $packageName',
async ({ module, datasource, packageName }) => {
Expand Down Expand Up @@ -347,23 +349,33 @@ 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" />';
'<meta name="go-import" content="org.visualstudio.com/my-project/_git/my-repo.git git https://org.visualstudio.com/my-project/_git/my-repo.git" />';
httpMock
.scope('https://dev.azure.com')
.get('/my-organization/my-project/_git/my-repo.git?go-get=1')
.scope('https://org.visualstudio.com')
.get('/my-project/_git/my-repo.git?go-get=1')
.reply(200, meta);

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

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

it('returns null for invalid azure devops source', async () => {
httpMock
.scope('https://dev.azure.com')
.get('/foo/bar.git?go-get=1')
.reply(200);

const res = await BaseGoDatasource.getDatasource(
'dev.azure.com/foo/bar.git',
);

expect(res).toBeNull();
});

it('handles uncommon imports', async () => {
const meta =
'<meta name="go-import" content="example.com/uncommon git ssh://git.example.com/uncommon">';
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('/');
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

0 comments on commit 88860db

Please sign in to comment.