diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index 9e24ed56d..1b4a3462d 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -8,7 +8,7 @@ use App\Models\GitlabApp; use App\Models\Project; use App\Models\StandaloneDocker; use App\Models\SwarmDocker; -use Illuminate\Support\Facades\Log; +use Carbon\Carbon; use Livewire\Component; use Spatie\Url\Url; @@ -26,9 +26,9 @@ class PublicGitRepository extends Component public string $selected_branch = 'main'; public bool $is_static = false; public string|null $publish_directory = null; - public string $git_branch; + public string $git_branch = 'main'; public int $rate_limit_remaining = 0; - public int $rate_limit_reset = 0; + public $rate_limit_reset = 0; private GithubApp|GitlabApp $git_source; private string $git_host; @@ -67,6 +67,12 @@ class PublicGitRepository extends Component } $this->emit('success', 'Application settings updated!'); } + private function get_branch() + { + ['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = git_api(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}"); + $this->rate_limit_reset = Carbon::parse((int)$this->rate_limit_reset)->format('Y-M-d H:i:s.u'); + $this->branch_found = true; + } public function load_branch() { $this->branch_found = false; @@ -74,12 +80,18 @@ class PublicGitRepository extends Component 'repository_url' => 'required|url' ]); $this->get_git_source(); - try { - ['data' => $data, 'rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = git_api(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}"); - $this->branch_found = true; - } catch (\Throwable $e) { - return general_error_handler(err: $e, that: $this); + $this->get_branch(); + } catch (\Exception $e) { + } + + if (!$this->branch_found && $this->git_branch == 'main') { + try { + $this->git_branch = 'master'; + $this->get_branch(); + } catch (\Exception $e) { + return general_error_handler(err: $e, that: $this); + } } } private function get_git_source() diff --git a/bootstrap/helpers/github.php b/bootstrap/helpers/github.php index 4e4fdd7fc..8d18e6290 100644 --- a/bootstrap/helpers/github.php +++ b/bootstrap/helpers/github.php @@ -2,6 +2,7 @@ use App\Models\GithubApp; use App\Models\GitlabApp; +use Carbon\Carbon; use Illuminate\Support\Str; use Illuminate\Support\Facades\Http; use Lcobucci\JWT\Encoding\ChainedFormatter; @@ -64,7 +65,7 @@ function git_api(GithubApp|GitlabApp $source, string $endpoint, string $method = } $json = $response->json(); if ($response->failed() && $throwError) { - throw new \Exception("Failed to get data from {$source->name} with error:

" . $json['message']); + throw new \Exception("Failed to get data from {$source->name} with error:

" . $json['message'] . "

Rate Limit resets at: " . Carbon::parse((int)$response->header('X-RateLimit-Reset'))->format('Y-m-d H:i:s') . 'UTC'); } return [ 'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'), diff --git a/resources/views/livewire/project/new/public-git-repository.blade.php b/resources/views/livewire/project/new/public-git-repository.blade.php index 63cfc0f54..21af86a2e 100644 --- a/resources/views/livewire/project/new/public-git-repository.blade.php +++ b/resources/views/livewire/project/new/public-git-repository.blade.php @@ -14,7 +14,7 @@ @if ($branch_found)
Rate limit remaining: {{ $rate_limit_remaining }}
-
Rate limit reset at: {{ date('Y-m-d H:i:s', substr($rate_limit_reset, 0, 10)) }}
+
Rate limit reset at: {{ $rate_limit_reset }}