#!/usr/bin/env python
import os
import argparse
from github import GithubException as GitHubException
from github import Github as GitHub


def create_repo(name):
    gh = GitHub(os.environ.get('GITHUB_ACCESS_TOKEN'))
    org = gh.get_organization(os.environ.get('GITHUB_ORG_NAME'))
    try:
        repo = org.get_repo(name)
        print(repo.clone_url.replace('https://', 'https://{}@'.format(os.environ.get('GITHUB_ACCESS_TOKEN'))))
    except GitHubException as e:
        repo = org.create_repo(name)
        print(repo.clone_url.replace('https://', 'https://{}@'.format(os.environ.get('GITHUB_ACCESS_TOKEN'))))


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', '--name')
    settings = parser.parse_args()

    create_repo(settings.name)
