I’m working on a bitbucket plugin (BB server v6.10.0) which tries to get all the commits for a PR.
Originally the code used CommitsBetweenRequest.Builder(PullRequest) which would find all commits from a feature branch that had been merged via a merge commit but would not find the “new commits” for a rebased or squashed commits from a feature branch to the target (or to ref) branch.
I modified the code as follows (from memory so maybe a few typos…):
CommitsBetweenRequest.Builder builder = new CommitsBetweenRequest.Builder(pullRequest); PullRequestRef toRef = pullRequest.getToRef(); CommitsBetweenRequest request = builder.build(); Iteratable<Commit> pullCommits = commitService.getCommitsBetween(request, ....)
Now for the case where the repo is using merge commits to merge from features branches into master, the above search is finding commits after the merge commit.
A --- B --- C --- D --- E --- F --- G --- H --- I \---B1 --- B2 -/
- A through to F is master
- B is the start of the feature branch
- E is the merge commit merged via a PR
- F, G, H and I are commits after the feature has been merged post PR
However, the code approach above seems to find B1, B2, E, F, G, H and I.
I would like it to find just the commits for the PR, so B1, B2, E.
I would also like it to handle the case where rebase or squash is used to merge post PR, where the Commits in the feature are copied “on top” of where master is so their commit hashes can change (especially if the feature branch commits are squashed onto master).
Would be great if anyone can help me to understand how to use the CommitsBetweenRequest to do what I need.
Thanks in advance…