Beispiel #1
0
def create_teams_for_data(databag):
    client = set_up_github_client()
    organization = get_cc_organization(client)

    print("Creating and populating teams...")
    projects = databag["projects"]
    for project in projects:
        project_name = project["name"]
        print(
            f"    Creating and populating teams for project {project_name}...")
        roles = project["roles"]
        for role, members in roles.items():
            if PERMISSIONS[role] is None:
                print(f"    Skipping {role} as it has no privileges.")
                continue

            print(f"        Finding team for role {role}...")
            team = map_role_to_team(organization, project_name, role)
            print("        Done.")

            print(f"        Populating repos for team {team.name}...")
            repos = project["repos"]
            map_team_to_repos(organization, team, repos, True)
            set_team_repo_permissions(team, PERMISSIONS[role])
            print("        Done.")

            print(f"        Populating members for team {team.name}...")
            members = [member["github"] for member in members]
            map_team_to_members(client, team, members, True)
            print("        Done.")
        print("    Done.")
    print("Done.")
def get_select_repos(args):
    github = set_up_github_client()
    repos = list(get_cc_repos(github))
    if args.repos:
        repos_selected = []
        for repo in repos:
            if repo.name in args.repos:
                repos_selected.append(repo)
        repos = repos_selected
        if not repos:
            raise ScriptError("Specified repositories do not include any valid"
                              f" repositories: {args.repos}")
    repos.sort(key=lambda repo: repo.name)
    return repos
Beispiel #3
0
def set_labels(standard_labels, repo_specific_labels):
    """
    Set labels on all repos for the organisation. This is the main entrypoint of
    the module.
    """

    logger.log(logging.INFO, "Setting up...")
    client = set_up_github_client()
    organization = get_cc_organization(client)
    logger.log(log.SUCCESS, "done.")

    logger.log(logging.INFO, "Fetching repos...")
    repos = list(organization.get_repos())
    logger.log(log.SUCCESS, f"done. Found {len(repos)} repos.")

    for repo in repos:
        logger.log(logging.INFO, f"Getting labels for repo '{repo.name}'...")
        labels = standard_labels + repo_specific_labels.get(repo.name, [])
        logger.log(log.SUCCESS, f"done. Found {len(labels)} labels.")
        logger.log(logging.INFO, f"Syncing labels for repo '{repo.name}'...")
        map_repo_to_labels(repo, labels)
        logger.log(log.SUCCESS, "done.")
def create_codeowners_for_data(databag):
    set_up_git_user()

    client = set_up_github_client()
    organization = get_cc_organization(client)

    print("Identifying and fixing CODEOWNER issues...")
    projects = databag["projects"]
    for project in projects:
        project_name = project["name"]
        print("    Identifying and fixing CODEOWNER issues for project"
              f" {project_name}...")

        print("        Finding all teams...")
        roles = project["roles"]
        teams = get_teams(organization, project_name, roles)
        print(f"        Found {len(teams)} teams for project {project_name}.")

        print("        Checking all projects...")
        repos = project["repos"]
        for repo in repos:
            check_and_fix_repo(organization, repo, teams)
    print("Done")
def update_branch_protection(repo):
    master = repo.get_branch("master")
    if repo.name not in branch_protections.EXEMPT_REPOSITORIES:
        if repo.name in branch_protections.REQUIRED_STATUS_CHECK_MAP:
            master.edit_protection(
                required_approving_review_count=1,
                user_push_restrictions=[],
                contexts=branch_protections.REQUIRED_STATUS_CHECK_MAP[
                    repo.name],
            )
        else:
            master.edit_protection(required_approving_review_count=1,
                                   user_push_restrictions=[])
        print(f'Updating branch protection for: "{repo.name}"')
    else:
        print(f'Skipping branch protection for exempt repo: "{repo.name}"')


if __name__ == "__main__":
    logger.log(logging.INFO, "Starting normalization")
    logger.log(logging.INFO, "Syncing labels...")
    set_labels(*get_labels())
    logger.log(log.SUCCESS, "done.")

    github = set_up_github_client()
    repos = get_cc_repos(github)
    for repo in repos:
        # TODO: Set up automatic deletion of merged branches
        update_branch_protection(repo)