Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(application): clarify deployment type precedence logic

Andras Bacsai0991f8e2ca8a
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 9f59445d82..82e4d6311f 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -989,17 +989,24 @@ class Application extends BaseModel
public function deploymentType()
{
- if (isDev() && data_get($this, 'private_key_id') === 0) {
+ $privateKeyId = data_get($this, 'private_key_id');
+
+ // Real private key (id > 0) always takes precedence
+ if ($privateKeyId !== null && $privateKeyId > 0) {
return 'deploy_key';
}
- if (! is_null(data_get($this, 'private_key_id'))) {
- return 'deploy_key';
- } elseif (data_get($this, 'source')) {
+
+ // GitHub/GitLab App source
+ if (data_get($this, 'source')) {
return 'source';
- } else {
- return 'other';
}
- throw new \Exception('No deployment type found');
+
+ // Localhost key (id = 0) when no source is configured
+ if ($privateKeyId === 0) {
+ return 'deploy_key';
+ }
+
+ return 'other';
}
public function could_set_build_commands(): bool
diff --git a/tests/Unit/ApplicationDeploymentTypeTest.php b/tests/Unit/ApplicationDeploymentTypeTest.php
index d240181f13..be7c7d5280 100644
--- a/tests/Unit/ApplicationDeploymentTypeTest.php
+++ b/tests/Unit/ApplicationDeploymentTypeTest.php
@@ -1,11 +1,54 @@
<?php
use App\Models\Application;
+use App\Models\GithubApp;
-it('treats zero private key id as deploy key', function () {
- $application = new Application();
+it('returns deploy_key when private_key_id is a real key', function () {
+ $application = new Application;
+ $application->private_key_id = 5;
+
+ expect($application->deploymentType())->toBe('deploy_key');
+});
+
+it('returns deploy_key when private_key_id is a real key even with source', function () {
+ $application = Mockery::mock(Application::class)->makePartial();
+ $application->private_key_id = 5;
+ $application->shouldReceive('getAttribute')->with('source')->andReturn(new GithubApp);
+ $application->shouldReceive('getAttribute')->with('private_key_id')->andReturn(5);
+
+ expect($application->deploymentType())->toBe('deploy_key');
+});
+
+it('returns source when private_key_id is null and source exists', function () {
+ $application = Mockery::mock(Application::class)->makePartial();
+ $application->private_key_id = null;
+ $application->shouldReceive('getAttribute')->with('source')->andReturn(new GithubApp);
+ $application->shouldReceive('getAttribute')->with('private_key_id')->andReturn(null);
+
+ expect($application->deploymentType())->toBe('source');
+});
+
+it('returns source when private_key_id is zero and source exists', function () {
+ $application = Mockery::mock(Application::class)->makePartial();
+ $application->private_key_id = 0;
+ $application->shouldReceive('getAttribute')->with('source')->andReturn(new GithubApp);
+ $application->shouldReceive('getAttribute')->with('private_key_id')->andReturn(0);
+
+ expect($application->deploymentType())->toBe('source');
+});
+
+it('returns deploy_key when private_key_id is zero and no source', function () {
+ $application = new Application;
$application->private_key_id = 0;
$application->source = null;
expect($application->deploymentType())->toBe('deploy_key');
});
+
+it('returns other when private_key_id is null and no source', function () {
+ $application = Mockery::mock(Application::class)->makePartial();
+ $application->shouldReceive('getAttribute')->with('source')->andReturn(null);
+ $application->shouldReceive('getAttribute')->with('private_key_id')->andReturn(null);
+
+ expect($application->deploymentType())->toBe('other');
+});