wip button to sync new app name

This commit is contained in:
peaklabs-dev
2024-12-03 13:12:58 +01:00
parent f38196c421
commit 737e81aa38
2 changed files with 16 additions and 5 deletions

View File

@@ -154,16 +154,26 @@ class Change extends Component
$github_access_token = generate_github_installation_token($this->github_app); $github_access_token = generate_github_installation_token($this->github_app);
$response = Http::withToken($github_access_token) $response = Http::withToken($github_access_token)
->get("{$this->github_app->api_url}/app"); ->withHeaders([
'Accept' => 'application/vnd.github+json',
'X-GitHub-Api-Version' => '2022-11-28',
])
->get("{$this->github_app->api_url}/installation/repositories");
if ($response->successful()) { if ($response->successful()) {
$app_data = $response->json(); $app_data = $response->json();
if ($app_data['name'] !== $this->github_app->name) { $app_name = data_get($app_data, 'installation.app_slug');
$this->github_app->name = $app_data['name'];
if ($app_name && $app_name !== $this->github_app->name) {
$this->github_app->name = $app_name;
$this->name = str($app_name)->kebab();
$this->github_app->save(); $this->github_app->save();
$this->name = str($this->github_app->name)->kebab(); $this->dispatch('success', 'Github App name synchronized successfully.');
$this->dispatch('success', 'Github App name synchronized.'); } else {
$this->dispatch('info', 'Github App name is already up to date.');
} }
} else {
$this->dispatch('error', 'Failed to fetch Github App information. Status: '.$response->status());
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);

View File

@@ -60,6 +60,7 @@
<div class="flex gap-2"> <div class="flex gap-2">
<div class="flex items-end gap-2 w-full"> <div class="flex items-end gap-2 w-full">
<x-forms.input id="github_app.name" label="App Name" disabled /> <x-forms.input id="github_app.name" label="App Name" disabled />
<x-forms.button wire:click.prevent="syncGithubAppName">Sync Name</x-forms.button>
<a href="{{ $this->getUpdatePath() }}"> <a href="{{ $this->getUpdatePath() }}">
<x-forms.button> <x-forms.button>
Update Update