From 2f2e57c3625c09b4b9d140eb2836cee151d27c87 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:02:43 +0545 Subject: [PATCH 01/13] feat: convert fetchReleaseNotes to enum=like add new features --- docs/usage/configuration-options.md | 7 +++- .../fetch-release-notes-migration.spec.ts | 21 ++++++++++ .../custom/fetch-release-notes-migration.ts | 10 +++++ lib/config/migrations/migrations-service.ts | 2 + lib/config/options/index.ts | 7 ++-- lib/config/types.ts | 4 +- .../repository/update/branch/index.spec.ts | 2 +- lib/workers/repository/update/branch/index.ts | 38 ++++++++++--------- .../repository/update/pr/index.spec.ts | 10 ++--- lib/workers/repository/update/pr/index.ts | 2 +- .../repository/updates/branchify.spec.ts | 4 +- lib/workers/repository/updates/branchify.ts | 4 +- 12 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 lib/config/migrations/custom/fetch-release-notes-migration.spec.ts create mode 100644 lib/config/migrations/custom/fetch-release-notes-migration.ts diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 5283cde1724deb..32b8816f3872f3 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -923,7 +923,12 @@ A similar one could strip leading `v` prefixes: ## fetchReleaseNotes -Set this to `false` if you want to disable release notes fetching. +Use this config option to configure release notes fetching. +The available options are: + +- `off` - disable release notes fetching +- `branch` - fetche release notes while creating/updating branch +- `pr`(default) - fecthes release notes while creating/updating pull-request Renovate can fetch release notes when they are hosted on one of these platforms: diff --git a/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts b/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts new file mode 100644 index 00000000000000..989660c61df4dc --- /dev/null +++ b/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts @@ -0,0 +1,21 @@ +import { FetchReleaseNotes } from './fetch-release-notes-migration'; +describe('config/migrations/custom/fetch-release-notes-migration', () => { + it('migrates', () => { + expect(FetchReleaseNotes).toMigrate( + { + fetchReleaseNotes: false as never, + }, + { + fetchReleaseNotes: 'off', + } + ); + expect(FetchReleaseNotes).toMigrate( + { + fetchReleaseNotes: true as never, + }, + { + fetchReleaseNotes: 'pr', + } + ); + }); +}); diff --git a/lib/config/migrations/custom/fetch-release-notes-migration.ts b/lib/config/migrations/custom/fetch-release-notes-migration.ts new file mode 100644 index 00000000000000..2bc91de9589301 --- /dev/null +++ b/lib/config/migrations/custom/fetch-release-notes-migration.ts @@ -0,0 +1,10 @@ +import is from '@sindresorhus/is'; +import { AbstractMigration } from '../base/abstract-migration'; +export class FetchReleaseNotes extends AbstractMigration { + override readonly propertyName = 'fetchReleaseNotes'; + override run(value: unknown): void { + if (is.boolean(value)) { + this.rewrite(value ? 'pr' : 'off'); + } + } +} diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 1b6c0d357d515f..51fc7c039be43d 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -54,6 +54,7 @@ import { UnpublishSafeMigration } from './custom/unpublish-safe-migration'; import { UpgradeInRangeMigration } from './custom/upgrade-in-range-migration'; import { VersionStrategyMigration } from './custom/version-strategy-migration'; import type { Migration, MigrationConstructor } from './types'; +import { FetchReleaseNotes } from './custom/fetch-release-notes-migration'; export class MigrationsService { static readonly removedProperties: ReadonlySet = new Set([ @@ -146,6 +147,7 @@ export class MigrationsService { MatchDatasourcesMigration, DatasourceMigration, StabilityDaysMigration, + FetchReleaseNotes, ]; static run(originalConfig: RenovateConfig): RenovateConfig { diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index f71066be46c06b..58efb94ca56fda 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2549,9 +2549,10 @@ const options: RenovateOptions[] = [ }, { name: 'fetchReleaseNotes', - description: 'Controls if release notes are fetched.', - type: 'boolean', - default: true, + description: 'Controls if and in which stage release notes are fetched.', + type: 'string', + allowedValues: ['off', 'branch', 'pr'], + default: 'pr', cli: false, env: false, }, diff --git a/lib/config/types.ts b/lib/config/types.ts index 5c390b09c825a0..711c0820809b7b 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -256,7 +256,7 @@ export interface RenovateConfig vulnerabilitySeverity?: string; regexManagers?: RegExManager[]; - fetchReleaseNotes?: boolean; + fetchReleaseNotes?: FetchReleaseNotesOptions; secrets?: Record; constraints?: Record; @@ -297,6 +297,8 @@ export type UpdateType = | 'bump' | 'replacement'; +type FetchReleaseNotesOptions = 'off' | 'branch' | 'pr'; + export type MatchStringsStrategy = 'any' | 'recursive' | 'combination'; export type MergeStrategy = diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 66e276a240c3af..3e7ff73e2a16a3 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -816,7 +816,7 @@ describe('workers/repository/update/branch/index', () => { ignoreTests: true, prCreation: 'not-pending', commitBody: '[skip-ci]', - fetchReleaseNotes: true, + fetchReleaseNotes: 'pr', } satisfies BranchConfig; mockedFunction(needsChangelogs).mockReturnValueOnce(true); scm.getBranchCommit.mockResolvedValue('123test'); //TODO:not needed? diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 003da47bb0c4ba..0b27c6765ffa87 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -34,7 +34,7 @@ import { toMs } from '../../../../util/pretty-time'; import * as template from '../../../../util/template'; import { isLimitReached } from '../../../global/limits'; import type { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; -import { embedChangelog, needsChangelogs } from '../../changelog'; +import { embedChangelogs, needsChangelogs } from '../../changelog'; import { ensurePr } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; import { setArtifactErrorStatus } from './artifacts'; @@ -540,26 +540,28 @@ export async function processBranch( config.forceCommit = forcedManually || config.isConflicted; // compile commit message with body, which maybe needs changelogs - if (config.commitBody) { - if ( - config.fetchReleaseNotes && - needsChangelogs(config, ['commitBody']) - ) { + if (config.fetchReleaseNotes !== 'off' && config.commitBody) { + if (config.fetchReleaseNotes === 'branch') { + await embedChangelogs(config.upgrades); + } else if (needsChangelogs(config, ['commitBody'])) { // we only need first upgrade, the others are only needed on PR update // we add it to first, so PR fetch can skip fetching for that update - await embedChangelog(config.upgrades[0]); - } - // changelog is on first upgrade - config.commitMessage = `${config.commitMessage!}\n\n${template.compile( - config.commitBody, - { - ...config, - logJSON: config.upgrades[0].logJSON, - releases: config.upgrades[0].releases, - } - )}`; + await embedChangelogs(config.upgrades); + + // changelog is on first upgrade + config.commitMessage = `${config.commitMessage!}\n\n${template.compile( + config.commitBody, + { + ...config, + logJSON: config.upgrades[0].logJSON, + releases: config.upgrades[0].releases, + } + )}`; - logger.trace(`commitMessage: ` + JSON.stringify(config.commitMessage)); + logger.trace( + `commitMessage: ` + JSON.stringify(config.commitMessage) + ); + } } commitSha = await commitFilesToBranch(config); diff --git a/lib/workers/repository/update/pr/index.spec.ts b/lib/workers/repository/update/pr/index.spec.ts index 2daad4639762e0..c9ddc64acc25b1 100644 --- a/lib/workers/repository/update/pr/index.spec.ts +++ b/lib/workers/repository/update/pr/index.spec.ts @@ -101,7 +101,7 @@ describe('workers/repository/update/pr/index', () => { platform.createPr.mockResolvedValueOnce(pr); limits.isLimitReached.mockReturnValueOnce(true); - config.fetchReleaseNotes = true; + config.fetchReleaseNotes = 'pr'; const res = await ensurePr(config); @@ -844,13 +844,13 @@ describe('workers/repository/update/pr/index', () => { bodyFingerprint: fingerprint( generatePrBodyFingerprintConfig({ ...config, - fetchReleaseNotes: true, + fetchReleaseNotes: 'pr', }) ), lastEdited: new Date('2020-01-20T00:00:00Z').toISOString(), }; prCache.getPrCache.mockReturnValueOnce(cachedPr); - const res = await ensurePr({ ...config, fetchReleaseNotes: true }); + const res = await ensurePr({ ...config, fetchReleaseNotes: 'pr' }); expect(res).toEqual({ type: 'with-pr', pr: existingPr, @@ -877,13 +877,13 @@ describe('workers/repository/update/pr/index', () => { bodyFingerprint: fingerprint( generatePrBodyFingerprintConfig({ ...config, - fetchReleaseNotes: true, + fetchReleaseNotes: 'pr', }) ), lastEdited: new Date('2020-01-20T00:00:00Z').toISOString(), }; prCache.getPrCache.mockReturnValueOnce(cachedPr); - const res = await ensurePr({ ...config, fetchReleaseNotes: true }); + const res = await ensurePr({ ...config, fetchReleaseNotes: 'pr' }); expect(res).toEqual({ type: 'with-pr', pr: { diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index cadbb3bea8df14..a66ef772d5c330 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -233,7 +233,7 @@ export async function ensurePr( }`; } - if (config.fetchReleaseNotes) { + if (config.fetchReleaseNotes === 'pr') { // fetch changelogs when not already done; await embedChangelogs(upgrades); } diff --git a/lib/workers/repository/updates/branchify.spec.ts b/lib/workers/repository/updates/branchify.spec.ts index 37c98be11dba29..d0b5ac6d54c228 100644 --- a/lib/workers/repository/updates/branchify.spec.ts +++ b/lib/workers/repository/updates/branchify.spec.ts @@ -124,7 +124,7 @@ describe('workers/repository/updates/branchify', () => { }); it('no fetch changelogs', async () => { - config.fetchReleaseNotes = false; + config.fetchReleaseNotes = 'off'; flattenUpdates.mockResolvedValueOnce([ { depName: 'foo', @@ -155,7 +155,7 @@ describe('workers/repository/updates/branchify', () => { }); it('fetch changelogs if required', async () => { - config.fetchReleaseNotes = true; + config.fetchReleaseNotes = 'pr'; config.repoIsOnboarded = true; mockedFunction(_changelog.needsChangelogs).mockReturnValueOnce(true); flattenUpdates.mockResolvedValueOnce([ diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts index 4401fb4341640d..d7043e91765abb 100644 --- a/lib/workers/repository/updates/branchify.ts +++ b/lib/workers/repository/updates/branchify.ts @@ -72,9 +72,9 @@ export async function branchifyUpgrades( }) .reverse(); - if (config.fetchReleaseNotes && config.repoIsOnboarded) { + if (config.fetchReleaseNotes !== 'off' && config.repoIsOnboarded) { const branches = branchUpgrades[branchName].filter((upg) => - needsChangelogs(upg) + needsChangelogs(upg) || config.fetchReleaseNotes === 'branch' ); if (branches.length) { logger.warn( From 5c313141e65ae15681739b2db02f2911b0ccf916 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:16:52 +0545 Subject: [PATCH 02/13] move fetching before postUpgradeTasks --- lib/workers/repository/update/branch/index.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 0b27c6765ffa87..b23cdd8c638376 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -34,7 +34,11 @@ import { toMs } from '../../../../util/pretty-time'; import * as template from '../../../../util/template'; import { isLimitReached } from '../../../global/limits'; import type { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; -import { embedChangelogs, needsChangelogs } from '../../changelog'; +import { + embedChangelog, + embedChangelogs, + needsChangelogs, +} from '../../changelog'; import { ensurePr } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; import { setArtifactErrorStatus } from './artifacts'; @@ -483,6 +487,10 @@ export async function processBranch( } else { logger.debug('No updated lock files in branch'); } + if (config.fetchReleaseNotes === 'branch') { + await embedChangelogs(config.upgrades); + } + const postUpgradeCommandResults = await executePostUpgradeCommands( config ); @@ -540,13 +548,14 @@ export async function processBranch( config.forceCommit = forcedManually || config.isConflicted; // compile commit message with body, which maybe needs changelogs - if (config.fetchReleaseNotes !== 'off' && config.commitBody) { - if (config.fetchReleaseNotes === 'branch') { - await embedChangelogs(config.upgrades); - } else if (needsChangelogs(config, ['commitBody'])) { + if (config.commitBody) { + if ( + config.fetchReleaseNotes !== 'off' && + needsChangelogs(config, ['commitBody']) + ) { // we only need first upgrade, the others are only needed on PR update // we add it to first, so PR fetch can skip fetching for that update - await embedChangelogs(config.upgrades); + await embedChangelog(config.upgrades[0]); // changelog is on first upgrade config.commitMessage = `${config.commitMessage!}\n\n${template.compile( From 5c61522ed0d23aa923e731215f1fdb869c2b4b31 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:20:03 +0545 Subject: [PATCH 03/13] refactor --- lib/workers/repository/update/branch/index.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index b23cdd8c638376..7556dd17c419a8 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -556,21 +556,18 @@ export async function processBranch( // we only need first upgrade, the others are only needed on PR update // we add it to first, so PR fetch can skip fetching for that update await embedChangelog(config.upgrades[0]); - - // changelog is on first upgrade - config.commitMessage = `${config.commitMessage!}\n\n${template.compile( - config.commitBody, - { - ...config, - logJSON: config.upgrades[0].logJSON, - releases: config.upgrades[0].releases, - } - )}`; - - logger.trace( - `commitMessage: ` + JSON.stringify(config.commitMessage) - ); } + // changelog is on first upgrade + config.commitMessage = `${config.commitMessage!}\n\n${template.compile( + config.commitBody, + { + ...config, + logJSON: config.upgrades[0].logJSON, + releases: config.upgrades[0].releases, + } + )}`; + + logger.trace(`commitMessage: ` + JSON.stringify(config.commitMessage)); } commitSha = await commitFilesToBranch(config); From 3117c3a4b343eb214b71207113f59ba91ae917ee Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:21:39 +0545 Subject: [PATCH 04/13] optimize --- lib/workers/repository/update/branch/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 7556dd17c419a8..53785af9c88a44 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -550,7 +550,7 @@ export async function processBranch( // compile commit message with body, which maybe needs changelogs if (config.commitBody) { if ( - config.fetchReleaseNotes !== 'off' && + config.fetchReleaseNotes === 'pr' && needsChangelogs(config, ['commitBody']) ) { // we only need first upgrade, the others are only needed on PR update From d9a1bd24b6000c23478f7c3a157742e9cab7a148 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:24:37 +0545 Subject: [PATCH 05/13] add comment --- lib/workers/repository/update/branch/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 53785af9c88a44..c42b67c40d6664 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -550,6 +550,8 @@ export async function processBranch( // compile commit message with body, which maybe needs changelogs if (config.commitBody) { if ( + // only fetch if fetchReleaseNotes=pr as we would have already + // fetched notes before the postUpgradeTasks if fetchReleaseNotes=branch config.fetchReleaseNotes === 'pr' && needsChangelogs(config, ['commitBody']) ) { From 9b9a5ee2ed4db609965b5adac3d722552c0fb2c3 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:34:21 +0545 Subject: [PATCH 06/13] Update index.ts --- lib/config/options/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 58efb94ca56fda..029df582c59033 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2549,7 +2549,7 @@ const options: RenovateOptions[] = [ }, { name: 'fetchReleaseNotes', - description: 'Controls if and in which stage release notes are fetched.', + description: 'Controls if and when release notes are fetched.', type: 'string', allowedValues: ['off', 'branch', 'pr'], default: 'pr', From 8efea20e536d1bebc6a40517b64488ae59f6fcf5 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 15 Jun 2023 03:37:02 +0545 Subject: [PATCH 07/13] Update index.ts --- lib/workers/repository/update/branch/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index c42b67c40d6664..1508d3791a10d1 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -551,7 +551,7 @@ export async function processBranch( if (config.commitBody) { if ( // only fetch if fetchReleaseNotes=pr as we would have already - // fetched notes before the postUpgradeTasks if fetchReleaseNotes=branch + // fetched the notes before executing the postUpgradeTasks if fetchReleaseNotes=branch config.fetchReleaseNotes === 'pr' && needsChangelogs(config, ['commitBody']) ) { From a1769e4fb872e2bfedb2835313fae81d54de9c0b Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 16 Jun 2023 19:34:33 +0545 Subject: [PATCH 08/13] Apply suggestions from code review Co-authored-by: Rhys Arkins --- docs/usage/configuration-options.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 127531c1f3a757..bae36c2c557a48 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -927,8 +927,10 @@ Use this config option to configure release notes fetching. The available options are: - `off` - disable release notes fetching -- `branch` - fetche release notes while creating/updating branch -- `pr`(default) - fecthes release notes while creating/updating pull-request +- `branch` - fetch release notes while creating/updating branch +- `pr`(default) - fetches release notes while creating/updating pull-request + +It is not recommended to set fetchReleaseNotes=branch unless you are embedding release notes in commit information, because it results in a performance decrease. Renovate can fetch release notes when they are hosted on one of these platforms: From ca9402ed84bca64ee739828328d06776554fbcd6 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 16 Jun 2023 19:52:49 +0545 Subject: [PATCH 09/13] refactor --- lib/config/migrations/migrations-service.ts | 2 +- .../repository/update/branch/index.spec.ts | 4 +--- lib/workers/repository/update/branch/index.ts | 16 +--------------- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index a658933ec4bf13..210980b10672af 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -20,6 +20,7 @@ import { DepTypesMigration } from './custom/dep-types-migration'; import { DryRunMigration } from './custom/dry-run-migration'; import { EnabledManagersMigration } from './custom/enabled-managers-migration'; import { ExtendsMigration } from './custom/extends-migration'; +import { FetchReleaseNotes } from './custom/fetch-release-notes-migration'; import { GoModTidyMigration } from './custom/go-mod-tidy-migration'; import { HostRulesMigration } from './custom/host-rules-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; @@ -55,7 +56,6 @@ import { UnpublishSafeMigration } from './custom/unpublish-safe-migration'; import { UpgradeInRangeMigration } from './custom/upgrade-in-range-migration'; import { VersionStrategyMigration } from './custom/version-strategy-migration'; import type { Migration, MigrationConstructor } from './types'; -import { FetchReleaseNotes } from './custom/fetch-release-notes-migration'; export class MigrationsService { static readonly removedProperties: ReadonlySet = new Set([ diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 835fa41dde5c9f..b969932b454a73 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -34,7 +34,6 @@ import * as _mergeConfidence from '../../../../util/merge-confidence'; import * as _sanitize from '../../../../util/sanitize'; import * as _limits from '../../../global/limits'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; -import { needsChangelogs } from '../../changelog'; import type { ResultWithPr } from '../pr'; import * as _prWorker from '../pr'; import * as _prAutomerge from '../pr/automerge'; @@ -816,9 +815,8 @@ describe('workers/repository/update/branch/index', () => { ignoreTests: true, prCreation: 'not-pending', commitBody: '[skip-ci]', - fetchReleaseNotes: 'pr', + fetchReleaseNotes: 'branch', } satisfies BranchConfig; - mockedFunction(needsChangelogs).mockReturnValueOnce(true); scm.getBranchCommit.mockResolvedValue('123test'); //TODO:not needed? expect(await branchWorker.processBranch(inconfig)).toEqual({ branchExists: true, diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 7419c0e14b28bc..64080d340707ec 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -34,11 +34,7 @@ import { toMs } from '../../../../util/pretty-time'; import * as template from '../../../../util/template'; import { isLimitReached } from '../../../global/limits'; import type { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; -import { - embedChangelog, - embedChangelogs, - needsChangelogs, -} from '../../changelog'; +import { embedChangelogs } from '../../changelog'; import { ensurePr } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; import { setArtifactErrorStatus } from './artifacts'; @@ -548,16 +544,6 @@ export async function processBranch( // compile commit message with body, which maybe needs changelogs if (config.commitBody) { - if ( - // only fetch if fetchReleaseNotes=pr as we would have already - // fetched the notes before executing the postUpgradeTasks if fetchReleaseNotes=branch - config.fetchReleaseNotes === 'pr' && - needsChangelogs(config, ['commitBody']) - ) { - // we only need first upgrade, the others are only needed on PR update - // we add it to first, so PR fetch can skip fetching for that update - await embedChangelog(config.upgrades[0]); - } // changelog is on first upgrade config.commitMessage = `${config.commitMessage!}\n\n${template.compile( config.commitBody, From ca83e8544e60b8298aa92bb7676f4f05173b1091 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 16 Jun 2023 19:57:47 +0545 Subject: [PATCH 10/13] refactor: rename migration class + formatting --- .../custom/fetch-release-notes-migration.spec.ts | 7 ++++--- .../migrations/custom/fetch-release-notes-migration.ts | 4 +++- lib/config/migrations/migrations-service.ts | 4 ++-- lib/workers/repository/update/branch/index.spec.ts | 1 - lib/workers/repository/updates/branchify.ts | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts b/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts index 989660c61df4dc..2e17148597eec2 100644 --- a/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts +++ b/lib/config/migrations/custom/fetch-release-notes-migration.spec.ts @@ -1,7 +1,8 @@ -import { FetchReleaseNotes } from './fetch-release-notes-migration'; +import { FetchReleaseNotesMigration } from './fetch-release-notes-migration'; + describe('config/migrations/custom/fetch-release-notes-migration', () => { it('migrates', () => { - expect(FetchReleaseNotes).toMigrate( + expect(FetchReleaseNotesMigration).toMigrate( { fetchReleaseNotes: false as never, }, @@ -9,7 +10,7 @@ describe('config/migrations/custom/fetch-release-notes-migration', () => { fetchReleaseNotes: 'off', } ); - expect(FetchReleaseNotes).toMigrate( + expect(FetchReleaseNotesMigration).toMigrate( { fetchReleaseNotes: true as never, }, diff --git a/lib/config/migrations/custom/fetch-release-notes-migration.ts b/lib/config/migrations/custom/fetch-release-notes-migration.ts index 2bc91de9589301..60b7afe6eaa1a4 100644 --- a/lib/config/migrations/custom/fetch-release-notes-migration.ts +++ b/lib/config/migrations/custom/fetch-release-notes-migration.ts @@ -1,7 +1,9 @@ import is from '@sindresorhus/is'; import { AbstractMigration } from '../base/abstract-migration'; -export class FetchReleaseNotes extends AbstractMigration { + +export class FetchReleaseNotesMigration extends AbstractMigration { override readonly propertyName = 'fetchReleaseNotes'; + override run(value: unknown): void { if (is.boolean(value)) { this.rewrite(value ? 'pr' : 'off'); diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 210980b10672af..4818e0f2c2a55b 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -20,7 +20,7 @@ import { DepTypesMigration } from './custom/dep-types-migration'; import { DryRunMigration } from './custom/dry-run-migration'; import { EnabledManagersMigration } from './custom/enabled-managers-migration'; import { ExtendsMigration } from './custom/extends-migration'; -import { FetchReleaseNotes } from './custom/fetch-release-notes-migration'; +import { FetchReleaseNotesMigration } from './custom/fetch-release-notes-migration'; import { GoModTidyMigration } from './custom/go-mod-tidy-migration'; import { HostRulesMigration } from './custom/host-rules-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; @@ -149,7 +149,7 @@ export class MigrationsService { DatasourceMigration, RecreateClosedMigration, StabilityDaysMigration, - FetchReleaseNotes, + FetchReleaseNotesMigration, ]; static run(originalConfig: RenovateConfig): RenovateConfig { diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index b969932b454a73..93531eab8def9a 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -3,7 +3,6 @@ import { getConfig, git, mocked, - mockedFunction, partial, platform, scm, diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts index d7043e91765abb..d78c0ecc73e57f 100644 --- a/lib/workers/repository/updates/branchify.ts +++ b/lib/workers/repository/updates/branchify.ts @@ -73,8 +73,8 @@ export async function branchifyUpgrades( .reverse(); if (config.fetchReleaseNotes !== 'off' && config.repoIsOnboarded) { - const branches = branchUpgrades[branchName].filter((upg) => - needsChangelogs(upg) || config.fetchReleaseNotes === 'branch' + const branches = branchUpgrades[branchName].filter( + (upg) => needsChangelogs(upg) || config.fetchReleaseNotes === 'branch' ); if (branches.length) { logger.warn( From 0c20c6fd616fb467d694c095950d26e2021cbc47 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Sat, 17 Jun 2023 06:53:51 +0545 Subject: [PATCH 11/13] Update lib/config/types.ts Co-authored-by: Michael Kriese --- lib/config/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/types.ts b/lib/config/types.ts index 61e92852f138e2..212f1827fe0000 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -299,7 +299,7 @@ export type UpdateType = | 'bump' | 'replacement'; -type FetchReleaseNotesOptions = 'off' | 'branch' | 'pr'; +export type FetchReleaseNotesOptions = 'off' | 'branch' | 'pr'; export type MatchStringsStrategy = 'any' | 'recursive' | 'combination'; From 931e8b96d999061dbd0afa4e13ae31b91f42edf2 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Sat, 17 Jun 2023 20:24:51 +0200 Subject: [PATCH 12/13] drop needsChangelogs() --- .../repository/changelog/index.spec.ts | 21 +----------- lib/workers/repository/changelog/index.ts | 18 ---------- .../repository/updates/branchify.spec.ts | 33 ------------------- lib/workers/repository/updates/branchify.ts | 17 ---------- 4 files changed, 1 insertion(+), 88 deletions(-) diff --git a/lib/workers/repository/changelog/index.spec.ts b/lib/workers/repository/changelog/index.spec.ts index 5ad0dd54bf60c4..709103b105b098 100644 --- a/lib/workers/repository/changelog/index.spec.ts +++ b/lib/workers/repository/changelog/index.spec.ts @@ -1,7 +1,7 @@ import { mockedFunction, partial } from '../../../../test/util'; import type { BranchUpgradeConfig } from '../../types'; import { getChangeLogJSON } from '../update/pr/changelog'; -import { embedChangelogs, needsChangelogs } from '.'; +import { embedChangelogs } from '.'; jest.mock('../update/pr/changelog'); @@ -27,23 +27,4 @@ describe('workers/repository/changelog/index', () => { { logJSON: null }, ]); }); - - it('needsChangelogs', () => { - expect(needsChangelogs(partial())).toBeFalse(); - expect( - needsChangelogs( - partial({ - commitBody: '{{#if logJSON.hasReleaseNotes}}has changelog{{/if}}', - }) - ) - ).toBeFalse(); - expect( - needsChangelogs( - partial({ - commitBody: '{{#if logJSON.hasReleaseNotes}}has changelog{{/if}}', - }), - ['commitBody'] - ) - ).toBeTrue(); - }); }); diff --git a/lib/workers/repository/changelog/index.ts b/lib/workers/repository/changelog/index.ts index 8bc6c455590223..f6c6c6ca4f6881 100644 --- a/lib/workers/repository/changelog/index.ts +++ b/lib/workers/repository/changelog/index.ts @@ -1,8 +1,4 @@ import * as p from '../../../util/promises'; -import { - containsTemplates, - exposedConfigOptions, -} from '../../../util/template'; import type { BranchUpgradeConfig } from '../../types'; import { getChangeLogJSON } from '../update/pr/changelog'; @@ -21,17 +17,3 @@ export async function embedChangelogs( ): Promise { await p.map(branches, embedChangelog, { concurrency: 10 }); } - -export function needsChangelogs( - upgrade: BranchUpgradeConfig, - fields = exposedConfigOptions.filter((o) => o !== 'commitBody') -): boolean { - // commitBody is now compiled when commit is done - for (const field of fields) { - // fields set by `getChangeLogJSON` - if (containsTemplates(upgrade[field], ['logJSON', 'releases'])) { - return true; - } - } - return false; -} diff --git a/lib/workers/repository/updates/branchify.spec.ts b/lib/workers/repository/updates/branchify.spec.ts index d0b5ac6d54c228..cc3bc8194b9bd3 100644 --- a/lib/workers/repository/updates/branchify.spec.ts +++ b/lib/workers/repository/updates/branchify.spec.ts @@ -153,38 +153,5 @@ describe('workers/repository/updates/branchify', () => { expect(embedChangelogs).not.toHaveBeenCalled(); expect(Object.keys(res.branches)).toHaveLength(2); }); - - it('fetch changelogs if required', async () => { - config.fetchReleaseNotes = 'pr'; - config.repoIsOnboarded = true; - mockedFunction(_changelog.needsChangelogs).mockReturnValueOnce(true); - flattenUpdates.mockResolvedValueOnce([ - { - depName: 'foo', - branchName: 'foo', - prTitle: 'some-title', - version: '1.1.0', - groupName: 'My Group', - group: { branchName: 'renovate/{{groupSlug}}' }, - }, - { - depName: 'foo', - branchName: 'foo', - prTitle: 'some-title', - version: '2.0.0', - }, - { - depName: 'bar', - branchName: 'bar-{{version}}', - prTitle: 'some-title', - version: '1.1.0', - groupName: 'My Group', - group: { branchName: 'renovate/my-group' }, - }, - ]); - const res = await branchifyUpgrades(config, {}); - expect(embedChangelogs).toHaveBeenCalledOnce(); - expect(Object.keys(res.branches)).toHaveLength(2); - }); }); }); diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts index d78c0ecc73e57f..d6d0ccf12e53aa 100644 --- a/lib/workers/repository/updates/branchify.ts +++ b/lib/workers/repository/updates/branchify.ts @@ -3,7 +3,6 @@ import type { Merge } from 'type-fest'; import type { RenovateConfig, ValidationMessage } from '../../../config/types'; import { addMeta, logger, removeMeta } from '../../../logger'; import type { BranchConfig, BranchUpgradeConfig } from '../../types'; -import { embedChangelogs, needsChangelogs } from '../changelog'; import { flattenUpdates } from './flatten'; import { generateBranchConfig } from './generate'; @@ -72,22 +71,6 @@ export async function branchifyUpgrades( }) .reverse(); - if (config.fetchReleaseNotes !== 'off' && config.repoIsOnboarded) { - const branches = branchUpgrades[branchName].filter( - (upg) => needsChangelogs(upg) || config.fetchReleaseNotes === 'branch' - ); - if (branches.length) { - logger.warn( - { - branches: branches.map((b) => b.branchName), - docs: 'https://docs.renovatebot.com/templates/', - }, - 'Fetching changelogs early is deprecated. Remove `logJSON` and `releases` from config templates. They are only allowed in `commitBody` template. See template docs for allowed templates' - ); - await embedChangelogs(branches); - } - } - const branch = generateBranchConfig(branchUpgrades[branchName]); branch.branchName = branchName; branch.packageFiles = packageFiles; From 708993a44357e6ae50b7defb9a2fe1748d4ae14c Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Sun, 18 Jun 2023 08:13:48 +0200 Subject: [PATCH 13/13] fix lint --- lib/workers/repository/updates/branchify.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/repository/updates/branchify.spec.ts b/lib/workers/repository/updates/branchify.spec.ts index cc3bc8194b9bd3..99c0d262bb4990 100644 --- a/lib/workers/repository/updates/branchify.spec.ts +++ b/lib/workers/repository/updates/branchify.spec.ts @@ -1,4 +1,4 @@ -import { RenovateConfig, mocked, mockedFunction } from '../../../../test/util'; +import { RenovateConfig, mocked } from '../../../../test/util'; import { getConfig } from '../../../config/defaults'; import * as _changelog from '../changelog'; import { branchifyUpgrades } from './branchify';