This commit is contained in:
Hemachandar
2026-03-02 22:31:22 +05:30
parent 0de52855fe
commit bb4d1edd0b
3 changed files with 26 additions and 15 deletions
@@ -5,7 +5,7 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub\Authorize\External;
use Appwrite\Event\Build;
use Appwrite\Extend\Exception;
use Appwrite\Platform\Action;
use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployments;
use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
@@ -23,7 +23,7 @@ use Utopia\VCS\Exception\RepositoryNotFound;
class Update extends Action
{
use HTTP;
use Deployments;
use Deployment;
public static function getName()
{
@@ -100,8 +100,6 @@ class Update extends Action
$providerPullRequestIds = \array_unique(\array_merge($repository->getAttribute('providerPullRequestIds', []), [$providerPullRequestId]));
$repository = $repository->setAttribute('providerPullRequestIds', $providerPullRequestIds);
// TODO: Delete from array when PR is closed
$repository = $authorization->skip(fn () => $dbForPlatform->updateDocument('repositories', $repository->getId(), $repository));
$privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
@@ -7,6 +7,7 @@ use Appwrite\Event\Event;
use Appwrite\Extend\Exception;
use Appwrite\Filter\BranchDomain as BranchDomainFilter;
use Appwrite\Vcs\Comment;
use Utopia\Config\Config;
use Utopia\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
@@ -16,12 +17,13 @@ use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\DSN\DSN;
use Utopia\Span\Span;
use Utopia\System\System;
use Utopia\VCS\Adapter\Git\GitHub;
use Utopia\VCS\Exception\RepositoryNotFound;
trait Deployments
trait Deployment
{
protected function createGitDeployments(
GitHub $github,
@@ -68,7 +70,18 @@ trait Deployments
throw new Exception(Exception::PROJECT_NOT_FOUND, 'Repository references non-existent project');
}
if (!$this->validateDB($project)) {
try {
$dsn = new DSN($project->getAttribute('database'));
$databaseName = $dsn->getHost();
} catch (\InvalidArgumentException) {
$databaseName = $project->getAttribute('database');
}
$databases = Config::getParam('pools-database', []);
$index = in_array($databaseName, $databases);
if ($index === false) {
Console::error("Database: '{$databaseName}' is not part of region: " . System::getEnv('_APP_REGION'));
continue;
}
@@ -503,11 +516,6 @@ trait Deployments
}
}
protected function validateDB(Document $project): bool
{
return true;
}
protected function getBuildQueueName(Document $project, Database $dbForPlatform, Authorization $authorization): string
{
return System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME);
@@ -5,7 +5,7 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub\Events;
use Appwrite\Event\Build;
use Appwrite\Extend\Exception;
use Appwrite\Platform\Action;
use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployments;
use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment;
use Appwrite\Utopia\Request;
use Appwrite\Utopia\Response;
use Utopia\Database\Database;
@@ -19,7 +19,7 @@ use Utopia\VCS\Adapter\Git\GitHub;
class Create extends Action
{
use HTTP;
use Deployments;
use Deployment;
public static function getName()
{
@@ -55,6 +55,8 @@ class Create extends Action
Build $queueForBuilds,
array $platform
) {
$this->preprocessEvent($request);
$event = $request->getHeader('x-github-event', '');
Span::add('vcs.github.event.name', $event);
@@ -69,8 +71,6 @@ class Create extends Action
throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, "Invalid webhook payload signature. Please make sure the webhook secret has same value in your GitHub app and in the _APP_VCS_GITHUB_WEBHOOK_SECRET environment variable");
}
// TODO(hmacr): Forward event to other regions
$githubAppId = System::getEnv('_APP_VCS_GITHUB_APP_ID');
$privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$parsedPayload = $github->getEvent($event, $payload);
@@ -85,6 +85,11 @@ class Create extends Action
return $response->json($parsedPayload);
}
protected function preprocessEvent(Request $request)
{
return;
}
private function handleInstallationEvent(
array $parsedPayload,
Database $dbForPlatform,