mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
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.
This commit is contained in:
1 parent
19f9a8824a
commit
bcfdbc829e
8 files changed
+125
-23
No files matched your search
+1
-1
@@ -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.*",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'] ?? '');
|
||||
|
||||
+3
-3
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
])
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Utopia\Database\Validator\Queries;
|
||||
|
||||
use Appwrite\Utopia\Database\Validator\Queries\VcsRepositories;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Query;
|
||||
|
||||
final class VcsRepositoriesTest extends TestCase
|
||||
{
|
||||
public function testEmptyQueries(): void
|
||||
{
|
||||
$validator = new VcsRepositories();
|
||||
|
||||
$this->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')]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Utopia\Database\Validator\Query;
|
||||
|
||||
use Appwrite\Utopia\Database\Validator\Query\VcsNamespace;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Query;
|
||||
|
||||
final class VcsNamespaceTest extends TestCase
|
||||
{
|
||||
public function testIsValid(): void
|
||||
{
|
||||
$validator = new VcsNamespace();
|
||||
|
||||
$this->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)])));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user