Skip to content

Commit

Permalink
fix(go): Avoid tag fetching for v0.0.0 (#20307)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Feb 9, 2023
1 parent 766cc3a commit 2502172
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
45 changes: 38 additions & 7 deletions lib/modules/datasource/go/index.spec.ts
Expand Up @@ -17,11 +17,13 @@ jest.mock('./releases-direct', () => {
return {
GoDirectDatasource: jest.fn().mockImplementation(() => {
return {
git: { getDigest: () => getDigestGitMock() },
github: { getDigest: () => getDigestGithubMock() },
gitlab: { getDigest: () => getDigestGitlabMock() },
bitbucket: { getDigest: () => getDigestBitbucketMock() },
getReleases: () => getReleasesDirectMock(),
git: { getDigest: (...args: any[]) => getDigestGitMock(...args) },
github: { getDigest: (...args: any[]) => getDigestGithubMock(...args) },
gitlab: { getDigest: (...args: any[]) => getDigestGitlabMock(...args) },
bitbucket: {
getDigest: (...args: any[]) => getDigestBitbucketMock(...args),
},
getReleases: (...args: any[]) => getReleasesDirectMock(...args),
};
}),
};
Expand Down Expand Up @@ -158,17 +160,46 @@ describe('modules/datasource/go/index', () => {
expect(res).toBe('abcdefabcdefabcdefabcdef');
});

it('returns digest', async () => {
it('returns github digest', async () => {
httpMock
.scope('https://golang.org/')
.get('/x/text?go-get=1')
.reply(200, Fixtures.get('go-get-github.html'));
getDigestGithubMock.mockResolvedValueOnce('abcdefabcdefabcdefabcdef');
const res = await datasource.getDigest(
{ packageName: 'golang.org/x/text' },
null
'v1.2.3'
);
expect(res).toBe('abcdefabcdefabcdefabcdef');
expect(getDigestGithubMock).toHaveBeenCalledWith(
{
datasource: 'github-tags',
packageName: 'golang/text',
registryUrl: 'https://github.com',
},
'v1.2.3'
);
});

it('returns github default branch digest', async () => {
httpMock
.scope('https://golang.org/')
.get('/x/text?go-get=1')
.reply(200, Fixtures.get('go-get-github.html'));
getDigestGithubMock.mockResolvedValueOnce('abcdefabcdefabcdefabcdef');
const res = await datasource.getDigest(
{ packageName: 'golang.org/x/text' },
'v0.0.0'
);
expect(res).toBe('abcdefabcdefabcdefabcdef');
expect(getDigestGithubMock).toHaveBeenCalledWith(
{
datasource: 'github-tags',
packageName: 'golang/text',
registryUrl: 'https://github.com',
},
undefined
);
});

it('support bitbucket digest', async () => {
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/datasource/go/index.ts
Expand Up @@ -65,8 +65,11 @@ export class GoDatasource extends Datasource {
}

// ignore vX.Y.Z-(0.)? pseudo versions that are used Go Modules - look up default branch instead
// ignore v0.0.0 versions to fetch the digest of default branch, not the commit of non-existing tag `v0.0.0`
const tag =
value && !GoDatasource.pversionRegexp.test(value) ? value : undefined;
value && !GoDatasource.pversionRegexp.test(value) && value !== 'v0.0.0'
? value
: undefined;

switch (source.datasource) {
case GitTagsDatasource.id: {
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/datasource/go/releases-direct.ts
Expand Up @@ -6,7 +6,7 @@ import { Datasource } from '../datasource';
import { GitTagsDatasource } from '../git-tags';
import { GithubTagsDatasource } from '../github-tags';
import { GitlabTagsDatasource } from '../gitlab-tags';
import type { DatasourceApi, GetReleasesConfig, ReleaseResult } from '../types';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import { BaseGoDatasource } from './base';
import { getSourceUrl } from './common';

Expand All @@ -15,8 +15,8 @@ export class GoDirectDatasource extends Datasource {

git: GitTagsDatasource;
github: GithubTagsDatasource;
gitlab: DatasourceApi;
bitbucket: DatasourceApi;
gitlab: GitlabTagsDatasource;
bitbucket: BitBucketTagsDatasource;

constructor() {
super(GoDirectDatasource.id);
Expand Down

0 comments on commit 2502172

Please sign in to comment.