diff --git a/lib/workers/repository/update/pr/changelog/gitlab/index.spec.ts b/lib/workers/repository/update/pr/changelog/gitlab/index.spec.ts index 9d4101102c8c83..bce831dde1d342 100644 --- a/lib/workers/repository/update/pr/changelog/gitlab/index.spec.ts +++ b/lib/workers/repository/update/pr/changelog/gitlab/index.spec.ts @@ -4,6 +4,7 @@ import { partial } from '../../../../../../../test/util'; import * as semverVersioning from '../../../../../../modules/versioning/semver'; import * as hostRules from '../../../../../../util/host-rules'; import type { BranchUpgradeConfig } from '../../../../../types'; +import { GitLabChangeLogSource } from './source'; const upgrade = partial({ manager: 'some-manager', @@ -29,6 +30,8 @@ const upgrade = partial({ const matchHost = 'https://gitlab.com/'; +const changelogSource = new GitLabChangeLogSource(); + describe('workers/repository/update/pr/changelog/gitlab/index', () => { afterEach(() => { // FIXME: add missing http mocks @@ -347,4 +350,31 @@ describe('workers/repository/update/pr/changelog/gitlab/index', () => { expect(config.sourceUrl).toBe(sourceUrl); // ensure unmodified function argument }); }); + + describe('hasValidRepository', () => { + it('handles invalid repository', () => { + expect(changelogSource.hasValidRepository('foo')).toBeFalse(); + }); + + it('handles valid repository', () => { + expect(changelogSource.hasValidRepository('some/repo')).toBeTrue(); + expect(changelogSource.hasValidRepository('some/repo/name')).toBeTrue(); + }); + }); + + describe('getAllTags', () => { + it('handles endpoint', async () => { + httpMock + .scope('https://git.test.com/') + .get('/api/v4/projects/some%2Frepo/repository/tags?per_page=100') + .reply(200, [ + { name: 'v5.2.0' }, + { name: 'v5.4.0' }, + { name: 'v5.5.0' }, + ]); + expect( + await changelogSource.getAllTags('https://git.test.com/', 'some/repo') + ).toEqual(['v5.2.0', 'v5.4.0', 'v5.5.0']); + }); + }); }); diff --git a/lib/workers/repository/update/pr/changelog/gitlab/source.ts b/lib/workers/repository/update/pr/changelog/gitlab/source.ts index 4dc86c3b996a72..1127f7bd354206 100644 --- a/lib/workers/repository/update/pr/changelog/gitlab/source.ts +++ b/lib/workers/repository/update/pr/changelog/gitlab/source.ts @@ -18,4 +18,8 @@ export class GitLabChangeLogSource extends ChangeLogSource { ): string { return `${baseUrl}${repository}/compare/${prevHead}...${nextHead}`; } + + override hasValidRepository(repository: string): boolean { + return repository.split('/').length >= 2; + } } diff --git a/lib/workers/repository/update/pr/changelog/source.spec.ts b/lib/workers/repository/update/pr/changelog/source.spec.ts index d28aa4090d9d2c..9e22bffe980fc7 100644 --- a/lib/workers/repository/update/pr/changelog/source.spec.ts +++ b/lib/workers/repository/update/pr/changelog/source.spec.ts @@ -41,4 +41,15 @@ describe('workers/repository/update/pr/changelog/source', () => { ); }); }); + + describe('hasValidRepository', () => { + it('handles invalid repository', () => { + expect(changelogSource.hasValidRepository('foo')).toBeFalse(); + expect(changelogSource.hasValidRepository('some/repo/name')).toBeFalse(); + }); + + it('handles valid repository', () => { + expect(changelogSource.hasValidRepository('some/repo')).toBeTrue(); + }); + }); }); diff --git a/lib/workers/repository/update/pr/changelog/source.ts b/lib/workers/repository/update/pr/changelog/source.ts index 6f746bd683aec7..2f35b16dd7c773 100644 --- a/lib/workers/repository/update/pr/changelog/source.ts +++ b/lib/workers/repository/update/pr/changelog/source.ts @@ -42,6 +42,7 @@ export abstract class ChangeLogSource { async getAllTags(endpoint: string, repository: string): Promise { const tags = ( await getPkgReleases({ + registryUrls: [endpoint], datasource: this.datasource, packageName: repository, versioning: @@ -91,7 +92,7 @@ export abstract class ChangeLogSource { return null; } - if (repository.split('/').length !== 2) { + if (is.falsy(this.hasValidRepository(repository))) { logger.debug(`Invalid ${this.platform} URL found: ${sourceUrl}`); return null; } @@ -266,4 +267,8 @@ export abstract class ChangeLogSource { protected shouldSkipPackage(config: BranchUpgradeConfig): boolean { return false; } + + hasValidRepository(repository: string): boolean { + return repository.split('/').length === 2; + } }