lasthourcloud/app/Livewire/Project/Shared/Webhooks.php

65 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Shared;
use Livewire\Component;
2024-07-12 09:52:32 +00:00
// Refactored ✅
class Webhooks extends Component
{
public $resource;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public string $deploywebhook;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public string $githubManualWebhook;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public string $gitlabManualWebhook;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public string $bitbucketManualWebhook;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public string $giteaManualWebhook;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public ?string $githubManualWebhookSecret = null;
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public ?string $gitlabManualWebhookSecret = null;
public ?string $bitbucketManualWebhookSecret = null;
public ?string $giteaManualWebhookSecret = null;
2024-06-10 20:43:34 +00:00
public function mount()
{
// ray()->clearAll();
// ray()->showQueries();
$this->deploywebhook = generateDeployWebhook($this->resource);
2024-07-12 09:52:32 +00:00
$this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github');
$this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github');
2024-07-12 09:52:32 +00:00
$this->gitlabManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitlab');
$this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab');
2024-07-12 09:52:32 +00:00
$this->bitbucketManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_bitbucket');
$this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket');
2024-07-12 09:52:32 +00:00
$this->giteaManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitea');
2024-05-23 09:30:18 +00:00
$this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea');
}
2024-06-10 20:43:34 +00:00
2024-07-12 09:52:32 +00:00
public function submit()
{
2024-07-12 09:52:32 +00:00
try {
$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);
}
}
}