-
Notifications
You must be signed in to change notification settings - Fork 6
Initial commit for gitea #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2c6095
Initial commit for gitea
c1cc30e
updated based with docker file to include initial setup based on disc…
jaysomani 93e05c8
feat: refactor VCS adapters to support both App and OAuth flows
jaysomani 6624ef9
updated with org creation based on discussion
jaysomani 2d7ef0c
updated /org/ with /orgs/
jaysomani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\VCS\Adapter\Git; | ||
|
|
||
| use Exception; | ||
| use Utopia\Cache\Cache; | ||
| use Utopia\VCS\Adapter\Git; | ||
|
|
||
| class Gitea extends Git | ||
| { | ||
| protected string $endpoint = 'http://gitea:3000/api/v1'; | ||
|
|
||
| protected string $accessToken; | ||
|
|
||
| protected string $refreshToken; | ||
|
|
||
| protected string $giteaUrl; | ||
|
|
||
| protected Cache $cache; | ||
|
|
||
| /** | ||
| * Global Headers | ||
| * | ||
| * @var array<string, string> | ||
| */ | ||
| protected $headers = ['content-type' => 'application/json']; | ||
|
|
||
| public function __construct(Cache $cache) | ||
| { | ||
| $this->cache = $cache; | ||
| } | ||
|
|
||
| /** | ||
| * Get Adapter Name | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return 'gitea'; | ||
| } | ||
|
|
||
| /** | ||
| * Gitea Initialisation with access token from OAuth2 flow. | ||
| * | ||
| * Note: Gitea uses OAuth2 instead of GitHub's App Installation flow. | ||
| * The parameters are adapted to maintain interface compatibility: | ||
| * - $installationId is used to pass the access token | ||
| * - $privateKey is used to pass the refresh token | ||
| * - $githubAppId is used to pass the Gitea instance URL | ||
| */ | ||
|
jaysomani marked this conversation as resolved.
|
||
| public function initializeVariables(string $installationId, string $privateKey, string $githubAppId): void | ||
|
jaysomani marked this conversation as resolved.
Outdated
|
||
| { | ||
| $this->accessToken = $installationId; | ||
|
jaysomani marked this conversation as resolved.
Outdated
|
||
| $this->refreshToken = $privateKey; | ||
| $this->giteaUrl = rtrim($githubAppId, '/'); | ||
| $this->endpoint = $this->giteaUrl . '/api/v1'; | ||
|
jaysomani marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Generate Access Token | ||
| * | ||
| * Note: This method is required by the Adapter interface but is not used for Gitea. | ||
| * Gitea uses OAuth2 tokens that are provided directly via initializeVariables(). | ||
| */ | ||
| protected function generateAccessToken(string $privateKey, string $githubAppId): void | ||
| { | ||
| // Not applicable for Gitea - OAuth2 tokens are passed directly | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Create new repository | ||
| * | ||
| * @return array<mixed> Details of new repository | ||
| */ | ||
| public function createRepository(string $owner, string $repositoryName, bool $private): array | ||
| { | ||
| $url = "/user/repos"; | ||
|
Meldiron marked this conversation as resolved.
Outdated
|
||
|
|
||
| $response = $this->call(self::METHOD_POST, $url, ['Authorization' => "token $this->accessToken"], [ | ||
| 'name' => $repositoryName, | ||
| 'private' => $private, | ||
| ]); | ||
|
|
||
| return $response['body'] ?? []; | ||
| } | ||
|
jaysomani marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // Stub methods to satisfy abstract class requirements | ||
| // These will be implemented in follow-up PRs | ||
|
|
||
| public function searchRepositories(string $owner, int $page, int $per_page, string $search = ''): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getRepository(string $owner, string $repositoryName): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
|
jaysomani marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public function getRepositoryName(string $repositoryId): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getRepositoryTree(string $owner, string $repositoryName, string $branch, bool $recursive = false): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function listRepositoryLanguages(string $owner, string $repositoryName): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getRepositoryContent(string $owner, string $repositoryName, string $path, string $ref = ''): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function listRepositoryContents(string $owner, string $repositoryName, string $path = '', string $ref = ''): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function deleteRepository(string $owner, string $repositoryName): bool | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function createComment(string $owner, string $repositoryName, int $pullRequestNumber, string $comment): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getComment(string $owner, string $repositoryName, string $commentId): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function updateComment(string $owner, string $repositoryName, int $commentId, string $comment): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getUser(string $username): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getOwnerName(string $installationId): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getPullRequest(string $owner, string $repositoryName, int $pullRequestNumber): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getPullRequestFromBranch(string $owner, string $repositoryName, string $branch): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function listBranches(string $owner, string $repositoryName): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getCommit(string $owner, string $repositoryName, string $commitHash): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getLatestCommit(string $owner, string $repositoryName, string $branch): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function updateCommitStatus(string $repositoryName, string $commitHash, string $owner, string $state, string $description = '', string $target_url = '', string $context = ''): void | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function getEvent(string $event, string $payload): array | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
|
|
||
| public function validateWebhookEvent(string $payload, string $signature, string $signatureKey): bool | ||
| { | ||
| throw new Exception("Not implemented yet"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Tests\VCS\Adapter; | ||
|
|
||
| use Utopia\Cache\Adapter\None; | ||
| use Utopia\Cache\Cache; | ||
| use Utopia\System\System; | ||
| use Utopia\Tests\Base; | ||
| use Utopia\VCS\Adapter\Git; | ||
| use Utopia\VCS\Adapter\Git\Gitea; | ||
|
|
||
|
Meldiron marked this conversation as resolved.
|
||
| class GiteaTest extends Base | ||
|
Meldiron marked this conversation as resolved.
|
||
| { | ||
| private static bool $setupDone = false; | ||
|
jaysomani marked this conversation as resolved.
Outdated
|
||
| private static string $accessToken = ''; | ||
|
|
||
| protected function createVCSAdapter(): Git | ||
| { | ||
| return new Gitea(new Cache(new None())); | ||
| } | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| if (!self::$setupDone) { | ||
| $this->setupGitea(); | ||
| self::$setupDone = true; | ||
| } | ||
|
|
||
| $this->vcsAdapter = new Gitea(new Cache(new None())); | ||
| $this->vcsAdapter->initializeVariables(self::$accessToken, '', System::getEnv('GITEA_URL') ?? 'http://gitea:3000'); | ||
| } | ||
|
|
||
| private function setupGitea(): void | ||
| { | ||
| $tokenFile = '/data/gitea/token.txt'; | ||
|
|
||
| if (file_exists($tokenFile)) { | ||
| self::$accessToken = trim(file_get_contents($tokenFile)); | ||
| } | ||
| } | ||
|
Meldiron marked this conversation as resolved.
|
||
|
|
||
| public function testCreateRepository(): void | ||
| { | ||
| $owner = System::getEnv('GITEA_TEST_OWNER'); | ||
|
Meldiron marked this conversation as resolved.
Outdated
jaysomani marked this conversation as resolved.
Outdated
|
||
| $repositoryName = 'test-repo-' . time(); | ||
|
|
||
| $result = $this->vcsAdapter->createRepository($owner, $repositoryName, false); | ||
|
|
||
| $this->assertIsArray($result); | ||
| $this->assertArrayHasKey('name', $result); | ||
| $this->assertSame($repositoryName, $result['name']); | ||
| $this->assertArrayHasKey('owner', $result); | ||
| $this->assertSame($owner, $result['owner']['login']); | ||
| } | ||
|
|
||
| public function testGetComment(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetRepositoryName(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetRepositoryTree(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetRepositoryContent(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testListRepositoryContents(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetPullRequest(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGenerateCloneCommand(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGenerateCloneCommandWithCommitHash(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGenerateCloneCommandWithTag(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testUpdateComment(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetCommit(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testGetLatestCommit(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
|
||
| public function testgetEvent(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| } | ||
|
jaysomani marked this conversation as resolved.
Outdated
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.