Merge pull request #12970 from appwrite/feat/vcs-gitlab-list-namespaces

Accept providerNamespace on createRepository to create in a GitLab group
This commit is contained in:
Harsh Mahajan authored and GitHub committed 2026-07-24 13:18:04 +05:30
commit 8cafca0fde
4 files changed
+19 -7

No files matched your search

+1 -1
View File
@@ -137,7 +137,7 @@ class Gitea extends OAuth2
return $this->user;
}
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', $this->endpoint . '/api/v1/user/repos', ['Authorization: token ' . $accessToken, 'Content-Type: application/json'], \json_encode([
'name' => $repositoryName,
+1 -1
View File
@@ -235,7 +235,7 @@ class Github extends OAuth2
return $this->user;
}
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', 'https://api.github.com/user/repos', ['Authorization: token ' . \urlencode($accessToken)], \json_encode([
'name' => $repositoryName,
+9 -3
View File
@@ -183,12 +183,18 @@ class Gitlab extends OAuth2
*
* @return array
*/
public function createRepository(string $accessToken, string $repositoryName, bool $private): array
public function createRepository(string $accessToken, string $repositoryName, bool $private, string $namespaceId = ''): array
{
$repository = $this->request('POST', $this->getEndpoint() . '/api/v4/projects', ['Authorization: Bearer ' . $accessToken, 'Content-Type: application/json'], \json_encode([
$payload = [
'name' => $repositoryName,
'visibility' => $private ? 'private' : 'public',
]));
];
if (!empty($namespaceId)) {
$payload['namespace_id'] = (int) $namespaceId;
}
$repository = $this->request('POST', $this->getEndpoint() . '/api/v4/projects', ['Authorization: Bearer ' . $accessToken, 'Content-Type: application/json'], \json_encode($payload));
$repository = \json_decode($repository, true) ?? [];
@@ -51,6 +51,7 @@ class Create extends Action
->param('installationId', '', new Text(256), 'Installation Id')
->param('name', '', new Text(256), 'Repository name (slug)')
->param('private', '', new Boolean(false), 'Mark repository public or private')
->param('providerNamespace', '', new Text(256), 'Namespace of the git repository. Defaults to the installation\'s own namespace.', true)
->inject('vcsFactory')
->inject('installationTokens')
->inject('user')
@@ -63,6 +64,7 @@ class Create extends Action
string $installationId,
string $name,
bool $private,
string $providerNamespace,
VcsFactory $vcsFactory,
InstallationTokens $installationTokens,
Document $user,
@@ -99,14 +101,18 @@ class Create extends Action
$accessToken = $installation->getAttribute('personalAccessToken');
try {
$repository = $oauth2->createRepository($accessToken, $name, $private);
if (!empty($providerNamespace)) {
$repository = $oauth2->createRepository($accessToken, $name, $private, $providerNamespace);
} else {
$repository = $oauth2->createRepository($accessToken, $name, $private);
}
} catch (\Throwable $exception) {
throw new Exception(Exception::GENERAL_PROVIDER_FAILURE, "VCS provider failed to process the request: " . $exception->getMessage());
}
} else {
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$vcs = $vcsFactory->fromInstallation($installation);
$owner = $vcs->getOwnerName($providerInstallationId);
$owner = !empty($providerNamespace) ? $providerNamespace : $vcs->getOwnerName($providerInstallationId);
try {
$repository = $vcs->createRepository($owner, $name, $private);