Skip to content

Fix: GitHub branch pagination#98

Open
HarshMN2345 wants to merge 5 commits into
mainfrom
fix/github-branches-pagination
Open

Fix: GitHub branch pagination#98
HarshMN2345 wants to merge 5 commits into
mainfrom
fix/github-branches-pagination

Conversation

@HarshMN2345
Copy link
Copy Markdown
Member

No description provided.

@HarshMN2345 HarshMN2345 requested a review from Meldiron May 11, 2026 11:06
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 11, 2026

Greptile Summary

This PR implements GitHub::createBranch (previously a stub throwing "Not implemented") and upgrades listBranches to accept explicit $perPage and $page parameters with HTTP status-code-based error handling, replacing the previous single-page call that relied on GitHub's default page size of 30.

  • createBranch resolves the latest commit SHA on the source branch and POSTs to /repos/{owner}/{repo}/git/refs; getLatestCommit already validates and throws on unexpected API responses, so error propagation is intact.
  • listBranches now defaults to 100 results per page (the GitHub API maximum), clamps $perPage to [1, 100], and returns an empty array on any non-2xx response. The $page parameter is not clamped, unlike $perPage.
  • A new integration test verifies single-page results, cross-page uniqueness, and full listing with the default page size.

Confidence Score: 5/5

Safe to merge; changes are additive and well-tested, with the only gap being an unvalidated $page parameter.

Both changes are well-scoped: createBranch delegates SHA resolution to an existing validated helper, and listBranches adds defensive status-code handling. The missing lower-bound clamp on $page is an inconsistency but not a blocking defect.

No files require special attention.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitHub.php Implements createBranch (previously threw "Not implemented") and refactors listBranches to accept explicit $perPage/$page params with HTTP status-code validation. $page is forwarded to the API without clamping, unlike $perPage.
tests/VCS/Adapter/GitHubTest.php Adds an integration test for listBranches pagination, verifying single-page results, distinct content across pages, and that all created branches appear in a full-page fetch.

Reviews (5): Last reviewed commit: "Remove loop from listBranches, use page/..." | Re-trigger Greptile

@HarshMN2345 HarshMN2345 requested a review from ChiragAgg5k May 11, 2026 11:07
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment on lines +741 to +743
$perPage = 100;
$currentPage = 1;
$names = [];
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 do proper pagination support with params for this method

Comment thread tests/VCS/Adapter/GitHubTest.php Outdated
$this->assertSame('7ae65094d56edafc48596ffbb77950e741e56412', $commitDetails['commitHash']);
}

public function testListBranchesFetchesAllPages(): void
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.

Instead of mocking, lets just prepare repository with 2 or 3 branches, and make sure it works fine with small pages

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 make sure to make test consistant with others. Thiis is not pattern we have anywhere else in tests in this repo

Comment thread tests/VCS/Adapter/GitHubTest.php Outdated
$this->assertSame('7ae65094d56edafc48596ffbb77950e741e56412', $commitDetails['commitHash']);
}

public function testListBranchesFetchesMultiplePages(): void
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.

Rewrite repositories

Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
* @return array<string> List of branch names as array
*/
public function listBranches(string $owner, string $repositoryName): array
public function listBranches(string $owner, string $repositoryName, int $perPage = 100): 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.

Support page (consistency)

…ation test

- Implement createBranch using GitHub refs API
- Add page parameter to listBranches for consistency with other methods
- Rewrite testListBranchesFetchesMultiplePages to use a real created repository
  with actual branches instead of a hardcoded external repo
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants