mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
fix: advanced schedules migration (#723)
- Split ‘x and y’ schedule into [x, y] - Replace schedules like ’on mondays’ with ‘on monday’
This commit is contained in:
parent
42e2a0905d
commit
5693b17ecf
4 changed files with 57 additions and 8 deletions
|
@ -76,14 +76,36 @@ function migrateConfig(config, parentConfig) {
|
||||||
migratedConfig.packagePatterns = [val];
|
migratedConfig.packagePatterns = [val];
|
||||||
delete migratedConfig.packagePattern;
|
delete migratedConfig.packagePattern;
|
||||||
} else if (key === 'schedule') {
|
} else if (key === 'schedule') {
|
||||||
for (let i = 0; i < val.length; i += 1) {
|
// massage to array first
|
||||||
if (val[i].indexOf('on the last day of the month') !== -1) {
|
let schedules = typeof val === 'string' ? [val] : val;
|
||||||
|
// split 'and'
|
||||||
|
for (let i = 0; i < schedules.length; i += 1) {
|
||||||
|
if (schedules[i].indexOf(' and ') !== -1) {
|
||||||
isMigrated = true;
|
isMigrated = true;
|
||||||
migratedConfig.schedule[i] = val[i].replace(
|
const split = schedules[i].split(' and ');
|
||||||
|
schedules[i] = split[0];
|
||||||
|
schedules = schedules.concat(split.slice(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < schedules.length; i += 1) {
|
||||||
|
if (schedules[i].indexOf('on the last day of the month') !== -1) {
|
||||||
|
isMigrated = true;
|
||||||
|
schedules[i] = schedules[i].replace(
|
||||||
'on the last day of the month',
|
'on the last day of the month',
|
||||||
'on the first day of the month'
|
'on the first day of the month'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (schedules[i].endsWith('days')) {
|
||||||
|
isMigrated = true;
|
||||||
|
schedules[i] = schedules[i].replace('days', 'day');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isMigrated) {
|
||||||
|
if (typeof val === 'string' && schedules.length === 1) {
|
||||||
|
migratedConfig.schedule = schedules[0];
|
||||||
|
} else {
|
||||||
|
migratedConfig.schedule = schedules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
typeof val === 'string' &&
|
typeof val === 'string' &&
|
||||||
|
|
|
@ -91,8 +91,11 @@ function isScheduledNow(config) {
|
||||||
config.logger.debug(`Checking ${configSchedule.length} schedule(s)`);
|
config.logger.debug(`Checking ${configSchedule.length} schedule(s)`);
|
||||||
// We run if any schedule matches
|
// We run if any schedule matches
|
||||||
const isWithinSchedule = configSchedule.some(scheduleText => {
|
const isWithinSchedule = configSchedule.some(scheduleText => {
|
||||||
config.logger.debug(`Checking schedule "${scheduleText}"`);
|
|
||||||
const parsedSchedule = later.parse.text(fixShortHours(scheduleText));
|
const parsedSchedule = later.parse.text(fixShortHours(scheduleText));
|
||||||
|
config.logger.debug(
|
||||||
|
{ parsedSchedule },
|
||||||
|
`Checking schedule "${scheduleText}"`
|
||||||
|
);
|
||||||
// Later library returns array of schedules
|
// Later library returns array of schedules
|
||||||
return parsedSchedule.schedules.some(schedule => {
|
return parsedSchedule.schedules.some(schedule => {
|
||||||
// Check if days are defined
|
// Check if days are defined
|
||||||
|
|
|
@ -26,6 +26,7 @@ Object {
|
||||||
"automerge": true,
|
"automerge": true,
|
||||||
},
|
},
|
||||||
"respectLatest": false,
|
"respectLatest": false,
|
||||||
|
"schedule": "before 5am on Monday",
|
||||||
},
|
},
|
||||||
"packageRules": Array [
|
"packageRules": Array [
|
||||||
Object {
|
Object {
|
||||||
|
@ -49,9 +50,7 @@ Object {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"prTitle": "some pr title",
|
"prTitle": "some pr title",
|
||||||
"schedule": Array [
|
"schedule": "on the first day of the month",
|
||||||
"on the first day of the month",
|
|
||||||
],
|
|
||||||
"semanticPrefix": "fix(deps):",
|
"semanticPrefix": "fix(deps):",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -101,3 +100,12 @@ Object {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`config/migration migrateConfig(config, parentConfig) migrates schedules with and 1`] = `
|
||||||
|
Object {
|
||||||
|
"schedule": Array [
|
||||||
|
"after 10pm",
|
||||||
|
"before 7am",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('config/migration', () => {
|
||||||
onboarding: 'false',
|
onboarding: 'false',
|
||||||
automerge: 'none',
|
automerge: 'none',
|
||||||
autodiscover: 'true',
|
autodiscover: 'true',
|
||||||
schedule: ['on the last day of the month'],
|
schedule: 'on the last day of the month',
|
||||||
commitMessage: '{{semanticPrefix}}some commit message',
|
commitMessage: '{{semanticPrefix}}some commit message',
|
||||||
prTitle: '{{semanticPrefix}}some pr title',
|
prTitle: '{{semanticPrefix}}some pr title',
|
||||||
semanticPrefix: 'fix(deps): ',
|
semanticPrefix: 'fix(deps): ',
|
||||||
|
@ -42,6 +42,7 @@ describe('config/migration', () => {
|
||||||
depType: 'optionalDependencies',
|
depType: 'optionalDependencies',
|
||||||
respectLatest: false,
|
respectLatest: false,
|
||||||
automerge: 'minor',
|
automerge: 'minor',
|
||||||
|
schedule: 'before 5am on Mondays',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -56,6 +57,21 @@ describe('config/migration', () => {
|
||||||
expect(migratedConfig.automerge).toEqual(false);
|
expect(migratedConfig.automerge).toEqual(false);
|
||||||
expect(migratedConfig).toMatchSnapshot();
|
expect(migratedConfig).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
it('migrates schedules with and', () => {
|
||||||
|
const config = {
|
||||||
|
schedule: 'after 10pm and before 7am',
|
||||||
|
};
|
||||||
|
const parentConfig = { ...defaultConfig };
|
||||||
|
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
|
||||||
|
config,
|
||||||
|
parentConfig
|
||||||
|
);
|
||||||
|
expect(migratedConfig).toMatchSnapshot();
|
||||||
|
expect(isMigrated).toBe(true);
|
||||||
|
expect(migratedConfig.schedule.length).toBe(2);
|
||||||
|
expect(migratedConfig.schedule[0]).toEqual('after 10pm');
|
||||||
|
expect(migratedConfig.schedule[1]).toEqual('before 7am');
|
||||||
|
});
|
||||||
it('it migrates packages', () => {
|
it('it migrates packages', () => {
|
||||||
const config = {
|
const config = {
|
||||||
packages: [
|
packages: [
|
||||||
|
|
Loading…
Reference in a new issue