Created
April 9, 2017 06:21
-
-
Save fmorato/be72affc748e18e30430ffabda62a32a to your computer and use it in GitHub Desktop.
Clone all repos from Bitbucket user or team
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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