How to decline a pull request from a fork when the upstream repository is deleted?
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
Declining a pull request raised via a forked repository when the original repository has been deleted does not work as the decline button does not respond. This document provides you a solution to decline the pull request
Diagnosis
The forking model in Git is a very common model of development where developers create forks of the main repository to make changes and raise pull request to the original repository. However, there are scenarios where the repositories have changed so much that the original is no longer relevant and you may have open pull requests. These seemingly cannot be declined since the decline button will simply give you a loading wheel that spins forever.
However, we have an alternative solution using the API that can decline such pull requests.
Solution
The pull request decline API will help you resolve this issue. The endpoint for this API is -
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/decline
Here is an example call made using cURL -
curl --request POST \
--url 'https://api.bitbucket.org/2.0/repositories/sample-workspace/sample-repository/pullrequests/43/decline' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
You can authenticate the above using an OAuth token or Access Tokens. Alternatively, you can also use an App Password using the below syntax -
curl --request POST \
--url 'https://api.bitbucket.org/2.0/repositories/sample-workspace/sample-repository/pullrequests/43/decline' \
--header 'Accept: application/json' \
-u <username>:<app-password>
Please refer to our Authentication Methods to use one that suits your requirement.