Skip to content

Commit

Permalink
fix: prPriority based sorting of prs (#29306)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed May 29, 2024
1 parent 6dd189e commit 9e2ca6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/workers/repository/process/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
]);
Expand Down
9 changes: 7 additions & 2 deletions lib/workers/repository/process/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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;
}

0 comments on commit 9e2ca6b

Please sign in to comment.