Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/VCS/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ abstract public function getRepository(string $owner, string $repositoryName): a
/**
* Create new repository
*
* @param string $project Project the repository belongs to, where the provider groups them
* @return array<mixed> Details of new repository
*/
abstract public function createRepository(string $owner, string $repositoryName, bool $private): array;
abstract public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array;

/**
* Delete repository
Expand Down
13 changes: 9 additions & 4 deletions src/VCS/Adapter/Git/Bitbucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,20 @@ private function normalizeRepository(array $repository): array
return $repository;
}

public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array
Comment thread
Meldiron marked this conversation as resolved.
Comment thread
greptile-apps[bot] marked this conversation as resolved.
{
$url = "/repositories/{$owner}/{$repositoryName}";

$response = $this->call(self::METHOD_POST, $url, ['Authorization' => $this->authorizationHeader()], [
$payload = [
'scm' => 'git',
'name' => $repositoryName,
'is_private' => $private,
]);
];

if ($project !== '') {
$payload['project'] = ['key' => $project];
}

$response = $this->call(self::METHOD_POST, $url, ['Authorization' => $this->authorizationHeader()], $payload);

$responseHeaders = $response['headers'] ?? [];
$statusCode = $responseHeaders['status-code'] ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function initializeVariables(string $installationId, string $privateKey,
*
* @return array<mixed> Details of new repository
*/
public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array
{
$url = "/orgs/{$owner}/repos";

Expand Down
2 changes: 1 addition & 1 deletion src/VCS/Adapter/Git/GitLab.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private function getNamespaceId(string $owner): string
return $owner;
}

public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array
{
$namespaceId = (int) $this->getNamespaceId($owner);

Expand Down
2 changes: 1 addition & 1 deletion src/VCS/Adapter/Git/Gitea.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function generateAccessToken(string $privateKey, string $appId): void
*
* @return array<mixed> Details of new repository
*/
public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not add project to all adapters, unless we know it is a feature. If project is bitbucket specific concept, we need to keep it bitbucket only

{
$url = "/orgs/{$owner}/repos";

Expand Down
2 changes: 1 addition & 1 deletion src/VCS/Adapter/Git/Gogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getBranchUrl(string $owner, string $repositoryName, string $bran
*
* @return array<mixed> Details of new repository
*/
public function createRepository(string $owner, string $repositoryName, bool $private): array
public function createRepository(string $owner, string $repositoryName, bool $private, string $project = ''): array
{
$url = "/org/{$owner}/repos";

Expand Down
13 changes: 13 additions & 0 deletions tests/VCS/Adapter/BitbucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Utopia\Cache\Cache;
use Utopia\System\System;
use Utopia\Tests\Base;
use Exception;
use Utopia\VCS\Adapter\Git\Bitbucket;

class BitbucketTest extends Base
Expand Down Expand Up @@ -175,6 +176,18 @@ private function eventActor(): array
* Bitbucket only names the author in a raw "Name <email>" string; a commit
* linked to an account is named by the account instead.
*/
public function testCreateRepositoryInAnUnknownProjectFails(): void
Comment thread
Meldiron marked this conversation as resolved.
{
$this->expectException(Exception::class);

$this->vcsAdapter->createRepository(
static::$owner,
'test-create-repository-unknown-project-' . \uniqid(),
false,
'NOSUCHPROJECTKEY'
);
}

public function testGetEventPushWithLinkedAuthor(): void
{
$payload = json_decode($this->pushPayload(static::$defaultBranch), true);
Expand Down
Loading