-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add Gitea commit endpoints (getCommit, getLatestCommit) #66
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
Changes from all commits
d54667d
698def7
81e6419
a905862
0552bea
49cfca8
66eaa7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,12 +365,87 @@ public function testUpdateComment(): void | |
|
|
||
| public function testGetCommit(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| $repositoryName = 'test-get-commit-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false); | ||
|
|
||
| $customMessage = 'Test commit message'; | ||
| $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test Commit', $customMessage); | ||
|
|
||
| $latestCommit = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main'); | ||
| $commitHash = $latestCommit['commitHash']; | ||
|
|
||
| $result = $this->vcsAdapter->getCommit(self::$owner, $repositoryName, $commitHash); | ||
|
|
||
| $this->assertIsArray($result); | ||
| $this->assertArrayHasKey('commitHash', $result); | ||
| $this->assertArrayHasKey('commitMessage', $result); | ||
| $this->assertArrayHasKey('commitAuthor', $result); | ||
| $this->assertArrayHasKey('commitUrl', $result); | ||
| $this->assertArrayHasKey('commitAuthorAvatar', $result); | ||
| $this->assertArrayHasKey('commitAuthorUrl', $result); | ||
|
|
||
| $this->assertSame($commitHash, $result['commitHash']); | ||
| $this->assertStringContainsString($customMessage, $result['commitMessage']); | ||
| $this->assertNotEmpty($result['commitAuthor']); | ||
| $this->assertNotEmpty($result['commitUrl']); | ||
|
|
||
jaysomani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName); | ||
| } | ||
|
Comment on lines
+368
to
393
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure repo cleanup runs on failing happy-path tests too. In Proposed resilient cleanup pattern public function testGetCommit(): void
{
$repositoryName = 'test-get-commit-' . \uniqid();
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
-
- $customMessage = 'Test commit message';
- $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test Commit', $customMessage);
-
- $latestCommit = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main');
- $commitHash = $latestCommit['commitHash'];
-
- $result = $this->vcsAdapter->getCommit(self::$owner, $repositoryName, $commitHash);
-
- $this->assertIsArray($result);
- $this->assertArrayHasKey('commitHash', $result);
- $this->assertArrayHasKey('commitMessage', $result);
- $this->assertArrayHasKey('commitAuthor', $result);
- $this->assertArrayHasKey('commitUrl', $result);
- $this->assertArrayHasKey('commitAuthorAvatar', $result);
- $this->assertArrayHasKey('commitAuthorUrl', $result);
-
- $this->assertSame($commitHash, $result['commitHash']);
- $this->assertStringContainsString($customMessage, $result['commitMessage']);
- $this->assertNotEmpty($result['commitAuthor']);
- $this->assertNotEmpty($result['commitUrl']);
-
- $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
+ try {
+ $customMessage = 'Test commit message';
+ $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test Commit', $customMessage);
+
+ $latestCommit = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main');
+ $commitHash = $latestCommit['commitHash'];
+
+ $result = $this->vcsAdapter->getCommit(self::$owner, $repositoryName, $commitHash);
+
+ $this->assertIsArray($result);
+ $this->assertArrayHasKey('commitHash', $result);
+ $this->assertArrayHasKey('commitMessage', $result);
+ $this->assertArrayHasKey('commitAuthor', $result);
+ $this->assertArrayHasKey('commitUrl', $result);
+ $this->assertArrayHasKey('commitAuthorAvatar', $result);
+ $this->assertArrayHasKey('commitAuthorUrl', $result);
+
+ $this->assertSame($commitHash, $result['commitHash']);
+ $this->assertStringContainsString($customMessage, $result['commitMessage']);
+ $this->assertNotEmpty($result['commitAuthor']);
+ $this->assertNotEmpty($result['commitUrl']);
+ } finally {
+ $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
+ }
}
public function testGetLatestCommit(): void
{
$repositoryName = 'test-get-latest-commit-' . \uniqid();
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
-
- $firstMessage = 'First commit';
- $secondMessage = 'Second commit';
- $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test', $firstMessage);
- $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test content', $secondMessage);
-
- $result = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main');
-
- $this->assertIsArray($result);
- $this->assertArrayHasKey('commitHash', $result);
- $this->assertArrayHasKey('commitMessage', $result);
- $this->assertArrayHasKey('commitAuthor', $result);
- $this->assertArrayHasKey('commitUrl', $result);
- $this->assertArrayHasKey('commitAuthorAvatar', $result);
- $this->assertArrayHasKey('commitAuthorUrl', $result);
-
- $this->assertNotEmpty($result['commitHash']);
- $this->assertStringContainsString($secondMessage, $result['commitMessage']);
- $this->assertNotEmpty($result['commitAuthor']);
- $this->assertNotEmpty($result['commitUrl']);
-
- $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
+ try {
+ $firstMessage = 'First commit';
+ $secondMessage = 'Second commit';
+ $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test', $firstMessage);
+ $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test content', $secondMessage);
+
+ $result = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main');
+
+ $this->assertIsArray($result);
+ $this->assertArrayHasKey('commitHash', $result);
+ $this->assertArrayHasKey('commitMessage', $result);
+ $this->assertArrayHasKey('commitAuthor', $result);
+ $this->assertArrayHasKey('commitUrl', $result);
+ $this->assertArrayHasKey('commitAuthorAvatar', $result);
+ $this->assertArrayHasKey('commitAuthorUrl', $result);
+
+ $this->assertNotEmpty($result['commitHash']);
+ $this->assertStringContainsString($secondMessage, $result['commitMessage']);
+ $this->assertNotEmpty($result['commitAuthor']);
+ $this->assertNotEmpty($result['commitUrl']);
+ } finally {
+ $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName);
+ }
}Also applies to: 397-421 🤖 Prompt for AI Agents |
||
|
|
||
| public function testGetLatestCommit(): void | ||
| { | ||
| $this->markTestSkipped('Will be implemented in follow-up PR'); | ||
| $repositoryName = 'test-get-latest-commit-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false); | ||
|
|
||
| $firstMessage = 'First commit'; | ||
| $secondMessage = 'Second commit'; | ||
| $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test', $firstMessage); | ||
| $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test content', $secondMessage); | ||
|
|
||
| $result = $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'main'); | ||
|
|
||
| $this->assertIsArray($result); | ||
| $this->assertArrayHasKey('commitHash', $result); | ||
| $this->assertArrayHasKey('commitMessage', $result); | ||
| $this->assertArrayHasKey('commitAuthor', $result); | ||
| $this->assertArrayHasKey('commitUrl', $result); | ||
| $this->assertArrayHasKey('commitAuthorAvatar', $result); | ||
| $this->assertArrayHasKey('commitAuthorUrl', $result); | ||
|
|
||
| $this->assertNotEmpty($result['commitHash']); | ||
jaysomani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertStringContainsString($secondMessage, $result['commitMessage']); | ||
| $this->assertNotEmpty($result['commitAuthor']); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above - assertHasKey and assertEmpty are most minimal assertions - everytime we can assert value, we should. For example here I would assertSame for commit hash, message, and author (author only if possible, not sure) |
||
| $this->assertNotEmpty($result['commitUrl']); | ||
|
|
||
| $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName); | ||
| } | ||
|
|
||
| public function testGetCommitWithInvalidSha(): void | ||
| { | ||
| $repositoryName = 'test-get-commit-invalid-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false); | ||
| $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test'); | ||
|
|
||
| try { | ||
| $this->expectException(\Exception::class); | ||
| $this->vcsAdapter->getCommit(self::$owner, $repositoryName, 'invalid-sha-12345'); | ||
| } finally { | ||
| $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName); | ||
| } | ||
| } | ||
jaysomani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public function testGetLatestCommitWithInvalidBranch(): void | ||
| { | ||
| $repositoryName = 'test-get-latest-commit-invalid-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(self::$owner, $repositoryName, false); | ||
| $this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test'); | ||
|
|
||
| try { | ||
| $this->expectException(\Exception::class); | ||
| $this->vcsAdapter->getLatestCommit(self::$owner, $repositoryName, 'non-existing-branch'); | ||
| } finally { | ||
| $this->vcsAdapter->deleteRepository(self::$owner, $repositoryName); | ||
| } | ||
| } | ||
|
|
||
| public function testGetEvent(): void | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.