-
Notifications
You must be signed in to change notification settings - Fork 6
Fix: GitHub branch pagination #98
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
+70
−7
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78507b1
Fix GitHub branch pagination
HarshMN2345 6f3a606
Address GitHub branch pagination review
HarshMN2345 67038d7
Merge remote-tracking branch 'origin/main' into claude/nice-elbakyan-…
HarshMN2345 a413e42
Implement createBranch, add page param to listBranches, rewrite pagin…
HarshMN2345 6e88252
Remove loop from listBranches, use page/perPage for single-page fetch
HarshMN2345 9d1fde0
Improve test coverage
Meldiron 5e4b936
Apply suggestion from @Meldiron
Meldiron 0fdd494
fix: use assertEqualsCanonicalizing for branch list order independence
HarshMN2345 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
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 |
|---|---|---|
|
|
@@ -525,6 +525,55 @@ public function testGetCommitWithInvalidHash(): void | |
| } | ||
| } | ||
|
|
||
| public function testListBranchesPagination(): void | ||
| { | ||
| $repositoryName = 'test-list-branches-pages-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(static::$owner, $repositoryName, false); | ||
|
|
||
| try { | ||
| $this->vcsAdapter->createFile(static::$owner, $repositoryName, 'README.md', '# Test'); | ||
| $this->vcsAdapter->createBranch(static::$owner, $repositoryName, 'branch-a', static::$defaultBranch); | ||
| $this->vcsAdapter->createBranch(static::$owner, $repositoryName, 'branch-b', static::$defaultBranch); | ||
|
|
||
| /** @var GitHub $adapter */ | ||
| $adapter = $this->vcsAdapter; | ||
|
|
||
| $page1 = $adapter->listBranches(static::$owner, $repositoryName, 1, 1); | ||
| $this->assertSame(['branch-a'], $page1); | ||
|
|
||
| $page2 = $adapter->listBranches(static::$owner, $repositoryName, 1, 2); | ||
| $this->assertSame(['branch-b'], $page2); | ||
|
|
||
| $all = $adapter->listBranches(static::$owner, $repositoryName, 100, 1); | ||
| $this->assertEqualsCanonicalizing([static::$defaultBranch, 'branch-a', 'branch-b'], $all); | ||
| } finally { | ||
|
Meldiron marked this conversation as resolved.
|
||
| $this->vcsAdapter->deleteRepository(static::$owner, $repositoryName); | ||
| } | ||
| } | ||
|
|
||
| public function testListBranchesEmptyRepository(): void | ||
| { | ||
| $repositoryName = 'test-list-branches-empty-' . \uniqid(); | ||
| $this->vcsAdapter->createRepository(static::$owner, $repositoryName, false); | ||
|
|
||
| try { | ||
| $branches = $this->vcsAdapter->listBranches(static::$owner, $repositoryName); | ||
|
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. If failing because of default branch, find a way to deleteBranch() |
||
|
|
||
| $this->assertIsArray($branches); | ||
| $this->assertEmpty($branches); | ||
| } finally { | ||
| $this->vcsAdapter->deleteRepository(static::$owner, $repositoryName); | ||
| } | ||
| } | ||
|
|
||
| public function testListBranchesNonExistingRepository(): void | ||
| { | ||
| $branches = $this->vcsAdapter->listBranches(static::$owner, 'non-existing-repo-' . \uniqid()); | ||
|
|
||
| $this->assertIsArray($branches); | ||
| $this->assertEmpty($branches); | ||
| } | ||
|
|
||
| public function testGetLatestCommit(): void | ||
| { | ||
| $repositoryName = 'test-get-latest-commit-' . \uniqid(); | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createBranchsilently swallows API errorsThe method doesn't inspect the HTTP status code before returning. If GitHub rejects the request (e.g., 422 "Reference already exists", 404 branch not found, 403 permission denied),
$response['body']contains an error object like{"message":"Reference already exists",...}andcreateBranchreturns it as if it succeeded. By contrast,listBranchesin this same PR correctly gates its output on$statusCode < 200 || $statusCode >= 300. Callers ofcreateBranchhave no way to distinguish a successful ref payload from an error payload without parsing themessagekey themselves.