fix: public repo limit shown + branch should be preselected.
This commit is contained in:
		
							parent
							
								
									47d37c6047
								
							
						
					
					
						commit
						ba18c589f0
					
				| @ -8,6 +8,7 @@ use App\Models\GitlabApp; | ||||
| 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 @@ class PublicGitRepository extends Component | ||||
|         } | ||||
|         $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); | ||||
|         } | ||||
|  | ||||
| @ -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) | ||||
|     ]; | ||||
| } | ||||
|  | ||||
| @ -5,21 +5,21 @@ | ||||
|         <div class="flex flex-col gap-2"> | ||||
|             <div class="flex flex-col"> | ||||
|                 <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') !!}" /> | ||||
|                     <x-forms.button wire:click.prevent="load_branches"> | ||||
|                     <x-forms.button wire:click.prevent="load_branch"> | ||||
|                         Check repository | ||||
|                     </x-forms.button> | ||||
|                 </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 gap-2"> | ||||
|                             <x-forms.select id="selected_branch" label="Branch"> | ||||
|                                 <option value="default" disabled selected>Select a branch</option> | ||||
|                                 @foreach ($branches as $branch) | ||||
|                                     <option value="{{ $branch }}">{{ $branch }}</option> | ||||
|                                 @endforeach | ||||
|                             </x-forms.select> | ||||
|                             <x-forms.input disabled id="git_branch" label="Selected branch" | ||||
|                                 helper="You can select other branches after configuration is done." /> | ||||
|                             @if ($is_static) | ||||
|                                 <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." /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user