From b6650a099dc53426d5309f3ed34de8ab1acc2b1f Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 2 Nov 2025 17:24:42 +0000 Subject: [PATCH 1/3] Fix: Add GitLab support to convertGitUrl function with custom port handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes two issues preventing GitLab deployments with custom SSH ports: 1. Missing GitlabApp import and type declaration in convertGitUrl function - Added 'use App\Models\GitlabApp;' import - Updated function signature to accept 'GithubApp|GitlabApp|null' 2. Custom ports not applied for SCP-style SSH URLs (e.g., git@host:repo.git) - Added logic to extract custom port from source when using SCP-style URLs - GitLab instances with custom SSH ports now work correctly Previously, the function only: - Accepted GithubApp in the type hint, causing runtime errors with GitlabApp - Handled custom ports for HTTP-to-SSH conversion - Didn't apply custom ports when SSH URLs were already provided This fix ensures both GitHub and GitLab apps with custom ports (e.g., 2222) work correctly with SCP-style repository URLs. Fixes deployment errors like: - "convertGitUrl(): Argument #3 must be of type GithubApp|GitlabApp|null, GitlabApp given" - SSH connection failures when GitLab uses non-standard port 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- bootstrap/helpers/shared.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 0f5b6f553..8665cf611 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -8,6 +8,7 @@ use App\Models\ApplicationDeploymentQueue; use App\Models\ApplicationPreview; use App\Models\EnvironmentVariable; use App\Models\GithubApp; +use App\Models\GitlabApp; use App\Models\InstanceSettings; use App\Models\LocalFileVolume; use App\Models\LocalPersistentVolume; @@ -3014,7 +3015,7 @@ NGINX; } } -function convertGitUrl(string $gitRepository, string $deploymentType, ?GithubApp $source = null): array +function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp|GitlabApp|null $source = null): array { $repository = $gitRepository; $providerInfo = [ @@ -3029,11 +3030,25 @@ function convertGitUrl(string $gitRepository, string $deploymentType, ?GithubApp // Let's try and parse the string to detect if it's a valid SSH string or not preg_match('/((.*?)\:\/\/)?(.*@.*:.*)/', $gitRepository, $sshMatches); + // Extract custom port from source for GitLab/GitHub apps with custom ports + // This handles SCP-style URLs like git@host:repo.git where host uses non-standard port + if ($deploymentType === 'deploy_key' && $source && ! empty($sshMatches)) { + switch ($source->getMorphClass()) { + case \App\Models\GithubApp::class: + case \App\Models\GitlabApp::class: + if ($source->custom_port !== 22) { + $providerInfo['port'] = $source->custom_port; + } + break; + } + } + if ($deploymentType === 'deploy_key' && empty($sshMatches) && $source) { // If this happens, the user may have provided an HTTP URL when they needed an SSH one // Let's try and fix that for known Git providers switch ($source->getMorphClass()) { case \App\Models\GithubApp::class: + case \App\Models\GitlabApp::class: $providerInfo['host'] = Url::fromString($source->html_url)->getHost(); $providerInfo['port'] = $source->custom_port; $providerInfo['user'] = $source->custom_user; From 174a766ae613493a3644e8c9705ec5a5c5df3a2f Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 2 Nov 2025 20:07:33 +0000 Subject: [PATCH 2/3] Fix null handling for custom_port to prevent SSH connection failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when custom_port was null (the common case), the code would set the port to null, breaking SSH connections. This fix adds proper null checks and defaults to port 22 when custom_port is not set. Changes: - Add null check before comparing custom_port to prevent null assignment - Cast custom_port to int for type safety - Default to port 22 when custom_port is null in fallback URL construction Fixes the issue reported by CodeRabbit in PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- bootstrap/helpers/shared.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 8665cf611..a41482b02 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -3036,8 +3036,8 @@ function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp| switch ($source->getMorphClass()) { case \App\Models\GithubApp::class: case \App\Models\GitlabApp::class: - if ($source->custom_port !== 22) { - $providerInfo['port'] = $source->custom_port; + if ($source->custom_port !== null && (int) $source->custom_port !== 22) { + $providerInfo['port'] = (int) $source->custom_port; } break; } @@ -3050,7 +3050,7 @@ function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp| case \App\Models\GithubApp::class: case \App\Models\GitlabApp::class: $providerInfo['host'] = Url::fromString($source->html_url)->getHost(); - $providerInfo['port'] = $source->custom_port; + $providerInfo['port'] = $source->custom_port ?? 22; $providerInfo['user'] = $source->custom_user; break; } From 8abbf284a5758a550581a17d1536a2bad71514da Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 2 Nov 2025 20:17:21 +0000 Subject: [PATCH 3/3] Fix empty string handling for custom_port to match defensive pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The null coalescing operator (??) only checks for null, not empty strings. When custom_port is an empty string, it would pass through and cause SSH connections to fail with an invalid port. This commit updates line 3053 to match the same defensive pattern used at lines 3039-3041, checking for null, empty strings, and casting to int for consistent validation across both code paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- bootstrap/helpers/shared.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index a41482b02..3edd66cdc 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -3050,7 +3050,7 @@ function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp| case \App\Models\GithubApp::class: case \App\Models\GitlabApp::class: $providerInfo['host'] = Url::fromString($source->html_url)->getHost(); - $providerInfo['port'] = $source->custom_port ?? 22; + $providerInfo['port'] = ($source->custom_port !== null && $source->custom_port !== '' && (int) $source->custom_port !== 22) ? (int) $source->custom_port : 22; $providerInfo['user'] = $source->custom_user; break; }