fix(bitbucket): use FindBranch and paginate PR listing in pullrequest…#8584
Merged
olblak merged 2 commits intoApr 25, 2026
Merged
Conversation
… action isRemoteBranchesExist() fetched all remote branches via a paginated list scan (Page: 1, Size: 30 with no follow-through) to check whether the source and target branches exist. On repositories with more than 30 branches this silently returned false, causing CreateAction to log "skipping pull request creation" at Debug level and exit with nil — the job appeared green with no PR and no visible explanation. Replace the list scan with two direct FindBranch calls (one per branch). This mirrors the approach used by GitHub's GraphQL implementation and is O(1) regardless of repository branch count. A 404 response from FindBranch is treated as a missing branch and logged at Warning level so the failure is visible without --debug. Also fix isPullRequestExist() which had the same Size: 30 truncation: it now paginates using resp.Page.Next until all open pull requests have been checked. Fixes the same class of bug as updatecli#1905 (GitLab) which was introduced when the Bitbucket Cloud plugin was added in updatecli#2847.
Member
|
Thanks for the fix |
Member
|
And thank you for the clear explanation. |
Member
|
@roulettedares Could you confirm that you tested this pullrequest on a bitbucket repository? |
Contributor
Author
|
it's been consistently working on repos with more than 30 branches |
Member
|
Thank you awesome, then I'll skip the manual testing this time |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
isRemoteBranchesExist() and isPullRequestExist() both fetch only the first page of results (Page: 1, Size: 30) with no follow-through pagination. On repositories with more than 30 branches, if either the source branch or target branch (main)
sorts alphabetically past position 30, the function silently returns false — causing CreateAction to log "skipping pull request creation" at Debug level and exit with nil. The job appears green with no PR created and no visible explanation in
normal log output.
Root cause / history
The Stash plugin (PR #1246, March 2023) used ListBranches with a manual name-match loop. The Bitbucket Cloud plugin (PR #2847, October 2024) copy-pasted this approach verbatim; no reviewer questioned it. FindBranch has been present in both
go-scm Bitbucket drivers since 2018 and was never unavailable. Branch names are never wildcards or patterns — there was no reason to list all branches. PR #5133 silently switched to FindBranch elsewhere in a refactor, but the Bitbucket Cloud
plugin was not updated.
Fix
Replace the ListBranches scan in isRemoteBranchesExist() with two direct FindBranch calls — one per branch. This is O(1) regardless of branch count, matches the approach used by GitHub's GraphQL ref(qualifiedName:) lookup, and treats a 404
response as "branch not found" logged at Warning level so the failure is visible without --debug.
Also fix isPullRequestExist() which has the same Size: 30 truncation: it now paginates using resp.Page.Next until all open pull requests have been checked.
Relates to #1905 (same class of bug observed in GitLab). Introduced in #2847.
Test
To test this pull request, you can run the following commands:
Additional Information
Checklist