From 1c6b735a27141f04a20a2a05f0fe43c25f32ffe5 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:48:45 -0400 Subject: [PATCH 1/2] feat: disconnecting git only when provider it is an empty string --- app/controllers/api/functions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 443260ea90..f23fbf2f69 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -47,6 +47,7 @@ use Utopia\System\System; use Utopia\Validator\ArrayList; use Utopia\Validator\Assoc; use Utopia\Validator\Boolean; +use Utopia\Validator\Nullable; use Utopia\Validator\Range; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; @@ -688,7 +689,7 @@ App::put('/v1/functions/:functionId') ->param('commands', '', new Text(8192, 0), 'Build Commands.', true) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API Key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Controle System) deployment.', true) - ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the function', true) + ->param('providerRepositoryId', null, new Nullable(new Text(128, 0)), 'Repository ID of the repo linked to the function', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function', true) ->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.', true) ->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true) @@ -700,7 +701,7 @@ App::put('/v1/functions/:functionId') ->inject('queueForBuilds') ->inject('dbForConsole') ->inject('gitHub') - ->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) { + ->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) { // TODO: If only branch changes, re-deploy $function = $dbForProject->getDocument('functions', $functionId); @@ -739,7 +740,7 @@ App::put('/v1/functions/:functionId') $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); // Git disconnect logic - if ($isConnected && empty($providerRepositoryId)) { + if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForConsole->find('repositories', [ Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('resourceInternalId', [$function->getInternalId()]), From 95fe93913608c1f708e73e741f1cbd2404e91b21 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:50:25 -0400 Subject: [PATCH 2/2] feat: adding explanation --- app/controllers/api/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f23fbf2f69..c119bfd76a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -739,7 +739,7 @@ App::put('/v1/functions/:functionId') $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); - // Git disconnect logic + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForConsole->find('repositories', [ Query::equal('projectInternalId', [$project->getInternalId()]),