Skip to content

Commit eefc97f

Browse files
authored
feat: prioritize main/master branch selection (#7520)
2 parents 75bf4c3 + 67c8732 commit eefc97f

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
@@ -128,6 +128,7 @@ public function loadBranches()
128128
$this->loadBranchByPage();
129129
}
130130
}
131+
$this->branches = sortBranchesByPriority($this->branches);
131132
$this->selected_branch_name = data_get($this->branches, '0.name', 'main');
132133
}
133134

bootstrap/helpers/shared.php

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

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

0 commit comments

Comments
 (0)