feat(SourceManagement): add functionality to change Git source and display current source in the application settings

This commit is contained in:
Andras Bacsai
2025-04-11 18:22:42 +02:00
parent 4c8ebe146c
commit ec36825545
2 changed files with 58 additions and 0 deletions

View File

@@ -30,11 +30,15 @@ class Source extends Component
#[Validate(['nullable', 'string'])] #[Validate(['nullable', 'string'])]
public ?string $gitCommitSha = null; public ?string $gitCommitSha = null;
#[Locked]
public $sources;
public function mount() public function mount()
{ {
try { try {
$this->syncData(); $this->syncData();
$this->getPrivateKeys(); $this->getPrivateKeys();
$this->getSources();
} catch (\Throwable $e) { } catch (\Throwable $e) {
handleError($e, $this); 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) public function setPrivateKey(int $privateKeyId)
{ {
try { try {
@@ -92,4 +104,18 @@ class Source extends Component
return handleError($e, $this); 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);
}
}
} }

View File

@@ -26,6 +26,9 @@
<div class="pb-4">Code source of your application.</div> <div class="pb-4">Code source of your application.</div>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<div>Currently connected source: <span
class="font-bold text-warning">{{ $application->source->name }}</span>
</div>
<div class="flex gap-2"> <div class="flex gap-2">
<x-forms.input placeholder="coollabsio/coolify-example" id="gitRepository" label="Repository" /> <x-forms.input placeholder="coollabsio/coolify-example" id="gitRepository" label="Repository" />
<x-forms.input placeholder="main" id="gitBranch" label="Branch" /> <x-forms.input placeholder="main" id="gitBranch" label="Branch" />
@@ -34,6 +37,35 @@
<x-forms.input placeholder="HEAD" id="gitCommitSha" placeholder="HEAD" label="Commit SHA" /> <x-forms.input placeholder="HEAD" id="gitCommitSha" placeholder="HEAD" label="Commit SHA" />
</div> </div>
</div> </div>
@if (filled($sources) && $sources->count() > 0)
<div class="pt-4">
<h3 class="pb-2">Change Git Source</h3>
<div class="grid grid-cols-1 gap-2">
@foreach ($sources as $source)
<x-modal-confirmation title="Change Git Source" :actions="['Change git source to ' . $source->name]" :buttonFullWidth="true"
:isHighlightedButton="$application->source_id === $source->id" :disabled="$application->source_id === $source->id"
submitAction="changeSource('{{ $source->id }}', '{{ $source->getMorphClass() }}')"
:confirmWithText="true" confirmationText="Change Git Source"
confirmationLabel="Please confirm changing the git source by entering the text below"
shortConfirmationLabel="Confirmation Text" :confirmWithPassword="false">
<x-slot:customButton>
<div class="box-title">
{{ $source->name }}
@if ($application->source_id === $source->id)
<span class="text-xs">(current)</span>
@endif
</div>
<div class="box-description">
{{ $source->organization_name ?? 'Personal Account' }}
</div>
</x-slot:customButton>
</x-modal-confirmation>
@endforeach
</div>
</div>
@endif
@if ($privateKeyId) @if ($privateKeyId)
<h3 class="pt-4">Deploy Key</h3> <h3 class="pt-4">Deploy Key</h3>
<div class="py-2 pt-4">Currently attached Private Key: <span <div class="py-2 pt-4">Currently attached Private Key: <span