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
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
@@ -923,7 +923,12 @@ 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` - fetche release notes while creating/updating branch
- `pr`(default) - fecthes release notes while creating/updating pull-request

Renovate can fetch release notes when they are hosted on one of these platforms:

21 changes: 21 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,21 @@
import { FetchReleaseNotes } from './fetch-release-notes-migration';
describe('config/migrations/custom/fetch-release-notes-migration', () => {
it('migrates', () => {
expect(FetchReleaseNotes).toMigrate(
{
fetchReleaseNotes: false as never,
},
{
fetchReleaseNotes: 'off',
}
);
expect(FetchReleaseNotes).toMigrate(
{
fetchReleaseNotes: true as never,
},
{
fetchReleaseNotes: 'pr',
}
);
});
});
10 changes: 10 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,10 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';
export class FetchReleaseNotes 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
@@ -55,6 +55,7 @@ import { UnpublishSafeMigration } from './custom/unpublish-safe-migration';
import { UpgradeInRangeMigration } from './custom/upgrade-in-range-migration';
import { VersionStrategyMigration } from './custom/version-strategy-migration';
import type { Migration, MigrationConstructor } from './types';
import { FetchReleaseNotes } from './custom/fetch-release-notes-migration';

export class MigrationsService {
static readonly removedProperties: ReadonlySet<string> = new Set([
@@ -148,6 +149,7 @@ export class MigrationsService {
DatasourceMigration,
RecreateClosedMigration,
StabilityDaysMigration,
FetchReleaseNotes,
];

static run(originalConfig: RenovateConfig): RenovateConfig {
7 changes: 4 additions & 3 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
@@ -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,
},
4 changes: 3 additions & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
@@ -258,7 +258,7 @@ export interface RenovateConfig
vulnerabilitySeverity?: string;
regexManagers?: RegExManager[];

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

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

type FetchReleaseNotesOptions = 'off' | 'branch' | 'pr';

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

export type MergeStrategy =
2 changes: 1 addition & 1 deletion lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
@@ -816,7 +816,7 @@ describe('workers/repository/update/branch/index', () => {
ignoreTests: true,
prCreation: 'not-pending',
commitBody: '[skip-ci]',
fetchReleaseNotes: true,
fetchReleaseNotes: 'pr',
} satisfies BranchConfig;
mockedFunction(needsChangelogs).mockReturnValueOnce(true);
scm.getBranchCommit.mockResolvedValue('123test'); //TODO:not needed?
14 changes: 12 additions & 2 deletions lib/workers/repository/update/branch/index.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,11 @@ 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 {
embedChangelog,
embedChangelogs,
needsChangelogs,
} from '../../changelog';
import { ensurePr } from '../pr';
import { checkAutoMerge } from '../pr/automerge';
import { setArtifactErrorStatus } from './artifacts';
@@ -482,6 +486,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
);
@@ -541,7 +549,9 @@ export async function processBranch(
// compile commit message with body, which maybe needs changelogs
if (config.commitBody) {
if (
config.fetchReleaseNotes &&
// only fetch if fetchReleaseNotes=pr as we would have already
// fetched the notes before executing the postUpgradeTasks if fetchReleaseNotes=branch
config.fetchReleaseNotes === 'pr' &&
needsChangelogs(config, ['commitBody'])
) {
// we only need first upgrade, the others are only needed on PR update
10 changes: 5 additions & 5 deletions lib/workers/repository/update/pr/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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);

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

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

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

if (config.fetchReleaseNotes && config.repoIsOnboarded) {
if (config.fetchReleaseNotes !== 'off' && config.repoIsOnboarded) {
const branches = branchUpgrades[branchName].filter((upg) =>
needsChangelogs(upg)
needsChangelogs(upg) || config.fetchReleaseNotes === 'branch'
);
if (branches.length) {
logger.warn(