Skip to content

Instantly share code, notes, and snippets.

@xitij2000
Created January 16, 2025 05:25
Show Gist options
  • Save xitij2000/699997e7402f1a6f8e937a5af04102f3 to your computer and use it in GitHub Desktop.
Save xitij2000/699997e7402f1a6f8e937a5af04102f3 to your computer and use it in GitHub Desktop.
Migrate GitHub team from the current per-CC mechanism to per-repo
# SPDX-FileCopyrightText: 2025-present Kshitij Sobti <[email protected]>
#
# SPDX-License-Identifier: MIT
from collections import defaultdict
from github import Github
from github import Auth
auth = Auth.Token("TOKEN")
g = Github(auth=auth)
org = g.get_organization("openedx")
teams = org.get_teams()
filtered_teams = [team for team in teams if team.name.startswith("CCP Committer:")]
repo_map = defaultdict(list)
for team in filtered_teams:
user = team.get_members()[0]
for repo in team.get_repos():
repo_map[repo].append(user)
for repo, users in repo_map.items():
team_name = f"CC For {repo.name}"
team_description = f"Team for Core Contributors that need access to {repo.name}"
team = org.create_team(
name=team_name,
description=team_description,
privacy="closed",
repo_names=[repo.full_name],
)
team.set_repo_permission(
repo=repo,
permission="push",
)
for user in users:
team.add_membership(user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment