Skip to content
Snippets Groups Projects
Unverified Commit 0f6772e6 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

refactor: flatten updateTypes inside packageRules (#2808)

Closes #2799 
parent b0293da9
No related merge requests found
......@@ -38,5 +38,35 @@ function massageConfig(config) {
massagedConfig[key] = massageConfig(val);
}
}
if (massagedConfig.packageRules) {
const newRules = [];
const updateTypes = [
'major',
'minor',
'patch',
'pin',
'digest',
'lockFileMaintenance',
'rollback',
];
for (const rule of massagedConfig.packageRules) {
newRules.push(rule);
for (const [key, val] of Object.entries(rule)) {
if (updateTypes.includes(key)) {
const newRule = deepcopy(rule);
newRule.updateTypes = rule.updateTypes || [];
newRule.updateTypes.push(key);
Object.assign(newRule, val);
newRules.push(newRule);
}
}
}
for (const rule of newRules) {
updateTypes.forEach(updateType => {
delete rule[updateType];
});
}
massagedConfig.packageRules = newRules;
}
return massagedConfig;
}
......@@ -7,4 +7,34 @@ Object {
}
`;
exports[`config/massage massageConfig massages packageRules updateTypes 1`] = `
Object {
"packageRules": Array [
Object {
"packageNames": Array [
"foo",
],
},
Object {
"packageNames": Array [
"foo",
],
"semanticCommitType": "feat",
"updateTypes": Array [
"minor",
],
},
Object {
"packageNames": Array [
"foo",
],
"semanticCommitType": "fix",
"updateTypes": Array [
"patch",
],
},
],
}
`;
exports[`config/massage massageConfig returns empty 1`] = `Object {}`;
......@@ -20,5 +20,23 @@ describe('config/massage', () => {
};
expect(massage.massageConfig(config)).toMatchSnapshot();
});
it('massages packageRules updateTypes', () => {
const config = {
packageRules: [
{
packageNames: ['foo'],
minor: {
semanticCommitType: 'feat',
},
patch: {
semanticCommitType: 'fix',
},
},
],
};
const res = massage.massageConfig(config);
expect(res).toMatchSnapshot();
expect(res.packageRules).toHaveLength(3);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment