[go: up one dir, main page]

Add default branch to top results for branch rules pagination

What does this MR do and why?

The branch rules finder currently returns the sort order:

  • All branches
  • All protected branches
  • Everything else alphabetically sorted

But it should have the sort order:

  • All branches
  • All protected branches
  • Default branch
  • Everything else alphabetically sorted

This MR adds the default branch to the top of the returned protected branches.

Query

scope :excluding_name, ->(name) { where.not(name: name) if name.present? }

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46478/commands/141764

SELECT "protected_branches".* FROM "protected_branches" 
WHERE "protected_branches"."project_id" = 278964 
AND "protected_branches"."name" != 'master'

References

See #576206 (comment 2949957056)

Screenshots or screen recordings

before after
Screenshot_2025-12-15_at_14.24.59 Screenshot_2025-12-15_at_14.24.11

How to set up and validate locally

  1. Create a test project with multiple protected branches (e.g., 'a', 'b', 'c', 'main')
  2. Ensure 'main' is set as the default branch for the project
  3. Create protected branch rule for each branch
  4. Navigate to the project's branch rules page: http://gdk.test:3000/[namespace]/[project]/-/settings/repository#branch-rules
  5. Verify the sort order is:
    • All branches rule
    • All protected branches rule
    • Default branch (main) rule
    • Other branches in alphabetical order (a, b, c)
  6. Paginate through results and verify the default branch only appears on the first page
  7. Verify later pages exclude the default branch and show remaining branches in order

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Gavin Hinfey

Merge request reports

Loading