Bitbucket: find the pull request for a commit
You have a commit ID, or a line in blame that looks wrong, and you want the pull request it came through: the discussion, who approved it, the builds. Bitbucket Cloud and Bitbucket Data Center each answer this with one REST call, and Cloud also on the commit's page. From Atlassian's REST references, Bitbucket Cloud: Pullrequests (List pull requests that contain a commit) and Bitbucket Data Center: Repository.
Bitbucket Cloud on the web: Go to pull request
- Open the commit's page on bitbucket.org and choose Go to pull request.
- The first time someone does this, Bitbucket installs the Pull Request Commit Links app. The REST call below needs that app; until it is installed, the call does not work.
Bitbucket Cloud: the REST call
GET https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/commit/{commit}/pullrequests- The answer is a paginated list of the pull requests in which the commit was reviewed;
pageandpagelenpage through it. - Scopes:
pullrequestfor OAuth 2.0;read:pullrequest:bitbucketfor an API token. - Besides 200, the reference lists 202 Accepted and 404 Not Found. On a 404, choose Go to pull request once on a commit's page in that repository (the step above), then ask again; on a 202, ask again a little later.
Bitbucket Data Center: the REST call
GET {your server}/rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/pull-requests- It returns a page of the pull requests in that repository that contain the commit.
startandlimitpage through it; withoutlimita page has 25. - You must be signed in (for example with an HTTP access token) and have access to the repository.
The number in the merge message
On Bitbucket Cloud, the default message of a merge commit and of a squash begins Merged in <source branch> (pull request #<number>) (our page on the default messages). So, unless someone changed the message when merging, git log --oneline --grep="(pull request #" origin/main lists those commits with their pull request numbers. To find the merge that brought a given commit into main, in Bash (Git Bash on Windows), replace <commit>:
for m in $(git rev-list --first-parent --merges --reverse origin/main); do
git merge-base --is-ancestor <commit> $m && { git log -1 --oneline $m; break; }
done
It walks the merges of origin/main from the oldest and prints the first one that contains the commit. After a squash or a fast-forward there is no such merge: use the REST call above.
Find Pull Request on Bitbucket in IntelliJ IDEA
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pull requests that wait for your review in an IDE tool window, with their diffs and discussions. From version 1.0.86, Find Pull Request on Bitbucket is on the annotate (blame) gutter and on a commit in the Git log. It asks the REST call above and opens the pull request that brought the commit in; when there are several it lists them to choose from. On Bitbucket Cloud it says in words when Bitbucket is still preparing the answer (202) or when the commit links are not on yet (404). An open one that is in your list opens in the tool window, where approving, commenting and merging are. Finding the pull request is free; creating, approving, commenting and merging are Pro, with a 30-day trial. It also works with Bitbucket Data Center (beta).
Get it on JetBrains Marketplace
Bitbucket and Atlassian are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: default title and merge message · Bitbucket merge strategies · revert a pull request · 日本語