From ec368255458f11f29adc157317384f611556170a Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Fri, 11 Apr 2025 18:22:42 +0200 Subject: [PATCH] feat(SourceManagement): add functionality to change Git source and display current source in the application settings --- app/Livewire/Project/Application/Source.php | 26 +++++++++++++++ .../project/application/source.blade.php | 32 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/app/Livewire/Project/Application/Source.php b/app/Livewire/Project/Application/Source.php index ade297d50..3afdbe075 100644 --- a/app/Livewire/Project/Application/Source.php +++ b/app/Livewire/Project/Application/Source.php @@ -30,11 +30,15 @@ class Source extends Component #[Validate(['nullable', 'string'])] public ?string $gitCommitSha = null; + #[Locked] + public $sources; + public function mount() { try { $this->syncData(); $this->getPrivateKeys(); + $this->getSources(); } catch (\Throwable $e) { handleError($e, $this); } @@ -66,6 +70,14 @@ class Source extends Component }); } + private function getSources() + { + // filter the current source out + $this->sources = currentTeam()->sources()->whereNotNull('app_id')->reject(function ($source) { + return $source->id === $this->application->source_id; + }); + } + public function setPrivateKey(int $privateKeyId) { try { @@ -92,4 +104,18 @@ class Source extends Component return handleError($e, $this); } } + + public function changeSource($sourceId, $sourceType) + { + try { + $this->application->update([ + 'source_id' => $sourceId, + 'source_type' => $sourceType, + ]); + $this->application->refresh(); + $this->dispatch('success', 'Source updated!'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } } diff --git a/resources/views/livewire/project/application/source.blade.php b/resources/views/livewire/project/application/source.blade.php index b542d5428..a32742a01 100644 --- a/resources/views/livewire/project/application/source.blade.php +++ b/resources/views/livewire/project/application/source.blade.php @@ -26,6 +26,9 @@
Code source of your application.
+
Currently connected source: {{ $application->source->name }} +
@@ -34,6 +37,35 @@
+ + @if (filled($sources) && $sources->count() > 0) +
+

Change Git Source

+
+ @foreach ($sources as $source) + + +
+ {{ $source->name }} + @if ($application->source_id === $source->id) + (current) + @endif +
+
+ {{ $source->organization_name ?? 'Personal Account' }} +
+
+
+ @endforeach +
+
+ @endif + @if ($privateKeyId)

Deploy Key

Currently attached Private Key: