fix(mr): enable label priority ordering for project and group MRs
Description
This MR fixes and enhances label priority ordering for merge requests in the glab mr list command.
Changes:
-
Fixed API sorting bug: Client-side sorting in
internal/api/merge_request.gowas unconditionally sorting byCreatedAt, overriding the API'sOrderByparameter. Now it only sorts byCreatedAtwhen noOrderByis specified, allowing API sorting to work correctly. -
Enabled label_priority for project-level MRs: Removed incorrect validation that required the
--groupflag forlabel_priorityordering. The GitLab API supports this for both project and group-level MR endpoints. -
Added intuitive default sorting: When using
--order label_prioritywithout explicit--sort, it now defaults toasc(ascending), showing highest priority labels first. Users can still explicitly specify--sort descfor reverse order. -
Updated documentation: Help text now lists all available order options (created_at, label_priority, milestone_due, popularity, priority, title, updated_at, merged_at) without the incorrect "For groups:" distinction.
Before:
# Required --group flag (incorrect)
glab mr list --order label_priority # Error
# Without --sort, showed lowest priority first (counterintuitive)
glab mr list --group mygroup --order label_priority
After:
# Works for both projects and groups
glab mr list -R project/repo --order label_priority
glab mr list --group mygroup --order label_priority
# Can still explicitly use desc
glab mr list --order label_priority --sort desc
How has this been tested?
- Manual API testing: Verified that GitLab API supports order_by=label_priority for both project and group endpoints using glab api
- Unit tests: All existing tests pass, including the mr list test suite
- Integration testing:
- Tested with mayachain/mayanode project containing MRs with various priority labels (critical, need, want, nice to)
- Verified default behavior shows highest priority first
- Verified explicit
--sortdesc still works - Verified other order options (updated_at, created_at, etc.) still work correctly
- Tested with milestone filters and other flags in combination
- Edge cases:
- MRs without priority labels sort last (as expected)
- Empty assignee/reviewer lists don't trigger incorrect sorting
- Both
-Rproject/repo and--groupgroup work correctly.