diff --git a/lib/workers/repository/update/pr/changelog/github/index.ts b/lib/workers/repository/update/pr/changelog/github/index.ts index 5f8817ef7d2a9afb7c214de17ff17db9f6c1ea0c..92c92d6656fbe51ef839ab2adbfe689b7c04f82e 100644 --- a/lib/workers/repository/update/pr/changelog/github/index.ts +++ b/lib/workers/repository/update/pr/changelog/github/index.ts @@ -10,7 +10,12 @@ import type { import { GithubHttp } from '../../../../../../util/http/github'; import { fromBase64 } from '../../../../../../util/string'; import { ensureTrailingSlash } from '../../../../../../util/url'; -import type { ChangeLogFile, ChangeLogNotes } from '../types'; +import type { + ChangeLogFile, + ChangeLogNotes, + ChangeLogProject, + ChangeLogRelease, +} from '../types'; export const id = 'github-changelog'; const http = new GithubHttp(id); @@ -107,10 +112,14 @@ export async function getReleaseNotesMd( } export async function getReleaseList( - apiBaseUrl: string, - repository: string + project: ChangeLogProject, + _release: ChangeLogRelease ): Promise<ChangeLogNotes[]> { logger.trace('github.getReleaseList()'); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const apiBaseUrl = project.apiBaseUrl!; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const repository = project.repository!; const notesSourceUrl = `${ensureTrailingSlash( apiBaseUrl )}repos/${repository}/releases`; diff --git a/lib/workers/repository/update/pr/changelog/gitlab/index.ts b/lib/workers/repository/update/pr/changelog/gitlab/index.ts index d20be75218d91839bd057d75519111a29e56408c..c24f431aacb73272713a1ddb0e331bf163780efe 100644 --- a/lib/workers/repository/update/pr/changelog/gitlab/index.ts +++ b/lib/workers/repository/update/pr/changelog/gitlab/index.ts @@ -5,7 +5,12 @@ import type { GitlabTag } from '../../../../../../modules/datasource/gitlab-tags import type { GitlabTreeNode } from '../../../../../../types/platform/gitlab'; import { GitlabHttp } from '../../../../../../util/http/gitlab'; import { ensureTrailingSlash } from '../../../../../../util/url'; -import type { ChangeLogFile, ChangeLogNotes } from '../types'; +import type { + ChangeLogFile, + ChangeLogNotes, + ChangeLogProject, + ChangeLogRelease, +} from '../types'; export const id = 'gitlab-changelog'; const http = new GitlabHttp(id); @@ -91,11 +96,14 @@ export async function getReleaseNotesMd( } export async function getReleaseList( - apiBaseUrl: string, - repository: string + project: ChangeLogProject, + _release: ChangeLogRelease ): Promise<ChangeLogNotes[]> { logger.trace('gitlab.getReleaseNotesMd()'); - + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const apiBaseUrl = project.apiBaseUrl!; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const repository = project.repository!; const urlEncodedRepo = encodeURIComponent(repository); const apiUrl = `${ensureTrailingSlash( apiBaseUrl diff --git a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts index c138e0d9d0d82cdeca1ea260625fdd7cf2a0b8e7..9580a00edbf327f094735ce139b78295d218302b 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.spec.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.spec.ts @@ -172,7 +172,10 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { describe('getReleaseList()', () => { it('should return empty array if no apiBaseUrl', async () => { - const res = await getReleaseList({} as ChangeLogProject); + const res = await getReleaseList( + {} as ChangeLogProject, + {} as ChangeLogRelease + ); expect(res).toBeEmptyArray(); }); @@ -186,10 +189,13 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { }, ] as never); - const res = await getReleaseList({ - ...githubProject, - repository: 'some/yet-other-repository', - }); + const res = await getReleaseList( + { + ...githubProject, + repository: 'some/yet-other-repository', + }, + {} as ChangeLogRelease + ); expect(res).toMatchSnapshot([ { notesSourceUrl: @@ -218,10 +224,13 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { body: 'some body #123, [#124](https://gitlab.com/some/yet-other-repository/issues/124)', }, ]); - const res = await getReleaseList({ - ...gitlabProject, - repository: 'some/yet-other-repository', - }); + const res = await getReleaseList( + { + ...gitlabProject, + repository: 'some/yet-other-repository', + }, + {} as ChangeLogRelease + ); expect(res).toMatchSnapshot([ { notesSourceUrl: @@ -252,12 +261,15 @@ describe('workers/repository/update/pr/changelog/release-notes', () => { body: 'some body #123, [#124](https://my.custom.domain/some/yet-other-repository/issues/124)', }, ]); - const res = await getReleaseList({ - ...gitlabProject, - repository: 'some/yet-other-repository', - apiBaseUrl: 'https://my.custom.domain/api/v4/', - baseUrl: 'https://my.custom.domain/', - }); + const res = await getReleaseList( + { + ...gitlabProject, + repository: 'some/yet-other-repository', + apiBaseUrl: 'https://my.custom.domain/api/v4/', + baseUrl: 'https://my.custom.domain/', + }, + {} as ChangeLogRelease + ); expect(res).toMatchSnapshot([ { notesSourceUrl: diff --git a/lib/workers/repository/update/pr/changelog/release-notes.ts b/lib/workers/repository/update/pr/changelog/release-notes.ts index 561b841192365688ce1c11e3008f362149fab232..71c0a8aed6ee8a8b01fc150085ae3cc8ffc2a610 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.ts @@ -22,16 +22,17 @@ const markdown = new MarkdownIt('zero'); markdown.enable(['heading', 'lheading']); export async function getReleaseList( - project: ChangeLogProject + project: ChangeLogProject, + release: ChangeLogRelease ): Promise<ChangeLogNotes[]> { logger.trace('getReleaseList()'); const { apiBaseUrl, repository, type } = project; try { switch (type) { case 'gitlab': - return await gitlab.getReleaseList(apiBaseUrl, repository); + return await gitlab.getReleaseList(project, release); case 'github': - return await github.getReleaseList(apiBaseUrl, repository); + return await github.getReleaseList(project, release); default: logger.warn({ apiBaseUrl, repository, type }, 'Invalid project type'); @@ -51,7 +52,8 @@ export async function getReleaseList( } export function getCachedReleaseList( - project: ChangeLogProject + project: ChangeLogProject, + release: ChangeLogRelease ): Promise<ChangeLogNotes[]> { const cacheKey = `getReleaseList-${project.apiBaseUrl}-${project.repository}`; const cachedResult = memCache.get<Promise<ChangeLogNotes[]>>(cacheKey); @@ -59,7 +61,7 @@ export function getCachedReleaseList( if (cachedResult !== undefined) { return cachedResult; } - const promisedRes = getReleaseList(project); + const promisedRes = getReleaseList(project, release); memCache.set(cacheKey, promisedRes); return promisedRes; } @@ -103,7 +105,7 @@ export async function getReleaseNotes( const { depName, repository } = project; const { version, gitRef } = release; logger.trace(`getReleaseNotes(${repository}, ${version}, ${depName})`); - const releases = await getCachedReleaseList(project); + const releases = await getCachedReleaseList(project, release); logger.trace({ releases }, 'Release list from getReleaseList'); let releaseNotes: ChangeLogNotes | null = null;