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:

  1. Fixed API sorting bug: Client-side sorting in internal/api/merge_request.go was unconditionally sorting by CreatedAt, overriding the API's OrderBy parameter. Now it only sorts by CreatedAt when no OrderBy is specified, allowing API sorting to work correctly.

  2. Enabled label_priority for project-level MRs: Removed incorrect validation that required the --group flag for label_priority ordering. The GitLab API supports this for both project and group-level MR endpoints.

  3. Added intuitive default sorting: When using --order label_priority without explicit --sort, it now defaults to asc (ascending), showing highest priority labels first. Users can still explicitly specify --sort desc for reverse order.

  4. 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?

  1. Manual API testing: Verified that GitLab API supports order_by=label_priority for both project and group endpoints using glab api
  2. Unit tests: All existing tests pass, including the mr list test suite
  3. 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 --sort desc still works
  • Verified other order options (updated_at, created_at, etc.) still work correctly
  • Tested with milestone filters and other flags in combination
  1. Edge cases:
  • MRs without priority labels sort last (as expected)
  • Empty assignee/reviewer lists don't trigger incorrect sorting
  • Both -R project/repo and --group group work correctly.

Merge request reports

Loading