Skip to content

fix(bitbucket): use FindBranch and paginate PR listing in pullrequest…#8584

Merged
olblak merged 2 commits into
updatecli:mainfrom
roulettedares:fix/bitbucket-pullrequest-branch-pagination
Apr 25, 2026
Merged

fix(bitbucket): use FindBranch and paginate PR listing in pullrequest…#8584
olblak merged 2 commits into
updatecli:mainfrom
roulettedares:fix/bitbucket-pullrequest-branch-pagination

Conversation

@roulettedares

@roulettedares roulettedares commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

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:

cd <to_package_directory>
go test

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

… 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.
@olblak

olblak commented Apr 24, 2026

Copy link
Copy Markdown
Member

Thanks for the fix

@olblak

olblak commented Apr 24, 2026

Copy link
Copy Markdown
Member

And thank you for the clear explanation.

@olblak olblak added bug Something isn't working scm-bitbucket All things related to the bitbucket integration labels Apr 24, 2026
@olblak

olblak commented Apr 24, 2026

Copy link
Copy Markdown
Member

@roulettedares Could you confirm that you tested this pullrequest on a bitbucket repository?

@roulettedares

Copy link
Copy Markdown
Contributor Author

it's been consistently working on repos with more than 30 branches

@olblak

olblak commented Apr 25, 2026

Copy link
Copy Markdown
Member

Thank you awesome, then I'll skip the manual testing this time

@olblak olblak merged commit 7b197e1 into updatecli:main Apr 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scm-bitbucket All things related to the bitbucket integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants