mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #12951 from appwrite/test/gitlab-list-namespaces-vcs
Add VCS namespaces endpoint
This commit is contained in:
10 files changed
+305
-16
No files matched your search
@@ -224,6 +224,7 @@ use Appwrite\Utopia\Response\Model\UsageVectorsDBs;
|
||||
use Appwrite\Utopia\Response\Model\User;
|
||||
use Appwrite\Utopia\Response\Model\Variable;
|
||||
use Appwrite\Utopia\Response\Model\VcsContent;
|
||||
use Appwrite\Utopia\Response\Model\VcsNamespace;
|
||||
use Appwrite\Utopia\Response\Model\VectorsDBCollection;
|
||||
use Appwrite\Utopia\Response\Model\Webhook;
|
||||
|
||||
@@ -259,6 +260,8 @@ Response::setModel(new BaseList('Function Templates List', Response::MODEL_TEMPL
|
||||
Response::setModel(new BaseList('Installations List', Response::MODEL_INSTALLATION_LIST, 'installations', Response::MODEL_INSTALLATION));
|
||||
Response::setModel(new ProviderRepositoryFrameworkList());
|
||||
Response::setModel(new ProviderRepositoryRuntimeList());
|
||||
Response::setModel(new VcsNamespace());
|
||||
Response::setModel(new BaseList('VCS Namespaces List', Response::MODEL_VCS_NAMESPACE_LIST, 'namespaces', Response::MODEL_VCS_NAMESPACE));
|
||||
Response::setModel(new BaseList('Branches List', Response::MODEL_BRANCH_LIST, 'branches', Response::MODEL_BRANCH));
|
||||
Response::setModel(new BaseList('Frameworks List', Response::MODEL_FRAMEWORK_LIST, 'frameworks', Response::MODEL_FRAMEWORK));
|
||||
Response::setModel(new BaseList('Runtimes List', Response::MODEL_RUNTIME_LIST, 'runtimes', Response::MODEL_RUNTIME));
|
||||
|
||||
+5
-1
@@ -41,6 +41,10 @@
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/utopia-php/auth"
|
||||
},
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/utopia-php/vcs"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@@ -96,7 +100,7 @@
|
||||
"utopia-php/telemetry": "^0.4",
|
||||
"utopia-php/user-agent": "0.1.*",
|
||||
"mustangostang/spyc": "0.6.*",
|
||||
"utopia-php/vcs": "^4.4.2",
|
||||
"utopia-php/vcs": "4.*.*",
|
||||
"utopia-php/websocket": "1.0.*",
|
||||
"dragonmantank/cron-expression": "3.4.*",
|
||||
"phpmailer/phpmailer": "6.9.*",
|
||||
|
||||
Generated
+27
-9
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "45a96f275db3fcab689375890cd5b41d",
|
||||
"content-hash": "a811ab43bece6d9d01be1caab8a08a75",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
@@ -5165,16 +5165,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/vcs",
|
||||
"version": "4.4.4",
|
||||
"version": "4.4.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/vcs.git",
|
||||
"reference": "37580b1a459c6b51f567b1720c118a8a0213f314"
|
||||
"reference": "4abcc51d113697fb45ad7fab83851bc4162c6bd4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/37580b1a459c6b51f567b1720c118a8a0213f314",
|
||||
"reference": "37580b1a459c6b51f567b1720c118a8a0213f314",
|
||||
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/4abcc51d113697fb45ad7fab83851bc4162c6bd4",
|
||||
"reference": "4abcc51d113697fb45ad7fab83851bc4162c6bd4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5195,7 +5195,25 @@
|
||||
"Utopia\\VCS\\": "src/VCS"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Utopia\\Tests\\": "tests/VCS"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": [
|
||||
"./vendor/bin/pint --test --config pint.json"
|
||||
],
|
||||
"format": [
|
||||
"./vendor/bin/pint --config pint.json"
|
||||
],
|
||||
"check": [
|
||||
"./vendor/bin/phpstan analyse --level 8 --memory-limit 512M -c phpstan.neon src tests"
|
||||
],
|
||||
"test": [
|
||||
"./vendor/bin/phpunit --configuration phpunit.xml --debug"
|
||||
]
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
@@ -5207,10 +5225,10 @@
|
||||
"vcs"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/vcs/issues",
|
||||
"source": "https://github.com/utopia-php/vcs/tree/4.4.4"
|
||||
"source": "https://github.com/utopia-php/vcs/tree/4.4.5",
|
||||
"issues": "https://github.com/utopia-php/vcs/issues"
|
||||
},
|
||||
"time": "2026-07-22T10:18:04+00:00"
|
||||
"time": "2026-07-23T13:01:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/websocket",
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\VCS\Http\Installations\Namespaces;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Platform\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Vcs\Factory as VcsFactory;
|
||||
use Appwrite\Vcs\InstallationTokens;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Queries;
|
||||
use Utopia\Database\Validator\Query\Limit;
|
||||
use Utopia\Database\Validator\Query\Offset;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class XList extends Action
|
||||
{
|
||||
use HTTP;
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return 'listNamespaces';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/vcs/installations/:installationId/namespaces')
|
||||
->desc('List namespaces')
|
||||
->groups(['api', 'vcs'])
|
||||
->label('scope', 'vcs.read')
|
||||
->label('resourceType', RESOURCE_TYPE_VCS)
|
||||
->label('sdk', new Method(
|
||||
namespace: 'vcs',
|
||||
group: 'namespaces',
|
||||
name: 'listNamespaces',
|
||||
description: 'List provider namespaces available to a VCS installation. This can include the user personal namespace and any groups or organizations the installation can browse.',
|
||||
auth: [AuthType::ADMIN],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
model: Response::MODEL_VCS_NAMESPACE_LIST,
|
||||
)
|
||||
]
|
||||
))
|
||||
->param('installationId', '', new Text(256), 'Installation Id')
|
||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
|
||||
->param('queries', [], new Queries([new Limit(), new Offset()]), '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 and offset', true)
|
||||
->inject('vcsFactory')
|
||||
->inject('installationTokens')
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
string $installationId,
|
||||
string $search,
|
||||
array $queries,
|
||||
VcsFactory $vcsFactory,
|
||||
InstallationTokens $installationTokens,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForPlatform
|
||||
) {
|
||||
$installation = $dbForPlatform->getDocument('installations', $installationId);
|
||||
|
||||
if ($installation->isEmpty()) {
|
||||
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($installation->getAttribute('projectInternalId') !== $project->getSequence()) {
|
||||
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$installation = $installationTokens->refreshForInstallation($installation, $dbForPlatform, $vcsFactory);
|
||||
$vcs = $vcsFactory->fromInstallation($installation);
|
||||
|
||||
$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));
|
||||
|
||||
$limit = !empty($limitQuery) ? $limitQuery->getValue() : 20;
|
||||
$offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0;
|
||||
|
||||
if ($offset % $limit !== 0) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'offset must be a multiple of the limit');
|
||||
}
|
||||
|
||||
$page = ($offset / $limit) + 1;
|
||||
|
||||
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,
|
||||
'name' => $owner,
|
||||
'path' => $owner,
|
||||
'type' => $installation->getAttribute('personal', false) ? 'user' : 'organization',
|
||||
'avatarUrl' => '',
|
||||
]] : [];
|
||||
$total = \count($namespaces);
|
||||
}
|
||||
|
||||
$namespaces = \array_map(fn ($namespace) => new Document($namespace), $namespaces);
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'namespaces' => $namespaces,
|
||||
'total' => $total,
|
||||
]), Response::MODEL_VCS_NAMESPACE_LIST);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +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\VcsRepositories;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Vcs\Factory as VcsFactory;
|
||||
use Appwrite\Vcs\InstallationTokens;
|
||||
@@ -17,9 +18,6 @@ use Utopia\Config\Exceptions\Parse;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Queries;
|
||||
use Utopia\Database\Validator\Query\Limit;
|
||||
use Utopia\Database\Validator\Query\Offset;
|
||||
use Utopia\Detector\Detection\Framework\Analog;
|
||||
use Utopia\Detector\Detection\Framework\Angular;
|
||||
use Utopia\Detector\Detection\Framework\Astro;
|
||||
@@ -97,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 Queries([new Limit(), new Offset()]), '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 and offset', 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')
|
||||
@@ -132,17 +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));
|
||||
$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;
|
||||
$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 = $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'] ?? '');
|
||||
|
||||
@@ -14,6 +14,7 @@ use Appwrite\Platform\Modules\VCS\Http\Gitlab\Callback\Get as GetGitlabCallback;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Gitlab\Events\Create as CreateGitlabEvent;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Delete as DeleteInstallation;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Get as GetInstallation;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Namespaces\XList as ListNamespaces;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Branches\XList as ListRepositoryBranches;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Contents\Get as GetRepositoryContents;
|
||||
use Appwrite\Platform\Modules\VCS\Http\Installations\Repositories\Create as CreateRepository;
|
||||
@@ -46,6 +47,7 @@ class Http extends Service
|
||||
$this->addAction(GetInstallation::getName(), new GetInstallation());
|
||||
$this->addAction(ListInstallations::getName(), new ListInstallations());
|
||||
$this->addAction(DeleteInstallation::getName(), new DeleteInstallation());
|
||||
$this->addAction(ListNamespaces::getName(), new ListNamespaces());
|
||||
|
||||
// Repositories
|
||||
$this->addAction(CreateRepository::getName(), new CreateRepository());
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
||||
|
||||
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 VcsRepositories extends Queries
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct([
|
||||
new Limit(),
|
||||
new Offset(),
|
||||
new VcsNamespace(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Database\Validator\Query;
|
||||
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Query\Base;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class VcsNamespace extends Base
|
||||
{
|
||||
public function getMethodType(): string
|
||||
{
|
||||
return self::METHOD_TYPE_FILTER;
|
||||
}
|
||||
|
||||
public function isValid($value): bool
|
||||
{
|
||||
if (!$value instanceof Query) {
|
||||
$this->message = 'Query must be an instance of Query';
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($value->getMethod() !== Query::TYPE_EQUAL) {
|
||||
$this->message = 'Only equal queries are supported for namespace';
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($value->getAttribute() !== 'namespace') {
|
||||
$this->message = 'Only namespace can be queried';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (\count($value->getValues()) !== 1) {
|
||||
$this->message = 'Namespace query must have exactly one value';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(new Text(256))->isValid($value->getValue())) {
|
||||
$this->message = 'Namespace query value must be a string with a maximum length of 256 characters';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,8 @@ class Response extends SwooleResponse
|
||||
public const MODEL_PROVIDER_REPOSITORY_FRAMEWORK_LIST = 'providerRepositoryFrameworkList';
|
||||
public const MODEL_PROVIDER_REPOSITORY_RUNTIME = 'providerRepositoryRuntime';
|
||||
public const MODEL_PROVIDER_REPOSITORY_RUNTIME_LIST = 'providerRepositoryRuntimeList';
|
||||
public const MODEL_VCS_NAMESPACE = 'vcsNamespace';
|
||||
public const MODEL_VCS_NAMESPACE_LIST = 'vcsNamespaceList';
|
||||
public const MODEL_BRANCH = 'branch';
|
||||
public const MODEL_BRANCH_LIST = 'branchList';
|
||||
public const MODEL_DETECTION_FRAMEWORK = 'detectionFramework';
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class VcsNamespace extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'VCS (Version Control System) namespace ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'VCS (Version Control System) namespace display name.',
|
||||
'default' => '',
|
||||
'example' => 'Appwrite',
|
||||
])
|
||||
->addRule('path', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'VCS (Version Control System) namespace path, used to filter repositories by namespace.',
|
||||
'default' => '',
|
||||
'example' => 'appwrite',
|
||||
])
|
||||
->addRule('type', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Namespace type. Either the user\'s personal namespace or a group/organization.',
|
||||
'default' => '',
|
||||
'example' => 'user',
|
||||
])
|
||||
->addRule('avatarUrl', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Namespace avatar URL.',
|
||||
'default' => '',
|
||||
'example' => 'https://example.com/avatar.png',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'VcsNamespace';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_VCS_NAMESPACE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user