Skip to content
Snippets Groups Projects
Commit 74d77db6 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(internal): deduplicate updates during branchify

parent 5cfed097
No related branches found
Tags 19.213.1
No related merge requests found
...@@ -38,6 +38,33 @@ describe('workers/repository/updates/branchify', () => { ...@@ -38,6 +38,33 @@ describe('workers/repository/updates/branchify', () => {
expect(res.branches[0].isMinor).toBe(true); expect(res.branches[0].isMinor).toBe(true);
expect(res.branches[0].upgrades[0].isMinor).toBe(true); expect(res.branches[0].upgrades[0].isMinor).toBe(true);
}); });
it('deduplicates', async () => {
flattenUpdates.mockResolvedValueOnce([
{
depName: 'foo',
branchName: 'foo-{{version}}',
currentValue: '1.1.0',
newValue: '1.3.0',
prTitle: 'some-title',
updateType: 'minor',
packageFile: 'foo/package.json',
},
{
depName: 'foo',
branchName: 'foo-{{version}}',
currentValue: '1.1.0',
newValue: '1.2.0',
prTitle: 'some-title',
updateType: 'minor',
packageFile: 'foo/package.json',
},
]);
config.repoIsOnboarded = true;
const res = await branchifyUpgrades(config, {});
expect(Object.keys(res.branches)).toHaveLength(1);
expect(res.branches[0].isMinor).toBe(true);
expect(res.branches[0].upgrades[0].isMinor).toBe(true);
});
it('uses major/minor/patch slugs', async () => { it('uses major/minor/patch slugs', async () => {
flattenUpdates.mockResolvedValueOnce([ flattenUpdates.mockResolvedValueOnce([
{ {
......
...@@ -117,6 +117,39 @@ export async function branchifyUpgrades( ...@@ -117,6 +117,39 @@ export async function branchifyUpgrades(
for (const upgrade of branchUpgrades[branchName]) { for (const upgrade of branchUpgrades[branchName]) {
upgrade.logJSON = await getChangeLogJSON(upgrade); upgrade.logJSON = await getChangeLogJSON(upgrade);
} }
const seenUpdates = {};
// Filter out duplicates
branchUpgrades[branchName] = branchUpgrades[branchName].filter(
(upgrade) => {
const {
manager,
packageFile,
depName,
currentValue,
newValue,
} = upgrade;
const upgradeKey = `${packageFile}:${depName}:${currentValue}`;
const previousNewValue = seenUpdates[upgradeKey];
if (previousNewValue) {
if (previousNewValue !== newValue) {
logger.info(
{
manager,
packageFile,
depName,
currentValue,
previousNewValue,
thisNewValue: newValue,
},
'Ignoring upgrade collision'
);
}
return false;
}
seenUpdates[upgradeKey] = newValue;
return true;
}
);
const branch = generateBranchConfig(branchUpgrades[branchName]); const branch = generateBranchConfig(branchUpgrades[branchName]);
branch.branchName = branchName; branch.branchName = branchName;
branches.push(branch); branches.push(branch);
......
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