From f38196c4213e1358d89c35c66f4c3b4f8ba6e258 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:54:20 +0100 Subject: [PATCH] fix: URL and sync new app name --- app/Livewire/Source/Github/Change.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Source/Github/Change.php b/app/Livewire/Source/Github/Change.php index 79cc02219..5d57ecf1e 100644 --- a/app/Livewire/Source/Github/Change.php +++ b/app/Livewire/Source/Github/Change.php @@ -4,6 +4,7 @@ namespace App\Livewire\Source\Github; use App\Jobs\GithubAppPermissionJob; use App\Models\GithubApp; +use Illuminate\Support\Facades\Http; use Livewire\Component; class Change extends Component @@ -144,7 +145,29 @@ class Change extends Component public function getUpdatePath() { - return "{$this->github_app->html_url}/settings/apps/{$this->github_app->app_id}"; + return "{$this->github_app->html_url}/settings/apps/{$this->github_app->name}"; + } + + public function syncGithubAppName() + { + try { + $github_access_token = generate_github_installation_token($this->github_app); + + $response = Http::withToken($github_access_token) + ->get("{$this->github_app->api_url}/app"); + + if ($response->successful()) { + $app_data = $response->json(); + if ($app_data['name'] !== $this->github_app->name) { + $this->github_app->name = $app_data['name']; + $this->github_app->save(); + $this->name = str($this->github_app->name)->kebab(); + $this->dispatch('success', 'Github App name synchronized.'); + } + } + } catch (\Throwable $e) { + return handleError($e, $this); + } } public function submit()