Skip to content

Commit b6b85eb

Browse files
authored
feat(package-rules): set skipStage (#30264)
1 parent e2a7586 commit b6b85eb

File tree

8 files changed

+61
-9
lines changed

8 files changed

+61
-9
lines changed

lib/config/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { LogLevelRemap } from '../logger/types';
44
import type { CustomManager } from '../modules/manager/custom/types';
55
import type { RepoSortMethod, SortMethod } from '../modules/platform/types';
66
import type { HostRule, SkipReason } from '../types';
7+
import type { StageName } from '../types/skip-reason';
78
import type { GitNoVerifyOption } from '../util/git/types';
89
import type { MergeConfidence } from '../util/merge-confidence/types';
910

@@ -555,6 +556,7 @@ export interface PackageRuleInputConfig extends Record<string, unknown> {
555556
currentVersionTimestamp?: string;
556557
enabled?: boolean;
557558
skipReason?: SkipReason;
559+
skipStage?: StageName;
558560
}
559561

560562
export interface ConfigMigration {

lib/types/skip-reason.ts

+10
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ export type SkipReason =
4646
| 'recursive-placeholder'
4747
| 'github-token-required'
4848
| 'inherited-dependency';
49+
50+
export type StageName =
51+
| 'current-timestamp'
52+
| 'datasource-merge'
53+
| 'lock-file-maintenance-merge'
54+
| 'lock-file-maintenance-merge-2'
55+
| 'pre-lookup'
56+
| 'source-url'
57+
| 'update-type'
58+
| 'update-type-merge';

lib/util/package-rules/index.spec.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,28 @@ describe('util/package-rules/index', () => {
219219
},
220220
],
221221
};
222-
const res = applyPackageRules(dep);
222+
const res = applyPackageRules(dep, 'datasource-merge');
223223
expect(res.enabled).toBeFalse();
224224
expect(res.skipReason).toBe('package-rules');
225+
expect(res.skipStage).toBe('datasource-merge');
226+
});
227+
228+
it('unsets skipReason=package-rules if enabled=true', () => {
229+
const dep: any = {
230+
depName: 'foo',
231+
packageRules: [
232+
{
233+
enabled: false,
234+
},
235+
{
236+
enabled: true,
237+
},
238+
],
239+
};
240+
const res = applyPackageRules(dep, 'datasource-merge');
241+
expect(res.enabled).toBeTrue();
242+
expect(res.skipReason).toBeUndefined();
243+
expect(res.skipStage).toBeUndefined();
225244
});
226245

227246
it('skips skipReason=package-rules if enabled=true', () => {

lib/util/package-rules/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import slugify from 'slugify';
33
import { mergeChildConfig } from '../../config';
44
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
55
import { logger } from '../../logger';
6+
import type { StageName } from '../../types/skip-reason';
67
import matchers from './matchers';
78
import { matcherOR } from './utils';
89

@@ -62,6 +63,7 @@ function matchesRule(
6263

6364
export function applyPackageRules<T extends PackageRuleInputConfig>(
6465
inputConfig: T,
66+
stageName?: StageName,
6567
): T {
6668
let config = { ...inputConfig };
6769
const packageRules = config.packageRules ?? [];
@@ -82,6 +84,13 @@ export function applyPackageRules<T extends PackageRuleInputConfig>(
8284
}
8385
if (toApply.enabled === false && config.enabled !== false) {
8486
config.skipReason = 'package-rules';
87+
if (stageName) {
88+
config.skipStage = stageName;
89+
}
90+
}
91+
if (toApply.enabled === true && config.enabled === false) {
92+
delete config.skipReason;
93+
delete config.skipStage;
8594
}
8695
config = mergeChildConfig(config, toApply);
8796
}

lib/workers/repository/process/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function fetchDepUpdates(
4444
const datasourceDefaultConfig = await getDefaultConfig(depConfig.datasource!);
4545
depConfig = mergeChildConfig(depConfig, datasourceDefaultConfig);
4646
depConfig.versioning ??= getDefaultVersioning(depConfig.datasource);
47-
depConfig = applyPackageRules(depConfig);
47+
depConfig = applyPackageRules(depConfig, 'pre-lookup');
4848
depConfig.packageName ??= depConfig.depName;
4949
if (depConfig.ignoreDeps!.includes(depName!)) {
5050
// TODO: fix types (#22198)

lib/workers/repository/process/lookup/filter-checks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function filterInternalChecks(
5252
releaseConfig[releaseConfig.updateType]!,
5353
);
5454
// Apply packageRules in case any apply to updateType
55-
releaseConfig = applyPackageRules(releaseConfig);
55+
releaseConfig = applyPackageRules(releaseConfig, 'update-type');
5656
// Now check for a minimumReleaseAge config
5757
const {
5858
minimumConfidence,

lib/workers/repository/process/lookup/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ export async function lookupUpdates(
200200
}
201201
}
202202
// Reapply package rules in case we missed something from sourceUrl
203-
config = applyPackageRules({ ...config, sourceUrl: res.sourceUrl });
203+
config = applyPackageRules(
204+
{ ...config, sourceUrl: res.sourceUrl },
205+
'source-url',
206+
);
204207
if (config.followTag) {
205208
const taggedVersion = dependency.tags?.[config.followTag];
206209
if (!taggedVersion) {
@@ -313,7 +316,10 @@ export async function lookupUpdates(
313316
)
314317
) {
315318
// Reapply package rules to check matches for matchCurrentAge
316-
config = applyPackageRules({ ...config, currentVersionTimestamp });
319+
config = applyPackageRules(
320+
{ ...config, currentVersionTimestamp },
321+
'current-timestamp',
322+
);
317323
}
318324
}
319325

lib/workers/repository/updates/flatten.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function flattenUpdates(
113113
depConfig.datasource,
114114
);
115115
updateConfig = mergeChildConfig(updateConfig, datasourceConfig);
116-
updateConfig = applyPackageRules(updateConfig);
116+
updateConfig = applyPackageRules(updateConfig, 'datasource-merge');
117117
// apply major/minor/patch/pin/digest
118118
updateConfig = mergeChildConfig(
119119
updateConfig,
@@ -123,7 +123,7 @@ export async function flattenUpdates(
123123
delete updateConfig[updateType];
124124
}
125125
// Apply again in case any were added by the updateType config
126-
updateConfig = applyPackageRules(updateConfig);
126+
updateConfig = applyPackageRules(updateConfig, 'update-type-merge');
127127
updateConfig = applyUpdateConfig(updateConfig);
128128
updateConfig.baseDeps = packageFile.deps;
129129
update.branchName = updateConfig.branchName;
@@ -143,13 +143,19 @@ export async function flattenUpdates(
143143
);
144144
lockFileConfig.updateType = 'lockFileMaintenance';
145145
lockFileConfig.isLockFileMaintenance = true;
146-
lockFileConfig = applyPackageRules(lockFileConfig);
146+
lockFileConfig = applyPackageRules(
147+
lockFileConfig,
148+
'lock-file-maintenance-merge',
149+
);
147150
// Apply lockFileMaintenance and packageRules again
148151
lockFileConfig = mergeChildConfig(
149152
lockFileConfig,
150153
lockFileConfig.lockFileMaintenance,
151154
);
152-
lockFileConfig = applyPackageRules(lockFileConfig);
155+
lockFileConfig = applyPackageRules(
156+
lockFileConfig,
157+
'lock-file-maintenance-merge-2',
158+
);
153159
// Remove unnecessary objects
154160
for (const updateType of updateTypes) {
155161
delete lockFileConfig[updateType];

0 commit comments

Comments
 (0)