-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_team.py
60 lines (48 loc) · 1.41 KB
/
add_team.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
59
60
from github import Github
import getpass
def login():
name = input('gh username: ')
passw = getpass.getpass()
g = Github(name, passw)
return g
def get_user_list(fname):
f = open(fname)
names = f.read().strip().split()
f.close()
return names
def add_user(g, team, user):
try:
gh_user = g.get_user(user)
team.add_membership(gh_user, 'member')
except:
print('user ', user, ' not found')
def add_users(g, team, user):
for user in users:
print('adding ', user)
add_user(g, team, user)
if __name__ == '__main__':
g = login()
org_name = input('gh org: ')
try:
org = g.get_organization( org_name )
except:
print('org ', org, ' not found.')
team_name = input('Team name: ')
choice = input('create team?[y/N] ')
if choice == 'y' or choice == 'Y':
org.create_team( team_name )
print('Team ', team_name, ' created.')
#get team
try:
team = org.get_team_by_slug(team_name)
except:
print('team ', team_name, ' not found')
choice = input('add single user to team?[y/N] ')
if choice == 'y' or choice == 'Y':
user = input('username: ')
add_user(g, team, user)
choice = input('batch add users?[y/N] ')
if choice == 'y' or choice == 'Y':
fname = input('filename: ')
users = get_user_list(fname)
add_users( g, team, users )