Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prPriority based sorting of prs #29306

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}