diff --git a/app/Livewire/Project/Shared/Webhooks.php b/app/Livewire/Project/Shared/Webhooks.php index e96bd888e..40e7cdd49 100644 --- a/app/Livewire/Project/Shared/Webhooks.php +++ b/app/Livewire/Project/Shared/Webhooks.php @@ -4,49 +4,59 @@ use Livewire\Component; +// Refactored ✅ class Webhooks extends Component { public $resource; - public ?string $deploywebhook = null; + public string $deploywebhook; - public ?string $githubManualWebhook = null; + public string $githubManualWebhook; - public ?string $gitlabManualWebhook = null; + public string $gitlabManualWebhook; - public ?string $bitbucketManualWebhook = null; + public string $bitbucketManualWebhook; - public ?string $giteaManualWebhook = null; + public string $giteaManualWebhook; - protected $rules = [ - 'resource.manual_webhook_secret_github' => 'nullable|string', - 'resource.manual_webhook_secret_gitlab' => 'nullable|string', - 'resource.manual_webhook_secret_bitbucket' => 'nullable|string', - 'resource.manual_webhook_secret_gitea' => 'nullable|string', - ]; + public ?string $githubManualWebhookSecret = null; - public function saveSecret() + public ?string $gitlabManualWebhookSecret = null; + + public ?string $bitbucketManualWebhookSecret = null; + + public ?string $giteaManualWebhookSecret = null; + + public function mount() + { + $this->deploywebhook = generateDeployWebhook($this->resource); + + $this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github'); + $this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github'); + + $this->gitlabManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitlab'); + $this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab'); + + $this->bitbucketManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_bitbucket'); + $this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket'); + + $this->giteaManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitea'); + $this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea'); + } + + public function submit() { try { - $this->validate(); - $this->resource->save(); + $this->authorize('update', $this->resource); + $this->resource->update([ + 'manual_webhook_secret_github' => $this->githubManualWebhookSecret, + 'manual_webhook_secret_gitlab' => $this->gitlabManualWebhookSecret, + 'manual_webhook_secret_bitbucket' => $this->bitbucketManualWebhookSecret, + 'manual_webhook_secret_gitea' => $this->giteaManualWebhookSecret, + ]); $this->dispatch('success', 'Secret Saved.'); } catch (\Exception $e) { return handleError($e, $this); } } - - public function mount() - { - $this->deploywebhook = generateDeployWebhook($this->resource); - $this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github'); - $this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab'); - $this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket'); - $this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea'); - } - - public function render() - { - return view('livewire.project.shared.webhooks'); - } } diff --git a/resources/views/livewire/project/shared/webhooks.blade.php b/resources/views/livewire/project/shared/webhooks.blade.php index 9390082c9..6b9e1c86d 100644 --- a/resources/views/livewire/project/shared/webhooks.blade.php +++ b/resources/views/livewire/project/shared/webhooks.blade.php @@ -13,13 +13,13 @@

Manual Git Webhooks

@if ($githubManualWebhook && $gitlabManualWebhook) -
+
+ label="GitHub Webhook Secret" id="githubManualWebhookSecret">
@@ -31,21 +31,19 @@ + label="GitLab Webhook Secret" id="gitlabManualWebhookSecret">
+ label="Bitbucket Webhook Secret" id="bitbucketManualWebhookSecret">
+ label="Gitea Webhook Secret" id="giteaManualWebhookSecret">
Save