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-08-08 09:51:36 +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-09-05 08:03:28 +00:00
|
|
|
$payload = [
|
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,
|
2023-08-22 15:44:49 +00:00
|
|
|
'team_id' => currentTeam()->id,
|
2023-09-05 08:03:28 +00:00
|
|
|
];
|
|
|
|
if (isCloud()) {
|
|
|
|
$payload['is_system_wide'] = $this->is_system_wide;
|
|
|
|
}
|
|
|
|
$github_app = GithubApp::create($payload);
|
2023-08-30 12:46:51 +00:00
|
|
|
if (session('from')) {
|
|
|
|
session(['from' => session('from') + ['source_id' => $github_app->id]]);
|
|
|
|
}
|
2023-05-09 09:33:50 +00:00
|
|
|
redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|