diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index ad42715..8a17b77 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -464,11 +464,13 @@ public function getPullRequestFromBranch(string $owner, string $repositoryName, * * @param string $owner Owner name of the repository * @param string $repositoryName Name of the GitHub repository + * @param int $page Page number for pagination + * @param int $perPage Number of results per page * @return array List of branch names as array */ - public function listBranches(string $owner, string $repositoryName): array + public function listBranches(string $owner, string $repositoryName, int $page = 1, int $perPage = 30): array { - $url = "/repos/$owner/$repositoryName/branches"; + $url = "/repos/$owner/$repositoryName/branches?page=$page&per_page=$perPage"; $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]); diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index 30661c0..3edd978 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -426,4 +426,22 @@ public function testGetLatestCommit(): void $this->assertSame('https://avatars.githubusercontent.com/u/43381712?v=4', $commitDetails['commitAuthorAvatar']); $this->assertSame('https://github.com/vermakhushboo', $commitDetails['commitAuthorUrl']); } + + public function testListBranches(): void + { + $owner = 'test-kh'; + $repositoryName = 'test2'; + + // Basic test + $branches = $this->vcsAdapter->listBranches($owner, $repositoryName); + $this->assertIsArray($branches); + $this->assertNotEmpty($branches); + $this->assertContains('main', $branches); + $this->assertContains('test', $branches); + + // Test with pagination params + $branches = $this->vcsAdapter->listBranches($owner, $repositoryName, 1, 1); + $this->assertIsArray($branches); + $this->assertCount(1, $branches); + } }