-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_collaborator.py
executable file
·76 lines (54 loc) · 2.1 KB
/
add_collaborator.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import sys
import boatswain_env as benv
from github import Github
CMD_NAME = 'add_collaborator'
DESC = 'Add user as collaborator to GitHub repo'
def add_collaborator_deco(parser):
parser.add_argument('owner',
type=str,
help='repo owner (individual or organization)',
metavar='<repo-owner>',
)
parser.add_argument('repo',
type=str,
help='repo name',
metavar='<repo-name>',
)
parser.add_argument('user',
type=str,
help='user name of user to be added',
metavar='<user>',
)
parser.add_argument('permission',
type=str,
help='permissions of user to be added',
metavar='push|pull|admin',
)
def do_add_collaborator(repo, user, permission, opt):
opt.info('Adding {} as collaborator to {} with {} permissions'
.format(user, repo.full_name, permission))
if opt.noop:
opt.log('--noop option specified; not adding collaborator')
return
repo.add_to_collaborators(user, permission=permission)
opt.info('User {} successfully added'.format(user))
def add_collaborator(opt):
g = Github(opt.githubToken())
repo_full_name = '{}/{}'.format(opt.owner, opt.repo)
repo = g.get_repo(repo_full_name)
if not opt.promptYes(('Are you sure you would like to add {} '
'as a collaborator to {} with {} permissions?')
.format(user, repo_full_name, permission),
True):
opt.warn('Aborting')
return
do_add_collaborator(repo, opt.user, opt.permission, opt)
def main(args=None, config_path=None):
if args is None:
args = sys.argv[1:]
opt = benv.ParseOption(args, section=CMD_NAME, config_path=config_path,
desc=DESC, parse_deco=add_collaborator_deco, req_github=True)
add_collaborator(opt)
if __name__ == '__main__':
main()