Skip to content

Commit 4b9c470

Browse files
author
Your Name
committed
fix: Address bot review feedback
- Remove limit=1 from getPullRequestFromBranch to fetch all PRs - Add branch parameter to createFile for branch-specific commits - Update tests to commit files to feature branches
1 parent 3277ea7 commit 4b9c470

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/VCS/Adapter/Git/Gitea.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,25 @@ public function getRepositoryTree(string $owner, string $repositoryName, string
188188
* @param string $message Commit message
189189
* @return array<mixed> Response from API
190190
*/
191-
public function createFile(string $owner, string $repositoryName, string $filepath, string $content, string $message = 'Add file'): array
191+
public function createFile(string $owner, string $repositoryName, string $filepath, string $content, string $message = 'Add file', string $branch = ''): array
192192
{
193193
$url = "/repos/{$owner}/{$repositoryName}/contents/{$filepath}";
194194

195+
$payload = [
196+
'content' => base64_encode($content),
197+
'message' => $message
198+
];
199+
200+
// Add branch if specified
201+
if (!empty($branch)) {
202+
$payload['branch'] = $branch;
203+
}
204+
195205
$response = $this->call(
196206
self::METHOD_POST,
197207
$url,
198208
['Authorization' => "token $this->accessToken"],
199-
[
200-
'content' => base64_encode($content),
201-
'message' => $message
202-
]
209+
$payload
203210
);
204211

205212
$responseHeaders = $response['headers'] ?? [];
@@ -446,7 +453,7 @@ public function getPullRequest(string $owner, string $repositoryName, int $pullR
446453

447454
public function getPullRequestFromBranch(string $owner, string $repositoryName, string $branch): array
448455
{
449-
$url = "/repos/{$owner}/{$repositoryName}/pulls?state=open&sort=recentupdate&limit=1";
456+
$url = "/repos/{$owner}/{$repositoryName}/pulls?state=open&sort=recentupdate";
450457

451458
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "token $this->accessToken"]);
452459

tests/VCS/Adapter/GiteaTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testCommentWorkflow(): void
105105

106106
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
107107
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'comment-test', 'main');
108-
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test');
108+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test', 'Add test file', 'comment-test');
109109

110110
$pr = $this->vcsAdapter->createPullRequest(
111111
self::$owner,
@@ -151,7 +151,7 @@ public function testGetComment(): void
151151

152152
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
153153
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'test-branch', 'main');
154-
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test');
154+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'test.txt', 'test', 'Add test', 'test-branch');
155155

156156
// Create PR
157157
$pr = $this->vcsAdapter->createPullRequest(
@@ -445,14 +445,10 @@ public function testGetPullRequest(): void
445445
$repositoryName = 'test-get-pull-request-' . \uniqid();
446446
$this->vcsAdapter->createRepository(self::$owner, $repositoryName, false);
447447

448-
// Create initial file on main branch
449448
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
450-
451-
// Create feature branch and add file
452449
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'feature-branch', 'main');
453-
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'feature.txt', 'feature content');
450+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'feature.txt', 'feature content', 'Add feature', 'feature-branch');
454451

455-
// Create pull request
456452
$pr = $this->vcsAdapter->createPullRequest(
457453
self::$owner,
458454
$repositoryName,
@@ -664,7 +660,7 @@ public function testGetPullRequestFromBranch(): void
664660

665661
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'README.md', '# Test');
666662
$this->vcsAdapter->createBranch(self::$owner, $repositoryName, 'my-feature', 'main');
667-
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'feature.txt', 'content');
663+
$this->vcsAdapter->createFile(self::$owner, $repositoryName, 'feature.txt', 'content', 'Add feature', 'my-feature');
668664

669665
// Create PR
670666
$pr = $this->vcsAdapter->createPullRequest(

0 commit comments

Comments
 (0)