fix: public repo limit shown + branch should be preselected.

This commit is contained in:
Andras Bacsai
2023-06-28 13:37:00 +02:00
parent 47d37c6047
commit ba18c589f0
3 changed files with 19 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ use App\Models\GitlabApp;
use App\Models\Project; use App\Models\Project;
use App\Models\StandaloneDocker; use App\Models\StandaloneDocker;
use App\Models\SwarmDocker; use App\Models\SwarmDocker;
use Illuminate\Support\Facades\Log;
use Livewire\Component; use Livewire\Component;
use Spatie\Url\Url; use Spatie\Url\Url;
@@ -21,15 +22,17 @@ class PublicGitRepository extends Component
public $parameters; public $parameters;
public $query; public $query;
public $branches = []; public bool $branch_found = false;
public string $selected_branch = 'main'; public string $selected_branch = 'main';
public bool $is_static = false; public bool $is_static = false;
public string|null $publish_directory = null; 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 GithubApp|GitlabApp $git_source;
private string $git_host; private string $git_host;
private string $git_repository; private string $git_repository;
private string $git_branch;
protected $rules = [ protected $rules = [
'repository_url' => 'required|url', 'repository_url' => 'required|url',
@@ -64,16 +67,17 @@ class PublicGitRepository extends Component
} }
$this->emit('success', 'Application settings updated!'); $this->emit('success', 'Application settings updated!');
} }
public function load_branches() public function load_branch()
{ {
$this->branch_found = false;
$this->validate([ $this->validate([
'repository_url' => 'required|url' 'repository_url' => 'required|url'
]); ]);
$this->get_git_source(); $this->get_git_source();
try { try {
['data' => $data] = git_api(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches"); ['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->branches = collect($data)->pluck('name')->toArray(); $this->branch_found = true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
return general_error_handler(err: $e, that: $this); return general_error_handler(err: $e, that: $this);
} }

View File

@@ -68,6 +68,7 @@ function git_api(GithubApp|GitlabApp $source, string $endpoint, string $method =
} }
return [ return [
'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'), 'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'),
'rate_limit_reset' => $response->header('X-RateLimit-Reset'),
'data' => collect($json) 'data' => collect($json)
]; ];
} }

View File

@@ -5,21 +5,21 @@
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<div class="flex flex-col"> <div class="flex flex-col">
<div class="flex items-end gap-2"> <div class="flex items-end gap-2">
<x-forms.input wire:keydown.enter='load_branches' id="repository_url" label="Repository URL" <x-forms.input wire:keydown.enter='load_branch' id="repository_url" label="Repository URL"
helper="{!! __('repository.url') !!}" /> helper="{!! __('repository.url') !!}" />
<x-forms.button wire:click.prevent="load_branches"> <x-forms.button wire:click.prevent="load_branch">
Check repository Check repository
</x-forms.button> </x-forms.button>
</div> </div>
@if (count($branches) > 0) @if ($branch_found)
<div class="py-2">
<div>Rate limit remaining: {{ $rate_limit_remaining }}</div>
<div>Rate limit reset at: {{ date('Y-m-d H:i:s', substr($rate_limit_reset, 0, 10)) }}</div>
</div>
<div class="flex flex-col gap-2 pb-6"> <div class="flex flex-col gap-2 pb-6">
<div class="flex gap-2"> <div class="flex gap-2">
<x-forms.select id="selected_branch" label="Branch"> <x-forms.input disabled id="git_branch" label="Selected branch"
<option value="default" disabled selected>Select a branch</option> helper="You can select other branches after configuration is done." />
@foreach ($branches as $branch)
<option value="{{ $branch }}">{{ $branch }}</option>
@endforeach
</x-forms.select>
@if ($is_static) @if ($is_static)
<x-forms.input id="publish_directory" label="Publish Directory" <x-forms.input id="publish_directory" label="Publish Directory"
helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." /> helper="If there is a build process involved (like Svelte, React, Next, etc..), please specify the output directory for the build assets." />