fix: master is the default, not main

This commit is contained in:
Andras Bacsai 2023-07-11 11:11:51 +02:00
parent 5570cea6b1
commit 6c955424cd
3 changed files with 23 additions and 10 deletions

View File

@ -8,7 +8,7 @@
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 @@ public function instantSave()
}
$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 @@ public function load_branch()
'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()

View File

@ -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:<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 [
'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'),

View File

@ -14,7 +14,7 @@
@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>Rate limit reset at: {{ $rate_limit_reset }}</div>
</div>
<div class="flex flex-col gap-2 pb-6">
<div class="flex gap-2">