xxxxxxxxxx
import requests
def remove_pull_request(owner, repo, pull_request_number, access_token):
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pull_request_number}"
headers = {
"Authorization": f"Bearer {access_token}"
}
response = requests.delete(url, headers=headers)
if response.status_code == 204:
print("Pull request successfully removed.")
else:
print("Failed to remove pull request.")
# Usage example
owner = "your_username"
repo = "your_repository"
pull_request_number = 123
access_token = "your_github_access_token"
remove_pull_request(owner, repo, pull_request_number, access_token)
xxxxxxxxxx
There is no way you can delete a pull request yourself -- you and the repo owner (and all users with push access to it) can close it, but it will remain in the log. This is part of the philosophy of not denying/hiding what happened during development.
However, if there are critical reasons for deleting it (this is mainly violation of Github Terms of Service), Github support staff will delete it for you.
Whether or not they are willing to delete your PR for you is something you can easily ask them, just drop them an email at support@github.com
UPDATE: Currently Github requires support requests to be created here: https://support.github.com/contact
xxxxxxxxxx
import requests
# API endpoint and authentication
repo_owner = "owner_username"
repo_name = "repository_name"
pull_request_number = 123
api_token = "your_github_api_token"
headers = {"Authorization": f"Bearer {api_token}"}
# Delete the pull request
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pull_request_number}"
response = requests.delete(url, headers=headers)
# Check the response status
if response.status_code == 204:
print("Pull request successfully removed.")
else:
print("Failed to remove the pull request.")
print(response.text) # Print response details in case of an error