-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathusers.py
executable file
·58 lines (51 loc) · 1.28 KB
/
users.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
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import argparse
import os
from utils import get_all_users
from utils import simplify
login = os.environ.get('GITHUB_LOGIN')
members_filter = "first: 100"
query = f"""
{{
organization(login: "{login}") {{
name,
membersWithRole({members_filter}) {{
pageInfo {{
endCursor,
}},
totalCount,
edges {{
role,
node {{
id,
login,
}},
}},
}},
}},
}}
"""
def main():
users = get_all_users(query)
for user in users:
username = user.get('node').get('login')
role = user.get('role').lower()
output = f"""
resource "github_membership" "{simplify(username)}" {{
username = "{username}"
role = "{role}"
}}"""
print(output)
def gen_import():
users = get_all_users(query)
for user in users:
username = user.get('node').get('login')
print(f"terraform import github_membership.{simplify(username)} {login}:{username}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate teams')
parser.add_argument('--gen-imports', default=False, action='store_true')
args = parser.parse_args()
if args.gen_imports:
gen_import()
else:
main()