From 3c2f6a5fd63c24b98e55a98234cab4c45383d60f Mon Sep 17 00:00:00 2001 From: Duane Adam Date: Sat, 6 Dec 2025 16:35:14 +0800 Subject: [PATCH] feat: Prioritize main/master branches in branch selection dropdown Add sortBranchesByPriority() helper to sort branches with priority: main first, master second, then alphabetically. This improves UX by pre-selecting the most commonly used default branches. --- .../Project/New/GithubPrivateRepository.php | 1 + bootstrap/helpers/shared.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/Livewire/Project/New/GithubPrivateRepository.php b/app/Livewire/Project/New/GithubPrivateRepository.php index 27ecacb99..6eba4f368 100644 --- a/app/Livewire/Project/New/GithubPrivateRepository.php +++ b/app/Livewire/Project/New/GithubPrivateRepository.php @@ -138,6 +138,7 @@ public function loadBranches() $this->loadBranchByPage(); } } + $this->branches = sortBranchesByPriority($this->branches); $this->selected_branch_name = data_get($this->branches, '0.name', 'main'); } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 1066f1a63..88024e299 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -300,6 +300,24 @@ function generate_application_name(string $git_repository, string $git_branch, ? return Str::kebab("$git_repository:$git_branch-$cuid"); } +/** + * Sort branches by priority: main first, master second, then alphabetically. + * + * @param Collection $branches Collection of branch objects with 'name' key + */ +function sortBranchesByPriority(Collection $branches): Collection +{ + return $branches->sortBy(function ($branch) { + $name = data_get($branch, 'name'); + + return match ($name) { + 'main' => '0_main', + 'master' => '1_master', + default => '2_'.$name, + }; + })->values(); +} + function base_ip(): string { if (isDev()) {