From 825e9639b1c9238df73fa918fd42c0ba2df63e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 6 Mar 2025 12:20:08 +0100 Subject: [PATCH] Move cancel build to deployment endpoint --- .../Http/Deployments/{Builds => Status}/Update.php | 11 ++++++----- .../Platform/Modules/Functions/Services/Http.php | 4 ++-- .../Http/Deployments/{Builds => Status}/Update.php | 10 +++++----- src/Appwrite/Platform/Modules/Sites/Services/Http.php | 4 ++-- tests/e2e/Services/Functions/FunctionsBase.php | 10 ++++++++++ .../Services/Functions/FunctionsCustomServerTest.php | 11 +++-------- tests/e2e/Services/Sites/SitesBase.php | 10 ++++++++++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 11 +++-------- 8 files changed, 41 insertions(+), 30 deletions(-) rename src/Appwrite/Platform/Modules/Functions/Http/Deployments/{Builds => Status}/Update.php (94%) rename src/Appwrite/Platform/Modules/Sites/Http/Deployments/{Builds => Status}/Update.php (95%) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Builds/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php similarity index 94% rename from src/Appwrite/Platform/Modules/Functions/Http/Deployments/Builds/Update.php rename to src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php index 85edfd42ca..e349292e4b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Builds/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Status/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/build') - ->desc('Cancel deployment') + ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/status') + ->httpAlias('/v1/functions/:functionId/deployments/:deploymentId/build') + ->desc('Update deployment status') ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) @@ -41,7 +42,7 @@ class Update extends Action ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( namespace: 'functions', - name: 'updateDeploymentBuild', + name: 'updateDeploymentStatus', description: <<addAction(CreateVcsDeployment::getName(), new CreateVcsDeployment()); $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment()); - $this->addAction(UpdateBuild::getName(), new UpdateBuild()); + $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); // Executions $this->addAction(CreateExecution::getName(), new CreateExecution()); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Builds/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php similarity index 95% rename from src/Appwrite/Platform/Modules/Sites/Http/Deployments/Builds/Update.php rename to src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php index 87831670a3..0a15053df1 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Builds/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Status/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/build') - ->desc('Cancel deployment') + ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/status') + ->desc('Update deployment status') ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('audits.event', 'deployment.update') ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( namespace: 'sites', - name: 'updateDeploymentBuild', + name: 'updateDeploymentStatus', description: <<addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment()); - $this->addAction(UpdateBuild::getName(), new UpdateBuild()); + $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); // Logs $this->addAction(GetLog::getName(), new GetLog()); diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index f812f57f00..9f0a5903f3 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -379,4 +379,14 @@ trait FunctionsBase return $function; } + + protected function cancelDeployment(string $functionId, string $deploymentId): mixed + { + $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId . '/status', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + return $deployment; + } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index a1904edea1..2056d1f689 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -536,14 +536,9 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('building', $deployment['body']['status']); }, 100000, 250); - // Cancel the deployment - $cancel = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId . '/build', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $cancel['headers']['status-code']); - $this->assertEquals('canceled', $cancel['body']['status']); + $deployment = $this->cancelDeployment($functionId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('canceled', $deployment['body']['status']); /** * Build worker still runs the build. diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 259bc85228..a7e0293409 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -404,4 +404,14 @@ trait SitesBase return $site; } + + protected function cancelDeployment(string $siteId, string $deploymentId): mixed + { + $deployment = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId . '/status', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + return $deployment; + } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 605c5abb3e..c9adc3a116 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -708,14 +708,9 @@ class SitesCustomServerTest extends Scope $this->assertEquals('building', $deployment['body']['status']); }, 100000, 250); - // Cancel the deployment - $cancel = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId . '/build', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); - - $this->assertEquals(200, $cancel['headers']['status-code']); - $this->assertEquals('canceled', $cancel['body']['status']); + $deployment = $this->cancelDeployment($siteId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals('canceled', $deployment['body']['status']); /** * Build worker still runs the build.