fix: prPriority based sorting of prs (#29306)

This commit is contained in:
RahulGautamSingh 2024-05-29 12:55:33 +05:45 committed by GitHub
parent 6dd189e3a6
commit 9e2ca6b152
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -58,11 +58,16 @@ describe('workers/repository/process/sort', () => {
prTitle: 'a minor update',
prPriority: -1,
},
{
updateType: 'patch' as UpdateType,
prTitle: 'a patch update',
},
];
sortBranches(branches);
expect(branches).toEqual([
{ prPriority: 1, prTitle: 'some major update', updateType: 'major' },
{ prPriority: 0, prTitle: 'some other pin', updateType: 'pin' },
{ prTitle: 'a patch update', updateType: 'patch' },
{ prPriority: -1, prTitle: 'some pin', updateType: 'pin' },
{ prPriority: -1, prTitle: 'a minor update', updateType: 'minor' },
]);

View file

@ -21,8 +21,9 @@ export function sortBranches(branches: Partial<BranchConfig>[]): void {
}
// TODO #22198
if (a.prPriority !== b.prPriority) {
return b.prPriority! - a.prPriority!;
const prPriorityDiff = getPrPriority(b) - getPrPriority(a);
if (prPriorityDiff !== 0) {
return prPriorityDiff;
}
// TODO #22198
const sortDiff =
@ -35,3 +36,7 @@ export function sortBranches(branches: Partial<BranchConfig>[]): void {
return a.prTitle! < b.prTitle! ? -1 : 1;
});
}
function getPrPriority(branch: Partial<BranchConfig>): number {
return branch.prPriority ?? 0;
}