-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassign.star
49 lines (34 loc) · 1.22 KB
/
assign.star
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
load("github.com/repokitteh/modules/lib/utils.star", "react")
def _assign(comment_id, action, sender, command):
if not(action in ['created', 'opened']):
return
if not github.issue_check_assignee(sender):
react(comment_id, '%s is not allowed to assign users.' % sender)
return
users = command.args
if not users:
# no arguments -> assume sender.
users.append(sender)
nopes = [user for user in users if not github.issue_check_assignee(user)]
if len(nopes) == 1:
react(comment_id, '%s cannot be assigned to this issue.' % nopes[0])
elif len(nopes) > 1:
react(comment_id, 'neither of %s can be assigned to this issue.' % ', '.join(nopes))
else:
# yay!
github.issue_assign(*users)
react(comment_id, None)
def _unassign(comment_id, action, sender, command):
if action != 'created':
return
if not github.issue_check_assignee(sender):
react(comment_id, '%s is not allowed to unassign users.' % sender)
return
users = command.args
if not users:
# no arguments -> assume sender.
users.append(sender)
github.issue_unassign(*users)
react(comment_id, None)
handlers.command(name='assign', func=_assign)
handlers.command(name='unassign', func=_unassign)