Change the destination branch, title or description of a Bitbucket pull request
A pull request opened against the wrong branch does not have to be declined and opened again. Its destination branch can be changed while it is open, together with the title, the description and the reviewers. Below is where that is, when Bitbucket Data Center refuses it, and the reviewers problem that catches scripts, from Atlassian's Create a pull request (Data Center 10.5) and the REST references for Bitbucket Cloud and Data Center.
On the web page
On Bitbucket Data Center, select Edit on the pull request's page. The form has the title, the description, the reviewers and the destination branch. To set a new destination branch you need Read permission on that branch.
On Bitbucket Cloud, Edit on the pull request opens the same kind of form. Atlassian's REST reference describes the update as one that "can be used to change the pull request's branches or description", and adds that "only open pull requests can be mutated". A declined pull request on Cloud cannot be reopened, so this is the step to take before declining one that only points at the wrong branch (decline and reopen).
When Data Center refuses the new destination branch
The Data Center REST reference lists the cases in which a change of destination branch answers 409:
- another open pull request already goes from the same source branch into the new destination (the same answer when creating one);
- the source branch and the new destination branch are the same;
- the new destination branch already has every change from the source branch, so there would be nothing to merge;
- the destination repository is archived.
A branch that does not exist answers 404. A pull request that changed after you opened the form answers 409 too, with "out-of-date information" (what to do).
From the REST API: send the reviewers back
On both Cloud and Data Center, a pull request is updated with a PUT to the pull request itself. The catch is the reviewers: an update that leaves them out can remove them. On a Bitbucket Server instance, someone sent only a version and a new description, and the reviewers were gone. An Atlassian staff member answered on the Atlassian Community that this is the expected behaviour, reproduced it, and suggested reading the current reviewers and sending them with the update. On Cloud, Renovate's Bitbucket code reads the pull request before each update for the same reason (its comment: "Updating a PR in Bitbucket will clear the reviewers if reviewers is not present").
So read the pull request first, then send its reviewers back with what you change. On Data Center, also send its current version; without it the update answers 400.
PUT https://bitbucket.example.com/rest/api/latest/projects/PROJ/repos/app/pull-requests/21
{"version": 3,
"title": "Retry the upload once",
"description": "Retries a failed upload once.",
"toRef": {"id": "refs/heads/release/2.4"},
"reviewers": [{"user": {"name": "a.reviewer"}}]}
PUT https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/21
{"title": "Retry the upload once",
"destination": {"branch": {"name": "release/2.4"}},
"reviewers": [{"uuid": "{reviewer-uuid}"}]}
On Cloud, an update that sends back a reviewer whose account was deactivated answers 400 with "reviewers: Malformed reviewers list". Atlassian has an open suggestion to say plainly that the user is inactive (BCLOUD-20266). Leave that reviewer out and send the update again.
Editing in IntelliJ IDEA
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the Bitbucket Cloud and Bitbucket Data Center pull requests waiting for your review in an IDE tool window. Edit title and description on an open pull request opens both in one dialog. It reads the pull request again first and sends its current reviewers back with your change (and the version on Data Center), so the reviewers stay and a long description is edited whole. It is a paid feature with a 30-day free trial; reading stays free. Change the destination branch in the browser.
Get it on JetBrains Marketplace
Bitbucket is a trademark of Atlassian Pty Ltd; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: decline and reopen · default reviewers · pull request templates · merge conflicts · 日本語