fix: master is the default, not main
This commit is contained in:
parent
5570cea6b1
commit
6c955424cd
@ -8,7 +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 Carbon\Carbon;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Spatie\Url\Url;
|
use Spatie\Url\Url;
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ class PublicGitRepository extends Component
|
|||||||
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 string $git_branch = 'main';
|
||||||
public int $rate_limit_remaining = 0;
|
public int $rate_limit_remaining = 0;
|
||||||
public int $rate_limit_reset = 0;
|
public $rate_limit_reset = 0;
|
||||||
|
|
||||||
private GithubApp|GitlabApp $git_source;
|
private GithubApp|GitlabApp $git_source;
|
||||||
private string $git_host;
|
private string $git_host;
|
||||||
@ -67,6 +67,12 @@ class PublicGitRepository extends Component
|
|||||||
}
|
}
|
||||||
$this->emit('success', 'Application settings updated!');
|
$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()
|
public function load_branch()
|
||||||
{
|
{
|
||||||
$this->branch_found = false;
|
$this->branch_found = false;
|
||||||
@ -74,12 +80,18 @@ class PublicGitRepository extends Component
|
|||||||
'repository_url' => 'required|url'
|
'repository_url' => 'required|url'
|
||||||
]);
|
]);
|
||||||
$this->get_git_source();
|
$this->get_git_source();
|
||||||
|
|
||||||
try {
|
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->get_branch();
|
||||||
$this->branch_found = true;
|
} catch (\Exception $e) {
|
||||||
} catch (\Throwable $e) {
|
}
|
||||||
return general_error_handler(err: $e, that: $this);
|
|
||||||
|
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()
|
private function get_git_source()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Models\GithubApp;
|
use App\Models\GithubApp;
|
||||||
use App\Models\GitlabApp;
|
use App\Models\GitlabApp;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Lcobucci\JWT\Encoding\ChainedFormatter;
|
use Lcobucci\JWT\Encoding\ChainedFormatter;
|
||||||
@ -64,7 +65,7 @@ function git_api(GithubApp|GitlabApp $source, string $endpoint, string $method =
|
|||||||
}
|
}
|
||||||
$json = $response->json();
|
$json = $response->json();
|
||||||
if ($response->failed() && $throwError) {
|
if ($response->failed() && $throwError) {
|
||||||
throw new \Exception("Failed to get data from {$source->name} with error:<br><br>" . $json['message']);
|
throw new \Exception("Failed to get data from {$source->name} with error:<br><br>" . $json['message'] . "<br><br>Rate Limit resets at: " . Carbon::parse((int)$response->header('X-RateLimit-Reset'))->format('Y-m-d H:i:s') . 'UTC');
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'),
|
'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'),
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
@if ($branch_found)
|
@if ($branch_found)
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
<div>Rate limit remaining: {{ $rate_limit_remaining }}</div>
|
<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>Rate limit reset at: {{ $rate_limit_reset }}</div>
|
||||||
</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">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user