Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(release-notes)!: support configurable fetching stage #22781

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,14 @@ 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` - 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:
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
22 changes: 22 additions & 0 deletions lib/config/migrations/custom/fetch-release-notes-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FetchReleaseNotesMigration } from './fetch-release-notes-migration';

describe('config/migrations/custom/fetch-release-notes-migration', () => {
it('migrates', () => {
expect(FetchReleaseNotesMigration).toMigrate(
{
fetchReleaseNotes: false as never,
},
{
fetchReleaseNotes: 'off',
}
);
expect(FetchReleaseNotesMigration).toMigrate(
{
fetchReleaseNotes: true as never,
},
{
fetchReleaseNotes: 'pr',
}
);
});
});
12 changes: 12 additions & 0 deletions lib/config/migrations/custom/fetch-release-notes-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class FetchReleaseNotesMigration extends AbstractMigration {
override readonly propertyName = 'fetchReleaseNotes';

override run(value: unknown): void {
if (is.boolean(value)) {
this.rewrite(value ? 'pr' : 'off');
}
}
}
2 changes: 2 additions & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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';
Expand Down Expand Up @@ -148,6 +149,7 @@ export class MigrationsService {
DatasourceMigration,
RecreateClosedMigration,
StabilityDaysMigration,
FetchReleaseNotesMigration,
];

static run(originalConfig: RenovateConfig): RenovateConfig {
Expand Down
7 changes: 4 additions & 3 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2551,9 +2551,10 @@ const options: RenovateOptions[] = [
},
{
name: 'fetchReleaseNotes',
description: 'Controls if release notes are fetched.',
type: 'boolean',
default: true,
description: 'Controls if and when release notes are fetched.',
type: 'string',
allowedValues: ['off', 'branch', 'pr'],
default: 'pr',
cli: false,
env: false,
},
Expand Down
4 changes: 3 additions & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface RenovateConfig
vulnerabilitySeverity?: string;
regexManagers?: RegExManager[];

fetchReleaseNotes?: boolean;
fetchReleaseNotes?: FetchReleaseNotesOptions;
secrets?: Record<string, string>;

constraints?: Record<string, string>;
Expand Down Expand Up @@ -299,6 +299,8 @@ export type UpdateType =
| 'bump'
| 'replacement';

type FetchReleaseNotesOptions = 'off' | 'branch' | 'pr';
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

export type MatchStringsStrategy = 'any' | 'recursive' | 'combination';

export type MergeStrategy =
Expand Down
5 changes: 1 addition & 4 deletions lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
getConfig,
git,
mocked,
mockedFunction,
partial,
platform,
scm,
Expand Down Expand Up @@ -34,7 +33,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';
Expand Down Expand Up @@ -816,9 +814,8 @@ describe('workers/repository/update/branch/index', () => {
ignoreTests: true,
prCreation: 'not-pending',
commitBody: '[skip-ci]',
fetchReleaseNotes: true,
fetchReleaseNotes: 'branch',
} satisfies BranchConfig;
mockedFunction(needsChangelogs).mockReturnValueOnce(true);
scm.getBranchCommit.mockResolvedValue('123test'); //TODO:not needed?
expect(await branchWorker.processBranch(inconfig)).toEqual({
branchExists: true,
Expand Down
14 changes: 5 additions & 9 deletions lib/workers/repository/update/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../changelog';
import { ensurePr } from '../pr';
import { checkAutoMerge } from '../pr/automerge';
import { setArtifactErrorStatus } from './artifacts';
Expand Down Expand Up @@ -482,6 +482,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
);
Expand Down Expand Up @@ -540,14 +544,6 @@ export async function processBranch(

// compile commit message with body, which maybe needs changelogs
if (config.commitBody) {
if (
config.fetchReleaseNotes &&
needsChangelogs(config, ['commitBody'])
rarkins marked this conversation as resolved.
Show resolved Hide resolved
) {
// 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
10 changes: 5 additions & 5 deletions lib/workers/repository/update/pr/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/update/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export async function ensurePr(
}`;
}

if (config.fetchReleaseNotes) {
if (config.fetchReleaseNotes === 'pr') {
// fetch changelogs when not already done;
await embedChangelogs(upgrades);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/updates/branchify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('workers/repository/updates/branchify', () => {
});

it('no fetch changelogs', async () => {
config.fetchReleaseNotes = false;
config.fetchReleaseNotes = 'off';
flattenUpdates.mockResolvedValueOnce([
{
depName: 'foo',
Expand Down Expand Up @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/updates/branchify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export async function branchifyUpgrades(
})
.reverse();

if (config.fetchReleaseNotes && config.repoIsOnboarded) {
const branches = branchUpgrades[branchName].filter((upg) =>
needsChangelogs(upg)
if (config.fetchReleaseNotes !== 'off' && config.repoIsOnboarded) {
const branches = branchUpgrades[branchName].filter(
(upg) => needsChangelogs(upg) || config.fetchReleaseNotes === 'branch'
);
if (branches.length) {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
logger.warn(
Expand Down