Skip to content

Instantly share code, notes, and snippets.

@fmorato
Created April 9, 2017 06:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmorato/be72affc748e18e30430ffabda62a32a to your computer and use it in GitHub Desktop.
Save fmorato/be72affc748e18e30430ffabda62a32a to your computer and use it in GitHub Desktop.
Clone all repos from Bitbucket user or team
#!/usr/bin/env python3
'''
Clone all repos from Bitbucket user or team
It assumes you have 'git' and/or 'hg' in your path
usage: clone_bitbucket_repos.py user --login you@example.com
'''
import argparse
import getpass
import subprocess
import requests
parser = argparse.ArgumentParser(description='Clone all repos from Bitbucket user or team')
parser.add_argument('user', help='the user or team to clone repos for')
parser.add_argument('--login',
help='your bitbucket username that has access to user\' or team\' repos')
args = parser.parse_args()
password = ''
auth = None
if args.login:
password = getpass.getpass()
auth = (args.login, password)
repoinfo = requests.get("https://api.bitbucket.org/1.0/users/" + args.user,
auth=auth).json()
if not repoinfo['repositories']:
print('No repositories available. Try logging in.')
exit(1)
for repo in repoinfo['repositories']:
subprocess.run([repo['scm'], "clone",
"ssh://hg@bitbucket.org/" + args.user + "/" + repo['name']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment