From ba18c589f0749843cbf40dc8775c0e36846c2e0f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 28 Jun 2023 13:37:00 +0200 Subject: [PATCH] fix: public repo limit shown + branch should be preselected. --- .../Project/New/PublicGitRepository.php | 14 +++++++++----- bootstrap/helpers/github.php | 1 + .../new/public-git-repository.blade.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index 05793695e..9e24ed56d 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -8,6 +8,7 @@ use App\Models\Project; use App\Models\StandaloneDocker; use App\Models\SwarmDocker; +use Illuminate\Support\Facades\Log; use Livewire\Component; use Spatie\Url\Url; @@ -21,15 +22,17 @@ class PublicGitRepository extends Component public $parameters; public $query; - public $branches = []; + public bool $branch_found = false; public string $selected_branch = 'main'; public bool $is_static = false; public string|null $publish_directory = null; + public string $git_branch; + public int $rate_limit_remaining = 0; + public int $rate_limit_reset = 0; private GithubApp|GitlabApp $git_source; private string $git_host; private string $git_repository; - private string $git_branch; protected $rules = [ 'repository_url' => 'required|url', @@ -64,16 +67,17 @@ public function instantSave() } $this->emit('success', 'Application settings updated!'); } - public function load_branches() + public function load_branch() { + $this->branch_found = false; $this->validate([ 'repository_url' => 'required|url' ]); $this->get_git_source(); try { - ['data' => $data] = git_api(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches"); - $this->branches = collect($data)->pluck('name')->toArray(); + ['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); } diff --git a/bootstrap/helpers/github.php b/bootstrap/helpers/github.php index f282ee6f1..53a0f52fb 100644 --- a/bootstrap/helpers/github.php +++ b/bootstrap/helpers/github.php @@ -68,6 +68,7 @@ function git_api(GithubApp|GitlabApp $source, string $endpoint, string $method = } return [ 'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'), + 'rate_limit_reset' => $response->header('X-RateLimit-Reset'), 'data' => collect($json) ]; } 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 53ef8bbd0..63cfc0f54 100644 --- a/resources/views/livewire/project/new/public-git-repository.blade.php +++ b/resources/views/livewire/project/new/public-git-repository.blade.php @@ -5,21 +5,21 @@
- - + Check repository
- @if (count($branches) > 0) + @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)) }}
+
- - - @foreach ($branches as $branch) - - @endforeach - + @if ($is_static)