From d3b76dfa932152fa2e80333b5b09091bb5be41d7 Mon Sep 17 00:00:00 2001 From: seahurt Date: Tue, 19 May 2026 14:10:17 +0800 Subject: [PATCH 1/2] fix: only strip git_host from repository_url when git_host is github.com --- app/Http/Controllers/Api/ApplicationsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php index 074269fa0..aaf18d64f 100644 --- a/app/Http/Controllers/Api/ApplicationsController.php +++ b/app/Http/Controllers/Api/ApplicationsController.php @@ -1140,8 +1140,8 @@ private function create_application(Request $request, $type) if ($git_host === 'github.com') { $application->source_type = GithubApp::class; $application->source_id = GithubApp::find(0)->id; + $application->git_repository = str($repository_url_parsed->getSegment(1).'/'.$repository_url_parsed->getSegment(2))->trim()->toString(); } - $application->git_repository = str($repository_url_parsed->getSegment(1).'/'.$repository_url_parsed->getSegment(2))->trim()->toString(); $application->fqdn = $fqdn; $application->destination_id = $destination->id; $application->destination_type = $destination->getMorphClass(); From 2741bc1d0d08fdb88771c4197948039fcc8a08ea Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 7 Jul 2026 12:10:38 +0200 Subject: [PATCH 2/2] test(api): cover public git repository URL storage --- .../ApplicationPublicApiGitRepositoryTest.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/Feature/ApplicationPublicApiGitRepositoryTest.php diff --git a/tests/Feature/ApplicationPublicApiGitRepositoryTest.php b/tests/Feature/ApplicationPublicApiGitRepositoryTest.php new file mode 100644 index 000000000..eb105e676 --- /dev/null +++ b/tests/Feature/ApplicationPublicApiGitRepositoryTest.php @@ -0,0 +1,88 @@ + InstanceSettings::firstOrCreate(['id' => 0])); + + $this->team = Team::factory()->create(); + $this->user = User::factory()->create(); + $this->team->members()->attach($this->user->id, ['role' => 'owner']); + session(['currentTeam' => $this->team]); + + $plainTextToken = Str::random(40); + $token = $this->user->tokens()->create([ + 'name' => 'public-git-api-test-'.Str::random(6), + 'token' => hash('sha256', $plainTextToken), + 'abilities' => ['*'], + 'team_id' => $this->team->id, + ]); + $this->bearerToken = $token->getKey().'|'.$plainTextToken; + + $this->server = Server::factory()->create(['team_id' => $this->team->id]); + $this->destination = StandaloneDocker::where('server_id', $this->server->id)->first(); + $this->project = Project::factory()->create(['team_id' => $this->team->id]); + $this->environment = Environment::factory()->create(['project_id' => $this->project->id]); +}); + +function createPublicGitApplication(array $overrides = []): Application +{ + $response = test()->withHeaders([ + 'Authorization' => 'Bearer '.test()->bearerToken, + 'Content-Type' => 'application/json', + ])->postJson('/api/v1/applications/public', array_merge([ + 'project_uuid' => test()->project->uuid, + 'environment_uuid' => test()->environment->uuid, + 'server_uuid' => test()->server->uuid, + 'git_repository' => 'https://gitlab.com/coolify/test-static-app', + 'git_branch' => 'main', + 'build_pack' => 'static', + 'ports_exposes' => '80', + 'autogenerate_domain' => false, + ], $overrides)); + + $response->assertCreated(); + + return Application::where('uuid', $response->json('uuid'))->firstOrFail(); +} + +test('public non github repositories keep their full git repository url', function () { + $application = createPublicGitApplication([ + 'git_repository' => 'https://cnb.cool/matridx/frp_webui', + ]); + + expect($application->git_repository)->toBe('https://cnb.cool/matridx/frp_webui') + ->and($application->source_type)->toBeNull() + ->and($application->source_id)->toBeNull(); +}); + +test('public github repositories are stored as owner and repository with the public github source', function () { + GithubApp::unguarded(fn () => GithubApp::create([ + 'id' => 0, + 'name' => 'Public GitHub', + 'api_url' => 'https://api.github.com', + 'html_url' => 'https://github.com', + 'is_public' => true, + 'team_id' => 0, + ])); + + $application = createPublicGitApplication([ + 'git_repository' => 'https://github.com/coollabsio/coolify-examples', + ]); + + expect($application->git_repository)->toBe('coollabsio/coolify-examples') + ->and($application->source_type)->toBe(GithubApp::class) + ->and($application->source_id)->toBe(0); +});