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 6b3f6e2a8952f17030b4a2c1bb3e4ccf489eee21..e9d8dcc1959629fe7c077a6a049063917b6cec1d 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 4d35aec78b1a358739e950eef9db9d267640090c..03e876758e0f7aa3965dee97e0ff739861387c1c 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 e71df0d1c78ae109d073d9655e32aa7698c5ae56..d0cd118bbb055d508b673d767aa9b3b9ed9687f7 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);