-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathteam_memberships.py
executable file
·47 lines (39 loc) · 1.55 KB
/
team_memberships.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import argparse
import os
from utils import simplify
from utils import get_all_teams
def main():
teams = get_all_teams()
for team in teams:
team_name = team.get('node').get('name')
users = team.get('node').get('members').get('edges')
users = sorted(users, key=lambda u: u['node']['login'])
for user in users:
username = user['node']['login']
role = user['role']
output = f"""
resource "github_team_membership" "{simplify(team_name)}_{simplify(username)}" {{
team_id = github_team.{simplify(team_name)}.id
username = github_membership.{simplify(username)}.username
role = "{role.lower()}"
}}"""
print(output)
def gen_import():
teams = get_all_teams()
for team in teams:
team_name = team.get('node').get('name')
users = team.get('node').get('members').get('edges')
users = sorted(users, key=lambda u: u['node']['login'])
for user in users:
username = user['node']['login']
team_id = team.get('node').get('databaseId')
print(f"terraform import github_team_membership.{simplify(team_name)}_{simplify(username)} {team_id}:{username}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate membership for teams')
parser.add_argument('--gen-imports', default=False, action='store_true')
args = parser.parse_args()
if args.gen_imports:
gen_import()
else:
main()