Skip to content

Instantly share code, notes, and snippets.

@joejag
Created October 29, 2022 11:46
Show Gist options
  • Save joejag/2de64c3caed5a94bb47db95d122e49a1 to your computer and use it in GitHub Desktop.
Save joejag/2de64c3caed5a94bb47db95d122e49a1 to your computer and use it in GitHub Desktop.
Create a json of the team structure of a Github org
#!/usr/bin/env python3
# Create a JSON of every team and the members for that team
# Final file has the form {"Team 1": [{"name": "Bob Smith", "email": "[email protected]", "login": "bobsmith"}]}
from collections import defaultdict
import os
import json
from github import Github # pip install pygithub
github_api = Github(os.environ.get("GITHUB_ACCESS_KEY"))
teams = github_api.get_organization("your_org").get_teams()
all_teams = defaultdict(list)
for team in teams:
print(team.name)
members = team.get_members()
for member in members:
all_teams[team.name].append(
{"name": member.name, "email": member.email, "login": member.login}
)
as_json = json.dumps(all_teams)
print(as_json, file=open("team.json", "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment