Example #1
0
def permissions(args):
    """
    Print a list of teams.
    For each team, list the members, repos and the permission (pull/push/admin)
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)
        result = []
        for team in org.list_teams():
            members = org.list_team_members(team)
            repos = org.list_team_repos(team)
            result.append({
                "name":
                team['name'],
                "permission":
                team['permission'],
                "repos": [{
                    'full_name': repo['full_name'],
                    'url': repo['url']
                } for repo in repos],
                "members": [{
                    'login': member['login'],
                    'url': member['url']
                } for member in members]
            })
        print(json.dumps(result, indent=2))
Example #2
0
def members(args):
    """
    Print a list of organisation members
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)
        for member in org.list_members():
            if args.json:
                print(json.dumps(member, indent=2))
            else:
                print(member['login'])
Example #3
0
def repos(args):
    """
    Print a list of organisation repositories
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)
        for repo in org.list_repos():
            if args.json:
                print(json.dumps(repo, indent=2))
            else:
                print(repo['name'])
Example #4
0
def migrate_project(args):
    """
    Migrate a Github project from one Github instance to another.

    Migration includes:
        - Project metadata
        - Git repository
        - Issues & pull requests
        - Comments
        - Hooks

    WARNING: This will copy the git repository verbatim. Any commits on the
    target repository that are not also on the source will be lost.

    Note: All issues and comments will be migrated as the target user with
    links back to the source Github instance.
    """
    with cli.catch_api_errors():
        src_org = Organisation(args.src)
        dst_org = Organisation(args.dst)
        src = Repo(args.src)
        dst = Repo(args.dst)

        # Create the repo object
        log.info("Migrating %s to %s -> creating repo", src, dst)
        project = src_org.get_repo(src.repo)
        project['name'] = dst.repo
        dst_org.create_repo(project)

        # Migrate repo data
        migrators.repo.migrate(src, dst)
        migrators.issues.migrate(src, dst)
        migrators.comments.migrate(src, dst)
        migrators.hooks.migrate(src, dst)