Skip to content

Instantly share code, notes, and snippets.

@silasrm
Last active June 28, 2018 17:35
Show Gist options
  • Save silasrm/98d660c13841d0bd5cd81cc8279a813b to your computer and use it in GitHub Desktop.
Save silasrm/98d660c13841d0bd5cd81cc8279a813b to your computer and use it in GitHub Desktop.
import requests
from requests.auth import HTTPBasicAuth
import argparse
from getpass import getpass
"""
@origin https://gist.github.com/cdefgah/35f127fe39b1ebf2caa2d53d675f1019#file-revokeaccesstounwantedbitbucketrepository-py
@author silasrm <[email protected]>
In some cases you may want to remove yourself from a different user's private repository in bitbucket.
This may be useful in cases you have access to "dead" repositories, which owners stopped using bitbucket.
And there's no straightforward way to remove yourself from these repos.
This (python3) code revokes access from repositories you don't want to work with and don't
want to see these repos in your account.
Specify username of unwanted repo owner and unwanted repo name below in the variables.
Also specify your username and password to the bitbucket (attlassian) account.
Then run this script.
You are free to share this script with anyone :)
"""
parser = argparse.ArgumentParser("revoke.py")
parser.add_argument("username", help="Your username.", type=str)
parser.add_argument('-p', '--password', action='store_true', dest='password', help='Your password')
parser.add_argument("owner", help="Repository owner.", type=str)
parser.add_argument("name", help="Repository name.", type=str)
args = parser.parse_args()
if args.password:
password = getpass()
action_url = "https://bitbucket.org/xhr/" + args.owner + "/" + args.name + "/revoke"
server_response = requests.post(action_url, auth=HTTPBasicAuth(args.username, password))
print(server_response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment