diff --git a/docs/usage/templates.md b/docs/usage/templates.md index ab46b61a3046b9..558afa3c27c869 100644 --- a/docs/usage/templates.md +++ b/docs/usage/templates.md @@ -13,6 +13,8 @@ You can recognize templates when you see strings like `{{depName}}` in configura Below you can find lists of fields/values that you can use in templates. Some are configuration options passed through, while others are generated as part of Renovate's run. +`logJSON` and `releases` are only allowed in `commitBody` template. + ## Exposed config options diff --git a/lib/workers/repository/changelog/index.spec.ts b/lib/workers/repository/changelog/index.spec.ts index 27eb29da452e8d..ad2a87d84a8428 100644 --- a/lib/workers/repository/changelog/index.spec.ts +++ b/lib/workers/repository/changelog/index.spec.ts @@ -36,6 +36,14 @@ describe('workers/repository/changelog/index', () => { 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 7bc144ad910afa..9a141dc04810b2 100644 --- a/lib/workers/repository/changelog/index.ts +++ b/lib/workers/repository/changelog/index.ts @@ -6,7 +6,9 @@ import { import type { BranchUpgradeConfig } from '../../types'; import { getChangeLogJSON } from '../update/pr/changelog'; -async function embedChangelog(upgrade: BranchUpgradeConfig): Promise { +export async function embedChangelog( + upgrade: BranchUpgradeConfig +): Promise { // getChangeLogJSON returns null on error, so don't try again if (upgrade.logJSON !== undefined) { return; @@ -20,8 +22,12 @@ export async function embedChangelogs( await pMap(branches, embedChangelog, { concurrency: 10 }); } -export function needsChangelogs(upgrade: BranchUpgradeConfig): boolean { - for (const field of exposedConfigOptions) { +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; diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index a5417289605439..0209c71efd8b69 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -46,6 +46,7 @@ jest.mock('./automerge'); jest.mock('./commit'); jest.mock('../pr'); jest.mock('../pr/automerge'); +jest.mock('../../changelog'); jest.mock('../../../../util/exec'); jest.mock('../../../../util/merge-confidence'); jest.mock('../../../../util/sanitize'); @@ -656,6 +657,7 @@ describe('workers/repository/update/branch/index', () => { ...config, ignoreTests: true, prCreation: 'not-pending', + commitBody: '[skip-ci]', }) ).toEqual({ branchExists: true, diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 53f1ef2cf9f1e0..465934804f65e0 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -40,8 +40,10 @@ import { isActiveConfidenceLevel, satisfiesConfidenceLevel, } from '../../../../util/merge-confidence'; +import * as template from '../../../../util/template'; import { Limit, isLimitReached } from '../../../global/limits'; import { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; +// import { embedChangelog, needsChangelogs } from '../../changelog'; import { ensurePr, getPlatformPrOptions, updatePrDebugData } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; import { getPrBody } from '../pr/body'; @@ -483,6 +485,25 @@ export async function processBranch( } } + // compile commit message with body, which maybe needs changelogs + if (config.commitBody) { + // TODO: defer fetching changelogs (#17020) + // if (config.fetchReleaseNotes && needsChangelogs(config, ['commitBody'])) { + // await embedChangelog(config); + // } + // 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)); + } + const commitSha = await commitFilesToBranch(config); // istanbul ignore if if (branchPr && platform.refreshPr) { diff --git a/lib/workers/repository/update/pr/index.spec.ts b/lib/workers/repository/update/pr/index.spec.ts index acb1d94c1dbd67..072bf4f1d28890 100644 --- a/lib/workers/repository/update/pr/index.spec.ts +++ b/lib/workers/repository/update/pr/index.spec.ts @@ -24,6 +24,7 @@ import * as _participants from './participants'; import { ensurePr } from '.'; jest.mock('../../../../util/git'); +jest.mock('../../changelog'); jest.mock('../../../global/limits'); const limits = mocked(_limits); diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index 6f049390f09280..8f0cd8afa0342b 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -27,6 +27,7 @@ import type { BranchUpgradeConfig, PrBlockedBy, } from '../../../types'; +// import { embedChangelogs } from '../../changelog'; import { resolveBranchStatus } from '../branch/status-checks'; import { getPrBody } from './body'; import { ChangeLogError } from './changelog/types'; @@ -194,6 +195,12 @@ export async function ensurePr( }`; } + // TODO: defer fetching changelogs (#17020) + // if (config.fetchReleaseNotes) { + // // fetch changelogs when not already done; + // await embedChangelogs(upgrades); + // } + // Get changelog and then generate template strings for (const upgrade of upgrades) { // TODO: types (#7154) diff --git a/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap b/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap index 59e1f8cdc8893f..3894797ee5f01f 100644 --- a/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap +++ b/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap @@ -1,7 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/repository/updates/generate generateBranchConfig() adds commit message body 1`] = `"Update dependency some-dep to v1.2.0\\n\\n[skip-ci]"`; - exports[`workers/repository/updates/generate generateBranchConfig() handles @types specially (reversed) 1`] = ` Object { "addLabels": Array [], diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts index 21efe11b7c4741..4401fb4341640d 100644 --- a/lib/workers/repository/updates/branchify.ts +++ b/lib/workers/repository/updates/branchify.ts @@ -73,11 +73,16 @@ export async function branchifyUpgrades( .reverse(); if (config.fetchReleaseNotes && config.repoIsOnboarded) { - const branches = branchUpgrades[branchName].filter(needsChangelogs); + const branches = branchUpgrades[branchName].filter((upg) => + needsChangelogs(upg) + ); if (branches.length) { - logger.info( - { branches: branches.map((b) => b.branchName) }, - 'Fetching changelogs early' + 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); } diff --git a/lib/workers/repository/updates/generate.spec.ts b/lib/workers/repository/updates/generate.spec.ts index 2b98079568ca63..baecdac8acff7f 100644 --- a/lib/workers/repository/updates/generate.spec.ts +++ b/lib/workers/repository/updates/generate.spec.ts @@ -679,8 +679,7 @@ describe('workers/repository/updates/generate', () => { } as BranchUpgradeConfig, ]; const res = generateBranchConfig(branch); - expect(res.commitMessage).toMatchSnapshot(); - expect(res.commitMessage).toContain('\n'); + expect(res.commitMessage).toBe('Update dependency some-dep to v1.2.0'); }); it('supports manual prTitle', () => { diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 080914bc5d3273..20ebc0de9d4d71 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -223,12 +223,7 @@ export function generateBranchConfig( splitMessage[0] = splitMessage[0].toLowerCase(); upgrade.commitMessage = splitMessage.join('\n'); } - if (upgrade.commitBody) { - upgrade.commitMessage = `${upgrade.commitMessage}\n\n${template.compile( - upgrade.commitBody, - upgrade - )}`; - } + logger.trace(`commitMessage: ` + JSON.stringify(upgrade.commitMessage)); if (upgrade.prTitle) { upgrade.prTitle = template.compile(upgrade.prTitle, upgrade);