Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
With atlassian falling apart and abandoning mercurial (the only reason to use bitbucket unless you're one of those anti-microsoft holdouts) you may find yourself looking to collect all your bitbucket repos to take elsewhere ... like ... github. This script is the first step. This is the first draft, only tested on mac running python 3.7 but shou…
from requests import get
from os import environ, getcwd, chdir, mkdir, system
from json import dumps
basedir = getcwd() + '/repos'
mkdir(basedir)
username=environ['BITBUCKET_USER']
password=environ['BITBUCKET_PASS']
team=environ['BITBUCKET_TEAM']
def grab_repos(repos):
for repo in repos:
print(">> grabbing >>", repo['slug'])
chdir(basedir)
if repo['scm'] == 'hg':
print("cloning %s via hg" % repo['slug'])
system('hg clone ssh://hg@bitbucket.org/%s/%s' % (team, repo['slug']))
elif repo['scm'] == 'git':
print("cloning %s via git" % repo['slug'])
system('git clone --mirror git@bitbucket.org:%s/%s' % (team, repo['slug']))
else:
raise Exception("Unable to handle: " . dumps(repo))
repolist = []
next_page = 'https://api.bitbucket.org/2.0/teams/%s/repositories' % team
while next_page != None:
print(">> loading repo list from", next_page)
results = get(next_page, auth=(username, password)).json()
next_page = results.get('next', None)
grab_repos(results['values'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.