From 8e0a2cdc0b00274d3fda4d4b65e53a20df1b8f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucian=20V=C4=83c=C4=83roiu?= Date: Sun, 16 Nov 2025 17:26:45 +0200 Subject: [PATCH 1/3] refactor(site): make repo and branch required in SiteDTO Remove isLocal() method and make repo/branch properties required strings. Update SiteRepository to always store and load repo/branch data. --- app/DTOs/SiteDTO.php | 16 ++++------------ app/Repositories/SiteRepository.php | 24 +++++++++--------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/app/DTOs/SiteDTO.php b/app/DTOs/SiteDTO.php index dc9bd797..236efe90 100644 --- a/app/DTOs/SiteDTO.php +++ b/app/DTOs/SiteDTO.php @@ -10,23 +10,15 @@ * Create a SiteDTO containing the site's domain, repository, branch, and associated servers. * * @param string $domain The site's domain name (e.g. example.com). - * @param string|null $repo The repository URL for git sites, null for local sites. - * @param string|null $branch The repository branch for git sites (e.g. main), null for local sites. + * @param string $repo The repository URL for git sites. + * @param string $branch The repository branch for git sites (e.g. main). * @param array $servers Ordered list of server hostnames or addresses associated with the site. */ public function __construct( public string $domain, - public ?string $repo, - public ?string $branch, + public string $repo, + public string $branch, public array $servers, ) { } - - /** - * Check if this is a local site (no git repository). - */ - public function isLocal(): bool - { - return $this->repo === null; - } } diff --git a/app/Repositories/SiteRepository.php b/app/Repositories/SiteRepository.php index 31425af3..0a0e6001 100644 --- a/app/Repositories/SiteRepository.php +++ b/app/Repositories/SiteRepository.php @@ -167,41 +167,35 @@ private function assertInventoryLoaded(): void * Serialize a SiteDTO into an associative array suitable for inventory storage. * * @param SiteDTO $site The site DTO to serialize. - * @return array Associative array with keys `domain`, `servers`, and optionally `repo`/`branch` for git sites. + * @return array Associative array with keys `domain`, `repo`, `branch`, and `servers`. */ private function dehydrateSiteDTO(SiteDTO $site): array { - $data = [ + return [ 'domain' => $site->domain, + 'repo' => $site->repo, + 'branch' => $site->branch, 'servers' => $site->servers, ]; - - // Only include repo/branch for git-based sites - if (!$site->isLocal()) { - $data['repo'] = $site->repo; - $data['branch'] = $site->branch; - } - - return $data; } /** * Create a SiteDTO from raw inventory data. * * @param array $data Raw associative array from inventory. - * @return SiteDTO A SiteDTO where `domain` is a string (empty if missing), `repo` and `branch` are nullable strings (null for local sites), and `servers` is an array of strings. + * @return SiteDTO A SiteDTO where `domain`, `repo`, and `branch` are strings (empty if missing), and `servers` is an array of strings. */ private function hydrateSiteDTO(array $data): SiteDTO { $domain = $data['domain'] ?? ''; - $repo = $data['repo'] ?? null; - $branch = $data['branch'] ?? null; + $repo = $data['repo'] ?? ''; + $branch = $data['branch'] ?? ''; $servers = $data['servers'] ?? []; return new SiteDTO( domain: is_string($domain) ? $domain : '', - repo: is_string($repo) ? $repo : null, - branch: is_string($branch) ? $branch : null, + repo: is_string($repo) ? $repo : '', + branch: is_string($branch) ? $branch : '', servers: is_array($servers) ? array_values(array_filter($servers, is_string(...))) : [], ); } From d94063a504c6ab00fa1fa243a6efb1d716858a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucian=20V=C4=83c=C4=83roiu?= Date: Sun, 16 Nov 2025 17:26:54 +0200 Subject: [PATCH 2/3] refactor(site): simplify site display to always show Git source Remove isLocal() conditional logic and always display Git as source type. --- app/Traits/SitesTrait.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/Traits/SitesTrait.php b/app/Traits/SitesTrait.php index 6f24bca3..a53c9237 100644 --- a/app/Traits/SitesTrait.php +++ b/app/Traits/SitesTrait.php @@ -110,18 +110,12 @@ protected function selectSite(?array $sites = null): SiteDTO|int */ protected function displaySiteDeets(SiteDTO $site): void { - $details = ['Domain' => $site->domain]; - - if ($site->isLocal()) { - $details['Source'] = 'Local'; - } else { - $details = [ - ...$details, - 'Source' => 'Git', - 'Repo' => $site->repo, - 'Branch' => $site->branch, - ]; - } + $details = [ + 'Domain' => $site->domain, + 'Source' => 'Git', + 'Repo' => $site->repo, + 'Branch' => $site->branch, + ]; if (count($site->servers) > 1) { $details['Servers'] = $site->servers; From 46f421e84122f56c95ea5bb41dcef98197699d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucian=20V=C4=83c=C4=83roiu?= Date: Sun, 16 Nov 2025 17:26:58 +0200 Subject: [PATCH 3/3] refactor(site): remove source selection from site:add command Remove --source option and always collect Git repository details. Simplify command flow by eliminating local vs git branching. --- app/Console/Site/SiteAddCommand.php | 110 ++++++++++------------------ 1 file changed, 40 insertions(+), 70 deletions(-) diff --git a/app/Console/Site/SiteAddCommand.php b/app/Console/Site/SiteAddCommand.php index 8ca99060..b8613ea2 100644 --- a/app/Console/Site/SiteAddCommand.php +++ b/app/Console/Site/SiteAddCommand.php @@ -31,9 +31,8 @@ protected function configure(): void $this ->addOption('domain', null, InputOption::VALUE_REQUIRED, 'Domain name') - ->addOption('source', null, InputOption::VALUE_REQUIRED, 'Site source: git or local') - ->addOption('repo', null, InputOption::VALUE_REQUIRED, 'Git repository URL (for git sites)') - ->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Git branch name (for git sites)') + ->addOption('repo', null, InputOption::VALUE_REQUIRED, 'Git repository URL') + ->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Git branch name') ->addOption('server', null, InputOption::VALUE_REQUIRED, 'Server name'); } @@ -59,7 +58,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int [ 'domain' => $domain, - 'siteSource' => $siteSource, 'repo' => $repo, 'branch' => $branch, 'server' => $server, @@ -96,18 +94,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Show command replay // ---- - $hintOptions = [ + $this->showCommandReplay('site:add', [ 'domain' => $domain, - 'source' => $siteSource, + 'repo' => $repo, + 'branch' => $branch, 'server' => $server->name, - ]; - - if ($siteSource !== 'local') { - $hintOptions['repo'] = $repo; - $hintOptions['branch'] = $branch; - } - - $this->showCommandReplay('site:add', $hintOptions); + ]); return Command::SUCCESS; } @@ -119,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * Gather site details from user input or CLI options. * - * @return array{domain: string, siteSource: string, repo: ?string, branch: ?string, server: ServerDTO}|null + * @return array{domain: string, repo: string, branch: string, server: ServerDTO}|null */ protected function gatherSiteDeets(): ?array { @@ -154,71 +146,49 @@ protected function gatherSiteDeets(): ?array } // - // Select site source + // Gather git details // ---- - /** @var string $siteSource */ - $siteSource = $this->io->getOptionOrPrompt( - 'source', - fn (): string => (string) $this->io->promptSelect( - label: 'Deploy from:', - options: ['git' => 'Git Repository', 'local' => 'Local files'], - default: 'git' - ) + $defaultRepo = $this->git->detectRemoteUrl() ?? ''; + + /** @var string|null $repo */ + $repo = $this->io->getValidatedOptionOrPrompt( + 'repo', + fn ($validate) => $this->io->promptText( + label: 'Git repository URL:', + placeholder: 'git@github.com:user/repo.git', + default: $defaultRepo, + required: true, + validate: $validate + ), + fn ($value) => $this->validateSiteRepo($value) ); - $isLocal = $siteSource === 'local'; + if ($repo === null) { + return null; + } - // - // Gather git-specific details - // ---- + $defaultBranch = $this->git->detectCurrentBranch() ?? 'main'; - $repo = null; - $branch = null; - - if (!$isLocal) { - $defaultRepo = $this->git->detectRemoteUrl() ?? ''; - - /** @var string|null $repo */ - $repo = $this->io->getValidatedOptionOrPrompt( - 'repo', - fn ($validate) => $this->io->promptText( - label: 'Git repository URL:', - placeholder: 'git@github.com:user/repo.git', - default: $defaultRepo, - required: true, - validate: $validate - ), - fn ($value) => $this->validateSiteRepo($value) - ); - - if ($repo === null) { - return null; - } - - $defaultBranch = $this->git->detectCurrentBranch() ?? 'main'; - - /** @var string|null $branch */ - $branch = $this->io->getValidatedOptionOrPrompt( - 'branch', - fn ($validate) => $this->io->promptText( - label: 'Git branch:', - placeholder: $defaultBranch, - default: $defaultBranch, - required: true, - validate: $validate - ), - fn ($value) => $this->validateSiteBranch($value) - ); - - if ($branch === null) { - return null; - } + /** @var string|null $branch */ + $branch = $this->io->getValidatedOptionOrPrompt( + 'branch', + fn ($validate) => $this->io->promptText( + label: 'Git branch:', + placeholder: $defaultBranch, + default: $defaultBranch, + required: true, + validate: $validate + ), + fn ($value) => $this->validateSiteBranch($value) + ); + + if ($branch === null) { + return null; } return [ 'domain' => $domain, - 'siteSource' => $siteSource, 'repo' => $repo, 'branch' => $branch, 'server' => $server,