Merge branch 'feat/vcs-factory' into feat/vcs-installation-tokens

This commit is contained in:
Harsh Mahajan authored and GitHub committed 2026-07-13 17:14:43 +05:30
commit bc8e538e0f
6 files changed
+11 -38

No files matched your search

+4
View File
@@ -382,10 +382,14 @@ $container->set('vcsFactory', fn (Cache $cache) => new VcsFactory($cache), ['cac
$container->set('installationTokens', fn () => new InstallationTokens(), []);
$container->set('repositoryWebhooks', fn (VcsFactory $vcsFactory) => new RepositoryWebhooks($vcsFactory), ['vcsFactory']);
$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 () => []);
@@ -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', ''));
@@ -16,7 +16,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 +36,7 @@ class Create extends Action
->desc('Create event')
->groups(['api', 'vcs'])
->label('scope', 'public')
->inject('vcsWebhookSecret')
->inject('vcsForProvider')
->inject('vcsForInstallation')
->inject('request')
@@ -51,6 +51,7 @@ class Create extends Action
}
public function action(
callable $vcsWebhookSecret,
callable $vcsForProvider,
callable $vcsForInstallation,
Request $request,
@@ -71,7 +72,7 @@ class Create extends Action
$payload = $request->getRawPayload();
$signature = $request->getHeaderLine('x-hub-signature-256', '');
$secretKey = System::getEnv('_APP_VCS_GITHUB_WEBHOOK_SECRET', '');
$secretKey = $vcsWebhookSecret('github');
$valid = empty($secretKey) ? true : $vcs->validateWebhookEvent($payload, $signature, $secretKey);
Span::add('vcs.github.event.signature.valid', $valid);
@@ -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;
}
-27
View File
@@ -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<string>
*/
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');
-3
View File
@@ -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);