From bcfdbc829ed4346862dcb1ed0ac33a45200d325a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 23 Jul 2026 19:17:42 +0530 Subject: [PATCH] Address VCS namespace review feedback Rename owner terminology to namespace across the repositories listing endpoint, rename ProviderOwner/ProviderRepositories validators to VcsNamespace/VcsRepositories, rename VcsNamespace model's kind/id fields to type/$id, and relax the utopia-php/vcs composer constraint. --- composer.json | 2 +- .../Http/Installations/Namespaces/XList.php | 11 +++- .../Http/Installations/Repositories/XList.php | 14 ++--- ...erRepositories.php => VcsRepositories.php} | 6 +-- .../{ProviderOwner.php => VcsNamespace.php} | 12 ++--- .../Utopia/Response/Model/VcsNamespace.php | 8 +-- .../Validator/Queries/VcsRepositoriesTest.php | 41 ++++++++++++++ .../Validator/Query/VcsNamespaceTest.php | 54 +++++++++++++++++++ 8 files changed, 125 insertions(+), 23 deletions(-) rename src/Appwrite/Utopia/Database/Validator/Queries/{ProviderRepositories.php => VcsRepositories.php} (70%) rename src/Appwrite/Utopia/Database/Validator/Query/{ProviderOwner.php => VcsNamespace.php} (71%) create mode 100644 tests/unit/Utopia/Database/Validator/Queries/VcsRepositoriesTest.php create mode 100644 tests/unit/Utopia/Database/Validator/Query/VcsNamespaceTest.php diff --git a/composer.json b/composer.json index 6baa6b6123..c0c528c006 100644 --- a/composer.json +++ b/composer.json @@ -100,7 +100,7 @@ "utopia-php/telemetry": "^0.4", "utopia-php/user-agent": "0.1.*", "mustangostang/spyc": "0.6.*", - "utopia-php/vcs": "^4.4.5", + "utopia-php/vcs": "4.*.*", "utopia-php/websocket": "1.0.*", "dragonmantank/cron-expression": "3.4.*", "phpmailer/phpmailer": "6.9.*", diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Namespaces/XList.php b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Namespaces/XList.php index 9849fcd451..b5c409ebc7 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Namespaces/XList.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Namespaces/XList.php @@ -99,15 +99,22 @@ class XList extends Action if (\method_exists($vcs, 'listNamespaces')) { ['items' => $namespaces, 'total' => $total] = $vcs->listNamespaces($page, $limit, $search); + $namespaces = \array_map(fn ($namespace) => [ + '$id' => $namespace['id'] ?? '', + 'name' => $namespace['name'] ?? '', + 'path' => $namespace['path'] ?? '', + 'type' => ($namespace['kind'] ?? '') === 'user' ? 'user' : 'organization', + 'avatarUrl' => $namespace['avatarUrl'] ?? '', + ], $namespaces); } else { $providerInstallationId = $installation->getAttribute('providerInstallationId', ''); $owner = $vcs->getOwnerName($providerInstallationId); $matches = empty($search) || \stripos($owner, $search) !== false; $namespaces = $matches ? [[ - 'id' => $providerInstallationId, + '$id' => $providerInstallationId, 'name' => $owner, 'path' => $owner, - 'kind' => $installation->getAttribute('personal', false) ? 'user' : 'organization', + 'type' => $installation->getAttribute('personal', false) ? 'user' : 'organization', 'avatarUrl' => '', ]] : []; $total = \count($namespaces); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/XList.php b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/XList.php index 2eabb6dd88..fc7059ccb0 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/XList.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/XList.php @@ -7,7 +7,7 @@ use Appwrite\Platform\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; -use Appwrite\Utopia\Database\Validator\Queries\ProviderRepositories; +use Appwrite\Utopia\Database\Validator\Queries\VcsRepositories; use Appwrite\Utopia\Response; use Appwrite\Vcs\Factory as VcsFactory; use Appwrite\Vcs\InstallationTokens; @@ -95,7 +95,7 @@ class XList extends Action ->param('installationId', '', new Text(256), 'Installation Id') ->param('type', '', new WhiteList(['runtime', 'framework']), 'Detector type. Must be one of the following: runtime, framework', enum: new Enum(name: 'VCSDetectionType')) ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) - ->param('queries', [], new ProviderRepositories(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit, offset, and equal on owner.', true) + ->param('queries', [], new VcsRepositories(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit, offset, and equal on namespace.', true) ->inject('vcsFactory') ->inject('installationTokens') ->inject('response') @@ -130,20 +130,20 @@ class XList extends Action $queries = Query::parseQueries($queries); $limitQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT)); $offsetQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET)); - $ownerQueries = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_EQUAL && $query->getAttribute() === 'owner'); + $namespaceQueries = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_EQUAL && $query->getAttribute() === 'namespace'); $limit = !empty($limitQuery) ? $limitQuery->getValue() : 4; $offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0; - $ownerQuery = current($ownerQueries); - $providerOwner = !empty($ownerQuery) ? $ownerQuery->getValue('') : ''; + $namespaceQuery = current($namespaceQueries); + $providerNamespace = !empty($namespaceQuery) ? $namespaceQuery->getValue('') : ''; if ($offset % $limit !== 0) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'offset must be a multiple of the limit'); } $page = ($offset / $limit) + 1; - $owner = !empty($providerOwner) ? $providerOwner : $vcs->getOwnerName($providerInstallationId); - ['items' => $repos, 'total' => $total] = $vcs->searchRepositories($owner, $page, $limit, $search); + $namespace = !empty($providerNamespace) ? $providerNamespace : $vcs->getOwnerName($providerInstallationId); + ['items' => $repos, 'total' => $total] = $vcs->searchRepositories($namespace, $page, $limit, $search); $repos = \array_map(function ($repo) use ($installation) { $repo['id'] = \strval($repo['id'] ?? ''); diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/ProviderRepositories.php b/src/Appwrite/Utopia/Database/Validator/Queries/VcsRepositories.php similarity index 70% rename from src/Appwrite/Utopia/Database/Validator/Queries/ProviderRepositories.php rename to src/Appwrite/Utopia/Database/Validator/Queries/VcsRepositories.php index 4713bd25e8..ada47ff42e 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/ProviderRepositories.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/VcsRepositories.php @@ -2,19 +2,19 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\Query\ProviderOwner; +use Appwrite\Utopia\Database\Validator\Query\VcsNamespace; use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; -class ProviderRepositories extends Queries +class VcsRepositories extends Queries { public function __construct() { parent::__construct([ new Limit(), new Offset(), - new ProviderOwner(), + new VcsNamespace(), ]); } } diff --git a/src/Appwrite/Utopia/Database/Validator/Query/ProviderOwner.php b/src/Appwrite/Utopia/Database/Validator/Query/VcsNamespace.php similarity index 71% rename from src/Appwrite/Utopia/Database/Validator/Query/ProviderOwner.php rename to src/Appwrite/Utopia/Database/Validator/Query/VcsNamespace.php index 6a61b8972d..87486bd758 100644 --- a/src/Appwrite/Utopia/Database/Validator/Query/ProviderOwner.php +++ b/src/Appwrite/Utopia/Database/Validator/Query/VcsNamespace.php @@ -6,7 +6,7 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Query\Base; use Utopia\Validator\Text; -class ProviderOwner extends Base +class VcsNamespace extends Base { public function getMethodType(): string { @@ -21,22 +21,22 @@ class ProviderOwner extends Base } if ($value->getMethod() !== Query::TYPE_EQUAL) { - $this->message = 'Only equal queries are supported for owner'; + $this->message = 'Only equal queries are supported for namespace'; return false; } - if ($value->getAttribute() !== 'owner') { - $this->message = 'Only owner can be queried'; + if ($value->getAttribute() !== 'namespace') { + $this->message = 'Only namespace can be queried'; return false; } if (\count($value->getValues()) !== 1) { - $this->message = 'Owner query must have exactly one value'; + $this->message = 'Namespace query must have exactly one value'; return false; } if (!(new Text(256))->isValid($value->getValue())) { - $this->message = 'Owner query value must be a string with a maximum length of 256 characters'; + $this->message = 'Namespace query value must be a string with a maximum length of 256 characters'; return false; } diff --git a/src/Appwrite/Utopia/Response/Model/VcsNamespace.php b/src/Appwrite/Utopia/Response/Model/VcsNamespace.php index dc0f38b07c..2903552668 100644 --- a/src/Appwrite/Utopia/Response/Model/VcsNamespace.php +++ b/src/Appwrite/Utopia/Response/Model/VcsNamespace.php @@ -10,7 +10,7 @@ class VcsNamespace extends Model public function __construct() { $this - ->addRule('id', [ + ->addRule('$id', [ 'type' => self::TYPE_STRING, 'description' => 'VCS (Version Control System) namespace ID.', 'default' => '', @@ -24,13 +24,13 @@ class VcsNamespace extends Model ]) ->addRule('path', [ 'type' => self::TYPE_STRING, - 'description' => 'VCS (Version Control System) namespace path, used as the owner when listing repositories.', + 'description' => 'VCS (Version Control System) namespace path, used to filter repositories by namespace.', 'default' => '', 'example' => 'appwrite', ]) - ->addRule('kind', [ + ->addRule('type', [ 'type' => self::TYPE_STRING, - 'description' => 'Namespace kind. Either the user\'s personal namespace or a group/organization.', + 'description' => 'Namespace type. Either the user\'s personal namespace or a group/organization.', 'default' => '', 'example' => 'user', ]) diff --git a/tests/unit/Utopia/Database/Validator/Queries/VcsRepositoriesTest.php b/tests/unit/Utopia/Database/Validator/Queries/VcsRepositoriesTest.php new file mode 100644 index 0000000000..c59ecc35ee --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/Queries/VcsRepositoriesTest.php @@ -0,0 +1,41 @@ +assertTrue($validator->isValid([]), $validator->getDescription()); + } + + public function testValidQueries(): void + { + $validator = new VcsRepositories(); + + $this->assertTrue($validator->isValid([Query::limit(25)]), $validator->getDescription()); + $this->assertTrue($validator->isValid([Query::offset(0)]), $validator->getDescription()); + $this->assertTrue($validator->isValid([Query::equal('namespace', ['appwrite'])]), $validator->getDescription()); + $this->assertTrue($validator->isValid([ + Query::limit(25), + Query::offset(0), + Query::equal('namespace', ['appwrite']), + ]), $validator->getDescription()); + } + + public function testInvalidQueries(): void + { + $validator = new VcsRepositories(); + + $this->assertFalse($validator->isValid([Query::equal('name', ['appwrite'])])); + $this->assertFalse($validator->isValid([Query::greaterThan('namespace', 'appwrite')])); + } +} diff --git a/tests/unit/Utopia/Database/Validator/Query/VcsNamespaceTest.php b/tests/unit/Utopia/Database/Validator/Query/VcsNamespaceTest.php new file mode 100644 index 0000000000..4f3f01a07b --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/Query/VcsNamespaceTest.php @@ -0,0 +1,54 @@ +assertTrue($validator->isValid(Query::equal('namespace', ['appwrite'])), $validator->getDescription()); + } + + public function testInvalidNotQuery(): void + { + $validator = new VcsNamespace(); + + $this->assertFalse($validator->isValid('namespace')); + } + + public function testInvalidMethod(): void + { + $validator = new VcsNamespace(); + + $this->assertFalse($validator->isValid(Query::greaterThan('namespace', 'appwrite'))); + } + + public function testInvalidAttribute(): void + { + $validator = new VcsNamespace(); + + $this->assertFalse($validator->isValid(Query::equal('name', ['appwrite']))); + } + + public function testInvalidMultipleValues(): void + { + $validator = new VcsNamespace(); + + $this->assertFalse($validator->isValid(Query::equal('namespace', ['appwrite', 'utopia']))); + } + + public function testInvalidValueTooLong(): void + { + $validator = new VcsNamespace(); + + $this->assertFalse($validator->isValid(Query::equal('namespace', [\str_repeat('a', 257)]))); + } +}