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 { addSplit, getSplits, splitInit } from '../../util/split';
import { setBranchCache } from './cache';
import { embedChangelogs } from './changelog';
import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error';
import { finaliseRepo } from './finalise';
@ -49,13 +48,6 @@ export async function renovateRepository(
) {
await ensureOnboardingPr(config, packageFiles, branches);
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);
setMeta({ repository: config.repository });
addSplit('update');

View file

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

View file

@ -43,6 +43,7 @@ import {
import * as template from '../../../../util/template';
import { Limit, isLimitReached } from '../../../global/limits';
import { BranchConfig, BranchResult, PrBlockedBy } from '../../../types';
import { embedChangelog, needsChangelogs } from '../../changelog';
// import { embedChangelog, needsChangelogs } from '../../changelog';
import { ensurePr, getPlatformPrOptions, updatePrDebugData } from '../pr';
import { checkAutoMerge } from '../pr/automerge';
@ -487,10 +488,11 @@ 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);
// }
if (config.fetchReleaseNotes && 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,

View file

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

View file

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