bitbucket2github / bitbucket2github /

#!/usr/bin/env python

import urllib2
import json
from import sh

base_url = ''

def repos(username):
    """ Returns the list of public repos owned by username """

    url = base_url + '/users/' + username + '/'
    f = urllib2.urlopen(url)
    response = json.loads(

    return [
            "description":repo.get('description', ''),
            "homepage":repo.get('website', ''),
			"scm":repo.get('scm', 'hg')
        } for repo in response.get('repositories')

def repo_exists(reponame, username):
    """ Checks whether the repo for that user exists """
        url = base_url + '/repositories/' + username + '/' + reponame + '/'
        response = urllib2.urlopen(url).read()
    except urllib2.HTTPError:
        return False
        return True

def create_repo(repo, username, password):
    """ Creates a public repository with the given credentials """

    reponame = repo['name']

    if not repo_exists(reponame, username):
        print "Creating " + reponame + " in BitBucket"
        # Somehow BitBucket authentication with urllib2 is not working. So using this ugly approach.
        cmd = 'curl -d "name={reponame}" -d "description={description}" -d "website={url}" -d "scm={scm}" -u {username}:{password} {base_url}/repositories/'
        cmd = cmd.format(reponame=reponame,

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.