From 2fd071cadf24e4c21a5255f25bc8b521f838d3ff Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Mon, 17 Jan 2022 11:38:14 +0300 Subject: [PATCH] refactor(datasource/go): Restrict parameters for "getDigest" (#13584) --- lib/datasource/go/get-datasource.spec.ts | 1 + lib/datasource/go/get-datasource.ts | 9 ++++++++- lib/datasource/go/releases-direct.spec.ts | 11 +++++++++++ lib/datasource/go/types.ts | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/datasource/go/get-datasource.spec.ts b/lib/datasource/go/get-datasource.spec.ts index 66290eb8ec..530cef6ef7 100644 --- a/lib/datasource/go/get-datasource.spec.ts +++ b/lib/datasource/go/get-datasource.spec.ts @@ -88,6 +88,7 @@ describe('datasource/go/get-datasource', () => { expect(res).toEqual({ datasource: githubDatasource, lookupName: 'golang/text', + registryUrl: 'https://github.com', }); }); diff --git a/lib/datasource/go/get-datasource.ts b/lib/datasource/go/get-datasource.ts index cf4a818da9..653e060fb7 100644 --- a/lib/datasource/go/get-datasource.ts +++ b/lib/datasource/go/get-datasource.ts @@ -35,6 +35,7 @@ async function goGetDatasource(goModule: string): Promise<DataSource | null> { lookupName: goSourceUrl .replace('https://github.com/', '') .replace(regEx(/\/$/), ''), + registryUrl: 'https://github.com', }; } const gitlabUrl = @@ -129,7 +130,11 @@ export async function getDatasource( if (goModule.startsWith('gopkg.in/')) { const [pkg] = goModule.replace('gopkg.in/', '').split('.'); const lookupName = pkg.includes('/') ? pkg : `go-${pkg}/${pkg}`; - return { datasource: github.id, lookupName }; + return { + datasource: github.id, + lookupName, + registryUrl: 'https://github.com', + }; } if (goModule.startsWith('github.com/')) { @@ -138,6 +143,7 @@ export async function getDatasource( return { datasource: github.id, lookupName, + registryUrl: 'https://github.com', }; } @@ -147,6 +153,7 @@ export async function getDatasource( return { datasource: bitbucket.id, lookupName, + registryUrl: 'https://bitbucket.org', }; } diff --git a/lib/datasource/go/releases-direct.spec.ts b/lib/datasource/go/releases-direct.spec.ts index ff1c6676f6..5f0e2a10ca 100644 --- a/lib/datasource/go/releases-direct.spec.ts +++ b/lib/datasource/go/releases-direct.spec.ts @@ -42,6 +42,7 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'golang/text', + registryUrl: 'https://github.com', }); httpMock .scope('https://api.github.com/') @@ -98,6 +99,7 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'bitbucket-tags', lookupName: 'golang/text', + registryUrl: 'https://bitbucket.org', }); httpMock .scope('https://api.bitbucket.org/') @@ -139,14 +141,17 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'go-x/x', + registryUrl: 'https://github.com', }); httpMock .scope('https://api.github.com/') @@ -199,14 +204,17 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); const packages = [ { lookupName: 'github.com/x/text/a' }, @@ -236,10 +244,12 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); const packages = [ { lookupName: 'github.com/x/text/a' }, @@ -267,6 +277,7 @@ describe('datasource/go/releases-direct', () => { ds.getDatasource.mockResolvedValueOnce({ datasource: 'github-tags', lookupName: 'x/text', + registryUrl: 'https://github.com', }); const pkg = { lookupName: 'github.com/x/text/b/v2' }; const tags = [ diff --git a/lib/datasource/go/types.ts b/lib/datasource/go/types.ts index 8eabe0696c..329e09493b 100644 --- a/lib/datasource/go/types.ts +++ b/lib/datasource/go/types.ts @@ -2,7 +2,7 @@ import type { GoproxyFallback } from './common'; export interface DataSource { datasource: string; - registryUrl?: string; + registryUrl: string; lookupName: string; } -- GitLab