From 57dd4922421f7d455b3bb1dd6e7781871bdaa690 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 13 Jul 2026 17:01:59 +0530 Subject: [PATCH 1/4] Use VCS factory helpers in GitHub routes --- .../Platform/Modules/VCS/Http/GitHub/Events/Create.php | 6 ++++-- .../VCS/Http/Installations/Repositories/Contents/Get.php | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 42be69bd1f..ac7e90b8a7 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,6 +8,7 @@ use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; +use Appwrite\Vcs\Factory as VcsFactory; use OpenRuntimes\Orchestrator\Jobs; use Utopia\Console; use Utopia\Database\Database; @@ -16,7 +17,6 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Platform\Scope\HTTP; use Utopia\Span\Span; -use Utopia\System\System; use Utopia\VCS\Adapter\Git\GitHub; class Create extends Action @@ -37,6 +37,7 @@ class Create extends Action ->desc('Create event') ->groups(['api', 'vcs']) ->label('scope', 'public') + ->inject('vcsFactory') ->inject('vcsForProvider') ->inject('vcsForInstallation') ->inject('request') @@ -51,6 +52,7 @@ class Create extends Action } public function action( + VcsFactory $vcsFactory, callable $vcsForProvider, callable $vcsForInstallation, Request $request, @@ -71,7 +73,7 @@ class Create extends Action $payload = $request->getRawPayload(); $signature = $request->getHeaderLine('x-hub-signature-256', ''); - $secretKey = System::getEnv('_APP_VCS_GITHUB_WEBHOOK_SECRET', ''); + $secretKey = $vcsFactory->getWebhookSecret('github'); $valid = empty($secretKey) ? true : $vcs->validateWebhookEvent($payload, $signature, $secretKey); Span::add('vcs.github.event.signature.valid', $valid); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Contents/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Contents/Get.php index 0d95e9e3e9..be71500a1a 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Contents/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Contents/Get.php @@ -12,7 +12,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Text; -use Utopia\VCS\Adapter\Git\GitHub; use Utopia\VCS\Exception\RepositoryNotFound; class Get extends Action @@ -89,7 +88,7 @@ class Get extends Action $vcsContents = []; foreach ($contents as $content) { $isDirectory = false; - if ($content['type'] === GitHub::CONTENTS_DIRECTORY) { + if ($content['type'] === 'dir') { $isDirectory = true; } From b3b43ab4e9ee8f337caaa9416ddf1026a8747d6c Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 13 Jul 2026 17:04:27 +0530 Subject: [PATCH 2/4] Use bootstrapped VCS config in test --- tests/unit/Vcs/FactoryTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/Vcs/FactoryTest.php b/tests/unit/Vcs/FactoryTest.php index d015b2b11c..9d2d367922 100644 --- a/tests/unit/Vcs/FactoryTest.php +++ b/tests/unit/Vcs/FactoryTest.php @@ -9,7 +9,6 @@ use Appwrite\Vcs\Factory; use PHPUnit\Framework\TestCase; use Utopia\Cache\Adapter\None; use Utopia\Cache\Cache; -use Utopia\Config\Adapters\PHP as ConfigPHP; use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\VCS\Adapter\Git; @@ -24,8 +23,6 @@ final class FactoryTest extends TestCase public function testRegistryEntries(): void { - Config::load('vcs', __DIR__ . '/../../../app/config/vcs.php', new ConfigPHP()); - $registry = Config::getParam('vcs', []); $this->assertNotEmpty($registry); From 0fd8c449ffbe259c638a2781ed272b1a1b6100c7 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 13 Jul 2026 17:05:55 +0530 Subject: [PATCH 3/4] Trim VCS factory comments --- src/Appwrite/Vcs/Factory.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/Appwrite/Vcs/Factory.php b/src/Appwrite/Vcs/Factory.php index 4dc55e11d7..4d8037e035 100644 --- a/src/Appwrite/Vcs/Factory.php +++ b/src/Appwrite/Vcs/Factory.php @@ -9,13 +9,6 @@ use Utopia\Database\Document; use Utopia\System\System; use Utopia\VCS\Adapter\Git; -/** - * Builds VCS adapters from the `vcs` config registry. - * - * DI resources use this service to resolve adapters from installation - * documents or provider keys instead of hardcoding one provider. - * The factory only constructs adapters — it never touches the database. - */ class Factory { /** @@ -41,11 +34,6 @@ class Factory } } - /** - * Keys of providers that are enabled and fully configured. - * - * @return array - */ public function getProviders(): array { return \array_values(\array_filter( @@ -54,9 +42,6 @@ class Factory )); } - /** - * Whether all required environment variables are set for a provider. - */ public function isConfigured(string $key): bool { if (!isset($this->registry[$key])) { @@ -72,10 +57,6 @@ class Factory return true; } - /** - * Uninitialized adapter for provider-level operations that need no - * installation credentials (webhook signature validation, payload parsing). - */ public function fromProvider(string $key): Git { if (!isset($this->registry[$key])) { @@ -92,11 +73,6 @@ class Factory return $adapter; } - /** - * Initialized adapter for an installation. App credentials and personal - * tokens are both always passed; each adapter uses the set its - * authentication scheme needs and ignores the other. - */ public function fromInstallation(Document $installation): Git { if ($installation->isEmpty()) { @@ -121,9 +97,6 @@ class Factory return $adapter; } - /** - * Webhook secret configured for a provider, empty if none is set. - */ public function getWebhookSecret(string $key): string { return $this->getEnv($key, 'WEBHOOK_SECRET'); From 8a12d98705f5017e14bf3930fafc020fb4168bf5 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 13 Jul 2026 17:11:52 +0530 Subject: [PATCH 4/4] Hide VCS factory behind DI closures --- app/init/resources.php | 4 ++++ .../Platform/Modules/Console/Http/Variables/Get.php | 7 +++---- .../Platform/Modules/VCS/Http/GitHub/Events/Create.php | 7 +++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index d0c7bc07be..37705c48fe 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -378,10 +378,14 @@ $container->set('promiseAdapter', fn ($register) => $register->get('promiseAdapt $container->set('vcsFactory', fn (Cache $cache) => new VcsFactory($cache), ['cache']); +$container->set('vcsProviders', fn (VcsFactory $vcsFactory) => fn () => $vcsFactory->getProviders(), ['vcsFactory']); + $container->set('vcsForInstallation', fn (VcsFactory $vcsFactory) => fn (Document $installation) => $vcsFactory->fromInstallation($installation), ['vcsFactory']); $container->set('vcsForProvider', fn (VcsFactory $vcsFactory) => fn (string $provider) => $vcsFactory->fromProvider($provider), ['vcsFactory']); +$container->set('vcsWebhookSecret', fn (VcsFactory $vcsFactory) => fn (string $provider) => $vcsFactory->getWebhookSecret($provider), ['vcsFactory']); + $container->set('plan', fn () => []); $container->set('smsRates', fn () => []); diff --git a/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php b/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php index f1beaeb276..0ab83d27d2 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php +++ b/src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php @@ -7,7 +7,6 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; -use Appwrite\Vcs\Factory; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Domains\Domain; @@ -47,7 +46,7 @@ class Get extends Action ], contentType: ContentType::JSON )) - ->inject('vcsFactory') + ->inject('vcsProviders') ->inject('response') ->inject('platform') ->inject('dbForProject') @@ -55,7 +54,7 @@ class Get extends Action } public function action( - Factory $vcsFactory, + callable $vcsProviders, Response $response, array $platform, Database $dbForProject @@ -72,7 +71,7 @@ class Get extends Action $isDomainEnabled = $isAAAAValid || $isAValid || $isCNAMEValid; - $isVcsEnabled = !empty($vcsFactory->getProviders()); + $isVcsEnabled = !empty($vcsProviders()); $isAssistantEnabled = !empty(System::getEnv('_APP_ASSISTANT_OPENAI_API_KEY', '')); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index ac7e90b8a7..687214bd93 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,7 +8,6 @@ use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; -use Appwrite\Vcs\Factory as VcsFactory; use OpenRuntimes\Orchestrator\Jobs; use Utopia\Console; use Utopia\Database\Database; @@ -37,7 +36,7 @@ class Create extends Action ->desc('Create event') ->groups(['api', 'vcs']) ->label('scope', 'public') - ->inject('vcsFactory') + ->inject('vcsWebhookSecret') ->inject('vcsForProvider') ->inject('vcsForInstallation') ->inject('request') @@ -52,7 +51,7 @@ class Create extends Action } public function action( - VcsFactory $vcsFactory, + callable $vcsWebhookSecret, callable $vcsForProvider, callable $vcsForInstallation, Request $request, @@ -73,7 +72,7 @@ class Create extends Action $payload = $request->getRawPayload(); $signature = $request->getHeaderLine('x-hub-signature-256', ''); - $secretKey = $vcsFactory->getWebhookSecret('github'); + $secretKey = $vcsWebhookSecret('github'); $valid = empty($secretKey) ? true : $vcs->validateWebhookEvent($payload, $signature, $secretKey); Span::add('vcs.github.event.signature.valid', $valid);