Source

bitbucket2github / bitbucket2github / github.py

#!/usr/bin/env python

from pygithub3 import Github

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

    github = Github()
    return [{
            "name":repo.name,
            "description":repo.description or '',
            "homepage":repo.homepage or '',
			"scm":"git",
			"clone_url":repo.clone_url
        }
        for repo in github.repos.list(username).iterator()]


def repo_exists(reponame, username):
    """ Checks whether the repo for that user already exists """

    github = Github()
    try:
        repo = github.repos.get(user=username, repo=reponame)
    except:
        return False
    else:
        return True


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

    reponame = repo['name']
    github = Github(login=username, password=password)
	
    try:
        repo = github.repos.get(user=username, repo=reponame)
    except:
        print "Creating " + reponame + " in GitHub"
        github.repos.create(dict(name=reponame, 
                        description=repo['description'], 
                        homepage=repo['homepage']))