diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php index 4f3382d51..d8d9e3ffd 100644 --- a/app/Http/Livewire/PrivateKey/Change.php +++ b/app/Http/Livewire/PrivateKey/Change.php @@ -35,7 +35,7 @@ class Change extends Component $this->private_key->save(); session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } } diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php index a3e845783..4d7836b5f 100644 --- a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php +++ b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php @@ -26,7 +26,7 @@ class All extends Component $this->application->refresh(); $this->emit('clearAddEnv'); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } } diff --git a/app/Http/Livewire/Project/Application/Storages/All.php b/app/Http/Livewire/Project/Application/Storages/All.php index 9c8e50b3a..e48111614 100644 --- a/app/Http/Livewire/Project/Application/Storages/All.php +++ b/app/Http/Livewire/Project/Application/Storages/All.php @@ -28,7 +28,7 @@ class All extends Component $this->application->refresh(); $this->emit('clearAddStorage'); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } } diff --git a/app/Http/Livewire/Project/Delete.php b/app/Http/Livewire/Project/Delete.php new file mode 100644 index 000000000..9677052eb --- /dev/null +++ b/app/Http/Livewire/Project/Delete.php @@ -0,0 +1,25 @@ +validate([ + 'project_id' => 'required|int', + ]); + $project = Project::findOrFail($this->project_id); + if ($project->applications->count() > 0) { + return $this->emit('error', 'Project has applications, please delete them first.'); + } + $project->delete(); + return redirect()->route('dashboard'); + } +} diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepository.php b/app/Http/Livewire/Project/New/GithubPrivateRepository.php index 6b46119d3..4e05636ca 100644 --- a/app/Http/Livewire/Project/New/GithubPrivateRepository.php +++ b/app/Http/Livewire/Project/New/GithubPrivateRepository.php @@ -16,6 +16,7 @@ class GithubPrivateRepository extends Component public $github_apps; public GithubApp $github_app; public $parameters; + public $type; public int $selected_repository_id; public string $selected_repository_owner; @@ -110,8 +111,16 @@ class GithubPrivateRepository extends Component public function submit() { try { - $project = Project::where('uuid', $this->parameters['project_uuid'])->first(); - $environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first(); + if ($this->type === 'project') { + $project = Project::create([ + 'name' => generateRandomName(), + 'team_id' => session('currentTeam')->id + ]); + $environment = $project->load(['environments'])->environments->first(); + } else { + $project = Project::where('uuid', $this->parameters['project_uuid'])->first(); + $environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first(); + } $application = Application::create([ 'name' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}:{$this->selected_branch_name}", 'git_repository' => "{$this->selected_repository_owner}/{$this->selected_repository_repo}", @@ -130,7 +139,7 @@ class GithubPrivateRepository extends Component 'environment_name' => $environment->name ]); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } public function mount() diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index c0eba0503..923006789 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -54,7 +54,7 @@ class Form extends Component $this->dockerComposeVersion = 'Not installed.'; } } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } public function delete() diff --git a/app/Http/Livewire/Source/Create.php b/app/Http/Livewire/Source/Create.php index a36c63301..f7f09bba7 100644 --- a/app/Http/Livewire/Source/Create.php +++ b/app/Http/Livewire/Source/Create.php @@ -31,7 +31,7 @@ class Create extends Component "custom_port" => 'required|int', "is_system_wide" => 'required|bool', ]); - GithubApp::create([ + $github_app = GithubApp::create([ 'name' => $this->name, 'organization' => $this->organization, 'api_url' => $this->api_url, @@ -41,8 +41,9 @@ class Create extends Component 'is_system_wide' => $this->is_system_wide, 'team_id' => session('currentTeam')->id, ]); + redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } } diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php index f7267d80b..ad4a9b0c9 100644 --- a/app/Http/Livewire/Source/Github/Change.php +++ b/app/Http/Livewire/Source/Github/Change.php @@ -36,7 +36,7 @@ class Change extends Component $this->validate(); $this->github_app->save(); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } public function instantSave() @@ -46,7 +46,7 @@ class Change extends Component $this->github_app->save(); $this->emit('saved', 'GitHub settings updated!'); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } public function mount() @@ -64,7 +64,7 @@ class Change extends Component $this->github_app->delete(); redirect()->route('dashboard'); } catch (\Exception $e) { - return generalErrorHandlerLivewire($e, $this); + return generalErrorHandler($e, $this); } } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index bd2368a5a..0c4bfec72 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -31,6 +31,9 @@ class RouteServiceProvider extends ServiceProvider ->prefix('api') ->group(base_path('routes/api.php')); + Route::prefix('webhooks') + ->group(base_path('routes/webhooks.php')); + Route::middleware('web') ->group(base_path('routes/web.php')); }); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 0cc76a5c4..f7796bd47 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -14,19 +14,23 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Storage; use Spatie\Activitylog\Contracts\Activity; -if (!function_exists('generalErrorHandlerLivewire')) { - function generalErrorHandlerLivewire(\Throwable $e, $that) +if (!function_exists('generalErrorHandler')) { + function generalErrorHandler(\Throwable $e, $that = null) { - if ($e instanceof QueryException) { - if ($e->errorInfo[0] === '23505') { - $that->emit('error', 'Duplicate entry found.'); - } else if (count($e->errorInfo) === 4) { - $that->emit('error', $e->errorInfo[3]); + if ($that) { + if ($e instanceof QueryException) { + if ($e->errorInfo[0] === '23505') { + $that->emit('error', 'Duplicate entry found.'); + } else if (count($e->errorInfo) === 4) { + $that->emit('error', $e->errorInfo[3]); + } else { + $that->emit('error', $e->errorInfo[2]); + } } else { - $that->emit('error', $e->errorInfo[2]); + $that->emit('error', $e->getMessage()); } } else { - $that->emit('error', $e); + dump($e); } } } diff --git a/resources/views/components/inputs/button.blade.php b/resources/views/components/inputs/button.blade.php index 8b9e5cd61..db2314256 100644 --- a/resources/views/components/inputs/button.blade.php +++ b/resources/views/components/inputs/button.blade.php @@ -1,19 +1,25 @@ @props([ 'isWarning' => null, + 'disabled' => null, 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 h-8', 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 h-8', + 'disabledClass' => 'text-neutral-400 bg-neutral-900 h-8', 'loadingClass' => 'text-black bg-green-500 h-8', 'confirm' => null, 'confirmAction' => null, ])