feat(changelogs): defer fetching until required (#17149)

This commit is contained in:
Michael Kriese 2022-08-12 09:12:19 +02:00 committed by GitHub
parent 60ed6ad40d
commit 8fd114ea90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 17 deletions

View file

@ -9,7 +9,6 @@ import { deleteLocalFile, privateCacheDir } from '../../util/fs';
import * as queue from '../../util/http/queue'; import * as queue from '../../util/http/queue';
import { addSplit, getSplits, splitInit } from '../../util/split'; import { addSplit, getSplits, splitInit } from '../../util/split';
import { setBranchCache } from './cache'; import { setBranchCache } from './cache';
import { embedChangelogs } from './changelog';
import { ensureDependencyDashboard } from './dependency-dashboard'; import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error'; import handleError from './error';
import { finaliseRepo } from './finalise'; import { finaliseRepo } from './finalise';
@ -49,13 +48,6 @@ export async function renovateRepository(
) { ) {
await ensureOnboardingPr(config, packageFiles, branches); await ensureOnboardingPr(config, packageFiles, branches);
addSplit('onboarding'); addSplit('onboarding');
if (config.fetchReleaseNotes && config.repoIsOnboarded) {
logger.info('Fetching changelogs');
for (const branch of branches) {
await embedChangelogs(branch.upgrades);
}
}
addSplit('changelogs');
const res = await updateRepo(config, branches); const res = await updateRepo(config, branches);
setMeta({ repository: config.repository }); setMeta({ repository: config.repository });
addSplit('update'); addSplit('update');

View file

@ -3,6 +3,7 @@ import {
fs, fs,
git, git,
mocked, mocked,
mockedFunction,
partial, partial,
platform, platform,
} from '../../../../../test/util'; } from '../../../../../test/util';
@ -24,6 +25,7 @@ import * as _sanitize from '../../../../util/sanitize';
import * as _limits from '../../../global/limits'; import * as _limits from '../../../global/limits';
import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types';
import { BranchResult } from '../../../types'; import { BranchResult } from '../../../types';
import { needsChangelogs } from '../../changelog';
import type { Pr } from '../../onboarding/branch/check'; import type { Pr } from '../../onboarding/branch/check';
import * as _prWorker from '../pr'; import * as _prWorker from '../pr';
import type { ResultWithPr } from '../pr'; import type { ResultWithPr } from '../pr';
@ -652,12 +654,16 @@ describe('workers/repository/update/branch/index', () => {
artifactErrors: [], artifactErrors: [],
updatedArtifacts: [partial<FileChange>({})], updatedArtifacts: [partial<FileChange>({})],
} as WriteExistingFilesResult); } as WriteExistingFilesResult);
mockedFunction(needsChangelogs).mockReturnValueOnce(true);
expect( expect(
await branchWorker.processBranch({ await branchWorker.processBranch({
...config, ...config,
ignoreTests: true, ignoreTests: true,
prCreation: 'not-pending', prCreation: 'not-pending',
commitBody: '[skip-ci]', commitBody: '[skip-ci]',
fetchReleaseNotes: true,
}) })
).toEqual({ ).toEqual({
branchExists: true, branchExists: true,

View file

@ -43,6 +43,7 @@ import {
import * as template from '../../../../util/template'; import * as template from '../../../../util/template';
import { Limit, isLimitReached } from '../../../global/limits'; import { Limit, isLimitReached } from '../../../global/limits';
import { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; import { BranchConfig, BranchResult, PrBlockedBy } from '../../../types';
import { embedChangelog, needsChangelogs } from '../../changelog';
// import { embedChangelog, needsChangelogs } from '../../changelog'; // import { embedChangelog, needsChangelogs } from '../../changelog';
import { ensurePr, getPlatformPrOptions, updatePrDebugData } from '../pr'; import { ensurePr, getPlatformPrOptions, updatePrDebugData } from '../pr';
import { checkAutoMerge } from '../pr/automerge'; import { checkAutoMerge } from '../pr/automerge';
@ -487,10 +488,11 @@ export async function processBranch(
// compile commit message with body, which maybe needs changelogs // compile commit message with body, which maybe needs changelogs
if (config.commitBody) { if (config.commitBody) {
// TODO: defer fetching changelogs (#17020) if (config.fetchReleaseNotes && needsChangelogs(config, ['commitBody'])) {
// if (config.fetchReleaseNotes && needsChangelogs(config, ['commitBody'])) { // we only need first upgrade, the others are only needed on PR update
// await embedChangelog(config); // we add it to first, so PR fetch can skip fetching for that update
// } await embedChangelog(config.upgrades[0]);
}
// changelog is on first upgrade // changelog is on first upgrade
config.commitMessage = `${config.commitMessage!}\n\n${template.compile( config.commitMessage = `${config.commitMessage!}\n\n${template.compile(
config.commitBody, config.commitBody,

View file

@ -91,6 +91,8 @@ describe('workers/repository/update/pr/index', () => {
platform.createPr.mockResolvedValueOnce(pr); platform.createPr.mockResolvedValueOnce(pr);
limits.isLimitReached.mockReturnValueOnce(true); limits.isLimitReached.mockReturnValueOnce(true);
config.fetchReleaseNotes = true;
const res = await ensurePr(config); const res = await ensurePr(config);
expect(res).toEqual({ type: 'without-pr', prBlockedBy: 'RateLimited' }); expect(res).toEqual({ type: 'without-pr', prBlockedBy: 'RateLimited' });

View file

@ -27,6 +27,7 @@ import type {
BranchUpgradeConfig, BranchUpgradeConfig,
PrBlockedBy, PrBlockedBy,
} from '../../../types'; } from '../../../types';
import { embedChangelogs } from '../../changelog';
// import { embedChangelogs } from '../../changelog'; // import { embedChangelogs } from '../../changelog';
import { resolveBranchStatus } from '../branch/status-checks'; import { resolveBranchStatus } from '../branch/status-checks';
import { getPrBody } from './body'; import { getPrBody } from './body';
@ -195,11 +196,10 @@ export async function ensurePr(
}`; }`;
} }
// TODO: defer fetching changelogs (#17020) if (config.fetchReleaseNotes) {
// if (config.fetchReleaseNotes) { // fetch changelogs when not already done;
// // fetch changelogs when not already done; await embedChangelogs(upgrades);
// await embedChangelogs(upgrades); }
// }
// Get changelog and then generate template strings // Get changelog and then generate template strings
for (const upgrade of upgrades) { for (const upgrade of upgrades) {