2023-05-08 11:36:49 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Source\Github;
|
2023-05-08 11:36:49 +00:00
|
|
|
|
|
|
|
use App\Models\GithubApp;
|
2023-11-07 08:44:47 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2023-05-08 11:36:49 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Change extends Component
|
|
|
|
{
|
2023-06-14 07:44:40 +00:00
|
|
|
public string $webhook_endpoint;
|
2023-11-07 08:44:47 +00:00
|
|
|
public ?string $ipv4;
|
|
|
|
public ?string $ipv6;
|
|
|
|
public ?string $fqdn;
|
2023-06-14 11:07:58 +00:00
|
|
|
|
2023-11-07 08:44:47 +00:00
|
|
|
public ?bool $default_permissions = true;
|
|
|
|
public ?bool $preview_deployment_permissions = true;
|
2023-06-14 11:07:58 +00:00
|
|
|
|
2023-05-08 11:36:49 +00:00
|
|
|
public $parameters;
|
|
|
|
public GithubApp $github_app;
|
2023-05-18 11:26:35 +00:00
|
|
|
public string $name;
|
2023-05-08 11:36:49 +00:00
|
|
|
public bool $is_system_wide;
|
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'github_app.name' => 'required|string',
|
|
|
|
'github_app.organization' => 'nullable|string',
|
|
|
|
'github_app.api_url' => 'required|string',
|
|
|
|
'github_app.html_url' => 'required|string',
|
|
|
|
'github_app.custom_user' => 'required|string',
|
|
|
|
'github_app.custom_port' => 'required|int',
|
|
|
|
'github_app.app_id' => 'required|int',
|
2023-11-07 08:44:47 +00:00
|
|
|
'github_app.installation_id' => 'required|int',
|
|
|
|
'github_app.client_id' => 'required|string',
|
|
|
|
'github_app.client_secret' => 'required|string',
|
|
|
|
'github_app.webhook_secret' => 'required|string',
|
2023-05-08 11:36:49 +00:00
|
|
|
'github_app.is_system_wide' => 'required|bool',
|
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-14 07:44:40 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-11-07 08:44:47 +00:00
|
|
|
$github_app_uuid = request()->github_app_uuid;
|
|
|
|
$this->github_app = GithubApp::where('uuid', $github_app_uuid)->first();
|
|
|
|
if (!$this->github_app) {
|
2023-12-07 21:56:55 +00:00
|
|
|
return $this->redirectRoute('source.all', navigate: true);
|
2023-11-07 08:44:47 +00:00
|
|
|
}
|
|
|
|
$settings = InstanceSettings::get();
|
|
|
|
$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');
|
|
|
|
|
|
|
|
$this->name = str($this->github_app->name)->kebab();
|
|
|
|
$this->fqdn = $settings->fqdn;
|
|
|
|
|
|
|
|
if ($settings->public_ipv4) {
|
|
|
|
$this->ipv4 = 'http://' . $settings->public_ipv4 . ':' . config('app.port');
|
|
|
|
}
|
|
|
|
if ($settings->public_ipv6) {
|
|
|
|
$this->ipv6 = 'http://' . $settings->public_ipv6 . ':' . config('app.port');
|
|
|
|
}
|
|
|
|
if ($this->github_app->installation_id && session('from')) {
|
|
|
|
$source_id = data_get(session('from'), 'source_id');
|
|
|
|
if (!$source_id || $this->github_app->id !== $source_id) {
|
|
|
|
session()->forget('from');
|
|
|
|
} else {
|
|
|
|
$parameters = data_get(session('from'), 'parameters');
|
|
|
|
$back = data_get(session('from'), 'back');
|
|
|
|
$environment_name = data_get($parameters, 'environment_name');
|
|
|
|
$project_uuid = data_get($parameters, 'project_uuid');
|
|
|
|
$type = data_get($parameters, 'type');
|
|
|
|
$destination = data_get($parameters, 'destination');
|
|
|
|
session()->forget('from');
|
2023-12-07 21:56:55 +00:00
|
|
|
return $this->redirectRoute($back, [
|
2023-11-07 08:44:47 +00:00
|
|
|
'environment_name' => $environment_name,
|
|
|
|
'project_uuid' => $project_uuid,
|
|
|
|
'type' => $type,
|
|
|
|
'destination' => $destination,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->parameters = get_route_parameters();
|
2023-08-31 07:56:37 +00:00
|
|
|
if (isCloud() && !isDev()) {
|
2023-08-28 19:03:07 +00:00
|
|
|
$this->webhook_endpoint = config('app.url');
|
|
|
|
} else {
|
|
|
|
$this->webhook_endpoint = $this->ipv4;
|
|
|
|
$this->is_system_wide = $this->github_app->is_system_wide;
|
|
|
|
}
|
2023-06-14 07:44:40 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-08 11:36:49 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
2023-11-07 08:44:47 +00:00
|
|
|
$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');
|
2023-12-08 18:57:55 +00:00
|
|
|
$this->validate([
|
|
|
|
'github_app.name' => 'required|string',
|
|
|
|
'github_app.organization' => 'nullable|string',
|
|
|
|
'github_app.api_url' => 'required|string',
|
|
|
|
'github_app.html_url' => 'required|string',
|
|
|
|
'github_app.custom_user' => 'required|string',
|
|
|
|
'github_app.custom_port' => 'required|int',
|
|
|
|
'github_app.app_id' => 'required|int',
|
|
|
|
'github_app.installation_id' => 'required|int',
|
|
|
|
'github_app.client_id' => 'required|string',
|
|
|
|
'github_app.client_secret' => 'required|string',
|
|
|
|
'github_app.webhook_secret' => 'required|string',
|
|
|
|
'github_app.is_system_wide' => 'required|bool',
|
|
|
|
]);
|
2023-05-08 11:36:49 +00:00
|
|
|
$this->github_app->save();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Github App updated successfully.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
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 instantSave()
|
|
|
|
{
|
|
|
|
}
|
2023-06-14 07:44:40 +00:00
|
|
|
|
2023-05-09 08:01:57 +00:00
|
|
|
public function delete()
|
2023-05-08 11:36:49 +00:00
|
|
|
{
|
2023-05-09 08:01:57 +00:00
|
|
|
try {
|
|
|
|
$this->github_app->delete();
|
2023-12-07 21:56:55 +00:00
|
|
|
return $this->redirectRoute('source.all', navigate: true);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-08 11:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|