lasthourcloud/app/Http/Livewire/Source/Github/Create.php

51 lines
1.6 KiB
PHP
Raw Normal View History

2023-05-08 11:36:49 +00:00
<?php
2023-05-31 20:23:17 +00:00
namespace App\Http\Livewire\Source\Github;
2023-05-08 11:36:49 +00:00
use App\Models\GithubApp;
use Livewire\Component;
class Create extends Component
{
public string $name;
public string|null $organization = null;
public string $api_url = 'https://api.github.com';
public string $html_url = 'https://github.com';
public string $custom_user = 'git';
public int $custom_port = 22;
public bool $is_system_wide = false;
public function mount()
{
2023-05-24 12:26:50 +00:00
$this->name = generate_random_name();
2023-05-08 11:36:49 +00:00
}
2023-05-08 11:36:49 +00:00
public function createGitHubApp()
{
try {
$this->validate([
"name" => 'required|string',
"organization" => 'nullable|string',
"api_url" => 'required|string',
"html_url" => 'required|string',
"custom_user" => 'required|string',
"custom_port" => 'required|int',
"is_system_wide" => 'required|bool',
]);
2023-05-09 09:33:50 +00:00
$github_app = GithubApp::create([
2023-05-08 11:36:49 +00:00
'name' => $this->name,
'organization' => $this->organization,
'api_url' => $this->api_url,
'html_url' => $this->html_url,
'custom_user' => $this->custom_user,
'custom_port' => $this->custom_port,
'is_system_wide' => $this->is_system_wide,
'team_id' => session('currentTeam')->id,
]);
2023-05-09 09:33:50 +00:00
redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]);
2023-05-08 11:36:49 +00:00
} catch (\Exception $e) {
2023-06-09 13:55:21 +00:00
return general_error_handler(err: $e, that: $this);
2023-05-08 11:36:49 +00:00
}
}
}