diff --git a/src/Appwrite/Auth/OAuth2/Gitea.php b/src/Appwrite/Auth/OAuth2/Gitea.php index 390189fc72..3494c3b622 100644 --- a/src/Appwrite/Auth/OAuth2/Gitea.php +++ b/src/Appwrite/Auth/OAuth2/Gitea.php @@ -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, diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index f80c067daa..d8f6bfaa6d 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -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, diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index fb6244bb52..db72385a12 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -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) ?? []; diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Create.php index 1277f44373..d8dae58f3b 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Create.php @@ -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);