fix(workers): guarantee symmetric result from sort branch predicate (#18275)

This commit is contained in:
George Georgiev 2022-10-13 20:54:35 -07:00 committed by GitHub
parent 61f8c9895f
commit e6c43aae81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View file

@ -100,5 +100,43 @@ describe('workers/repository/process/sort', () => {
{ prPriority: -1, prTitle: 'some pin', updateType: 'pin' },
]);
});
it('sorts based on isVulnerabilityAlert symmetric', () => {
const branches = [
{
updateType: 'minor' as UpdateType,
prTitle: 'a minor update',
prPriority: -1,
isVulnerabilityAlert: true,
},
{
updateType: 'major' as UpdateType,
prTitle: 'some major update',
prPriority: 1,
},
{
updateType: 'pin' as UpdateType,
prTitle: 'some pin',
prPriority: -1,
},
{
updateType: 'pin' as UpdateType,
prTitle: 'some other pin',
prPriority: 0,
},
];
sortBranches(branches);
expect(branches).toEqual([
{
isVulnerabilityAlert: true,
prPriority: -1,
prTitle: 'a minor update',
updateType: 'minor',
},
{ prPriority: 1, prTitle: 'some major update', updateType: 'major' },
{ prPriority: 0, prTitle: 'some other pin', updateType: 'pin' },
{ prPriority: -1, prTitle: 'some pin', updateType: 'pin' },
]);
});
});
});

View file

@ -16,6 +16,10 @@ export function sortBranches(branches: Partial<BranchConfig>[]): void {
if (a.isVulnerabilityAlert && !b.isVulnerabilityAlert) {
return -1;
}
if (!a.isVulnerabilityAlert && b.isVulnerabilityAlert) {
return 1;
}
// TODO #7154
if (a.prPriority !== b.prPriority) {
return b.prPriority! - a.prPriority!;