Skip to content

Commit 3c2f6a5

Browse files
committed
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.
1 parent a528f4c commit 3c2f6a5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/Livewire/Project/New/GithubPrivateRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public function loadBranches()
138138
$this->loadBranchByPage();
139139
}
140140
}
141+
$this->branches = sortBranchesByPriority($this->branches);
141142
$this->selected_branch_name = data_get($this->branches, '0.name', 'main');
142143
}
143144

bootstrap/helpers/shared.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,24 @@ function generate_application_name(string $git_repository, string $git_branch, ?
300300
return Str::kebab("$git_repository:$git_branch-$cuid");
301301
}
302302

303+
/**
304+
* Sort branches by priority: main first, master second, then alphabetically.
305+
*
306+
* @param Collection $branches Collection of branch objects with 'name' key
307+
*/
308+
function sortBranchesByPriority(Collection $branches): Collection
309+
{
310+
return $branches->sortBy(function ($branch) {
311+
$name = data_get($branch, 'name');
312+
313+
return match ($name) {
314+
'main' => '0_main',
315+
'master' => '1_master',
316+
default => '2_'.$name,
317+
};
318+
})->values();
319+
}
320+
303321
function base_ip(): string
304322
{
305323
if (isDev()) {

0 commit comments

Comments
 (0)