Last active
March 4, 2020 06:04
-
-
Save xcsrz/6aa1fb3f42fa82c9f41b22efe847f273 to your computer and use it in GitHub Desktop.
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…
This file contains hidden or 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
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://[email protected]/%s/%s' % (team, repo['slug'])) | |
elif repo['scm'] == 'git': | |
print("cloning %s via git" % repo['slug']) | |
system('git clone --mirror [email protected]:%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