Skip to content

Commit

Permalink
feat(changelogs): defer fetching until required (#17149)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 12, 2022
1 parent 60ed6ad commit 8fd114e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
8 changes: 0 additions & 8 deletions lib/workers/repository/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions lib/workers/repository/update/branch/index.spec.ts
Expand Up @@ -3,6 +3,7 @@ import {
fs,
git,
mocked,
mockedFunction,
partial,
platform,
} from '../../../../../test/util';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions lib/workers/repository/update/branch/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/workers/repository/update/pr/index.spec.ts
Expand Up @@ -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' });
Expand Down
10 changes: 5 additions & 5 deletions lib/workers/repository/update/pr/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8fd114e

Please sign in to comment.