|
4 | 4 |
|
5 | 5 | use Livewire\Component;
|
6 | 6 |
|
| 7 | +// Refactored ✅ |
7 | 8 | class Webhooks extends Component
|
8 | 9 | {
|
9 | 10 | public $resource;
|
10 | 11 |
|
11 |
| - public ?string $deploywebhook = null; |
| 12 | + public string $deploywebhook; |
12 | 13 |
|
13 |
| - public ?string $githubManualWebhook = null; |
| 14 | + public string $githubManualWebhook; |
14 | 15 |
|
15 |
| - public ?string $gitlabManualWebhook = null; |
| 16 | + public string $gitlabManualWebhook; |
16 | 17 |
|
17 |
| - public ?string $bitbucketManualWebhook = null; |
| 18 | + public string $bitbucketManualWebhook; |
18 | 19 |
|
19 |
| - public ?string $giteaManualWebhook = null; |
| 20 | + public string $giteaManualWebhook; |
20 | 21 |
|
21 |
| - protected $rules = [ |
22 |
| - 'resource.manual_webhook_secret_github' => 'nullable|string', |
23 |
| - 'resource.manual_webhook_secret_gitlab' => 'nullable|string', |
24 |
| - 'resource.manual_webhook_secret_bitbucket' => 'nullable|string', |
25 |
| - 'resource.manual_webhook_secret_gitea' => 'nullable|string', |
26 |
| - ]; |
| 22 | + public ?string $githubManualWebhookSecret = null; |
27 | 23 |
|
28 |
| - public function saveSecret() |
29 |
| - { |
30 |
| - try { |
31 |
| - $this->validate(); |
32 |
| - $this->resource->save(); |
33 |
| - $this->dispatch('success', 'Secret Saved.'); |
34 |
| - } catch (\Exception $e) { |
35 |
| - return handleError($e, $this); |
36 |
| - } |
37 |
| - } |
| 24 | + public ?string $gitlabManualWebhookSecret = null; |
| 25 | + |
| 26 | + public ?string $bitbucketManualWebhookSecret = null; |
| 27 | + |
| 28 | + public ?string $giteaManualWebhookSecret = null; |
38 | 29 |
|
39 | 30 | public function mount()
|
40 | 31 | {
|
41 | 32 | $this->deploywebhook = generateDeployWebhook($this->resource);
|
| 33 | + |
| 34 | + $this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github'); |
42 | 35 | $this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github');
|
| 36 | + |
| 37 | + $this->gitlabManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitlab'); |
43 | 38 | $this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab');
|
| 39 | + |
| 40 | + $this->bitbucketManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_bitbucket'); |
44 | 41 | $this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket');
|
| 42 | + |
| 43 | + $this->giteaManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitea'); |
45 | 44 | $this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea');
|
46 | 45 | }
|
47 | 46 |
|
48 |
| - public function render() |
| 47 | + public function submit() |
49 | 48 | {
|
50 |
| - return view('livewire.project.shared.webhooks'); |
| 49 | + try { |
| 50 | + $this->authorize('update', $this->resource); |
| 51 | + $this->resource->update([ |
| 52 | + 'manual_webhook_secret_github' => $this->githubManualWebhookSecret, |
| 53 | + 'manual_webhook_secret_gitlab' => $this->gitlabManualWebhookSecret, |
| 54 | + 'manual_webhook_secret_bitbucket' => $this->bitbucketManualWebhookSecret, |
| 55 | + 'manual_webhook_secret_gitea' => $this->giteaManualWebhookSecret, |
| 56 | + ]); |
| 57 | + $this->dispatch('success', 'Secret Saved.'); |
| 58 | + } catch (\Exception $e) { |
| 59 | + return handleError($e, $this); |
| 60 | + } |
51 | 61 | }
|
52 | 62 | }
|
0 commit comments