diff --git a/app/config/collections.php b/app/config/collections.php index c0123f539b..be5f4ca51b 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2461,6 +2461,16 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('branch'), + 'type' => Database::VAR_STRING, + 'signed' => true, + 'size' => Database::LENGTH_KEY, + 'format' => '', + 'filters' => [], + 'required' => false, + 'array' => false, + ], [ '$id' => ID::custom('logging'), 'type' => Database::VAR_BOOLEAN, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 041f1228de..26ff5ae47e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -525,13 +525,14 @@ App::put('/v1/functions/:functionId') ->param('installCommand', '', new Text('1028'), 'Install Command.', true) ->param('installationId', '', new Text(128), 'Appwrite Installation ID for vcs deployment.', true) ->param('repositoryId', '', new Text(128), 'Repository ID of the repo linked to the function', true) + ->param('branch', 'main', new Text(128), 'Production branch for the repo linked to the function', true) ->inject('response') ->inject('dbForProject') ->inject('project') ->inject('user') ->inject('events') ->inject('dbForConsole') - ->action(function (string $functionId, string $name, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $buildCommand, string $installCommand, string $vcsInstallationId, string $repositoryId, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance, Database $dbForConsole) { + ->action(function (string $functionId, string $name, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $buildCommand, string $installCommand, string $vcsInstallationId, string $repositoryId, string $branch, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance, Database $dbForConsole) { $function = $dbForProject->getDocument('functions', $functionId); @@ -611,7 +612,7 @@ App::put('/v1/functions/:functionId') 'vcsInstallationInternalId' => $installation->getInternalId(), 'vcsRepoId' => $vcsRepoId, 'vcsRepoInternalId' => $vcsRepoInternalId, - 'branch' => "main", + 'branch' => $branch, 'search' => implode(' ', [$deploymentId, $entrypoint]), 'activate' => true, ])); @@ -639,6 +640,7 @@ App::put('/v1/functions/:functionId') 'vcsInstallationInternalId' => $installation->getInternalId(), 'vcsRepoId' => $vcsRepoId ?? $function->getAttribute('vcsRepoId', ''), 'vcsRepoInternalId' => $vcsRepoInternalId ?? $function->getAttribute('vcsRepoInternalId', ''), + 'branch'=> $branch, 'search' => implode(' ', [$functionId, $name, $function->getAttribute('runtime')]), ]))); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index abe702ef8e..fd6249ce3e 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -213,10 +213,11 @@ App::post('/v1/vcs/github/incomingwebhook') $vcsRepoInternalId = $resource->getInternalId(); $vcsInstallationId = $resource->getAttribute('vcsInstallationId'); $vcsInstallationInternalId = $resource->getAttribute('vcsInstallationInternalId'); + $productionBranch = $resource->getAttribute('branch', 'main'); $activate = false; // TODO: Configurable in function settings - if ($branchName == "main") { + if ($branchName == $productionBranch) { $activate = true; }