From ea4fe8fd6db8986fda346b76435a0b28e984ed43 Mon Sep 17 00:00:00 2001 From: mikaello <2505178+mikaello@users.noreply.github.com> Date: Thu, 22 Sep 2022 13:10:13 +0200 Subject: [PATCH] feat(golang-version): enable custom registryUrls (#17828) --- .../__snapshots__/index.spec.ts.snap | 2 +- .../datasource/golang-version/index.spec.ts | 20 +++++++++++++++++++ .../datasource/golang-version/index.ts | 18 ++++++++++++----- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/modules/datasource/golang-version/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/golang-version/__snapshots__/index.spec.ts.snap index 6b3f6e2a89..e9d8dcc195 100644 --- a/lib/modules/datasource/golang-version/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/golang-version/__snapshots__/index.spec.ts.snap @@ -3,7 +3,7 @@ exports[`modules/datasource/golang-version/index getReleases parses real data 1`] = ` { "homepage": "https://go.dev/", - "registryUrl": "https://raw.githubusercontent.com/golang/website/", + "registryUrl": "https://raw.githubusercontent.com/golang/website", "releases": [ { "releaseTimestamp": "2012-03-28T00:00:00.000Z", diff --git a/lib/modules/datasource/golang-version/index.spec.ts b/lib/modules/datasource/golang-version/index.spec.ts index 4d35aec78b..03e876758e 100644 --- a/lib/modules/datasource/golang-version/index.spec.ts +++ b/lib/modules/datasource/golang-version/index.spec.ts @@ -33,6 +33,26 @@ describe('modules/datasource/golang-version/index', () => { expect(res).toMatchSnapshot(); }); + it('supports custom registry URL', async () => { + httpMock + .scope('https://custom-registry/website') + .get('/HEAD/internal/history/release.go') + .reply(200, golangReleasesContent); + const config = { + registryUrls: ['https://custom-registry/website'], + }; + const res = await getPkgReleases({ + ...config, + datasource, + depName: 'golang', + }); + expect(res?.releases).toHaveLength(132); + expect(res?.releases[0]).toEqual({ + releaseTimestamp: '2012-03-28T00:00:00.000Z', + version: '1.0.0', + }); + }); + it('throws ExternalHostError for invalid release with no versions', async () => { httpMock .scope('https://raw.githubusercontent.com') diff --git a/lib/modules/datasource/golang-version/index.ts b/lib/modules/datasource/golang-version/index.ts index e71df0d1c7..d0cd118bbb 100644 --- a/lib/modules/datasource/golang-version/index.ts +++ b/lib/modules/datasource/golang-version/index.ts @@ -1,6 +1,7 @@ import { ExternalHostError } from '../../../types/errors/external-host-error'; import { cache } from '../../../util/cache/package/decorator'; import { regEx } from '../../../util/regex'; +import { joinUrlParts } from '../../../util/url'; import { isVersion, id as semverVersioningId } from '../../versioning/semver'; import { Datasource } from '../datasource'; import type { GetReleasesConfig, Release, ReleaseResult } from '../types'; @@ -24,10 +25,10 @@ export class GolangVersionDatasource extends Datasource { } override readonly defaultRegistryUrls = [ - 'https://raw.githubusercontent.com/golang/website/', + 'https://raw.githubusercontent.com/golang/website', ]; - override readonly customRegistrySupport = false; + override readonly customRegistrySupport = true; override readonly defaultVersioning = semverVersioningId; @@ -35,14 +36,21 @@ export class GolangVersionDatasource extends Datasource { async getReleases({ registryUrl, }: GetReleasesConfig): Promise<ReleaseResult | null> { + // istanbul ignore if + if (!registryUrl) { + return null; + } + const res: ReleaseResult = { homepage: 'https://go.dev/', sourceUrl: 'https://github.com/golang/go', releases: [], }; - // TODO: types (#7154) - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - const golangVersionsUrl = `${registryUrl}HEAD/internal/history/release.go`; + + const golangVersionsUrl = joinUrlParts( + registryUrl, + '/HEAD/internal/history/release.go' + ); const response = await this.http.get(golangVersionsUrl); -- GitLab