Skip to content

Commit ad89329

Browse files
authored
[ENH,MNT] Assign Bot (assigned issues>2) (#2702)
* Empty-Commit * point 2 working * changes * changes in comment message
1 parent 836f47d commit ad89329

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

.github/utilities/issue_assign.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
It checks if a comment on an issue or PR includes the trigger
44
phrase (as defined) and a mentioned user.
55
If it does, it assigns the issue to the mentioned user.
6+
Users without write access can only have up to 2 open issues assigned.
7+
Users with write access (or admin) are exempt from this limit.
8+
If a non-write user already has 2 or more open issues, the bot
9+
comments on the issue with links to the currently assigned open issues.
610
"""
711

812
import json
@@ -29,4 +33,37 @@
2933
mentioned_users.remove("aeon-actions-bot")
3034

3135
for user in mentioned_users:
32-
issue.add_to_assignees(user)
36+
user_obj = g.get_user(user)
37+
permission = repo.get_collaborator_permission(user_obj)
38+
39+
if permission in ["admin", "write"]:
40+
issue.add_to_assignees(user)
41+
else:
42+
# First check if the user is already assigned to this issue
43+
if user in [assignee.login for assignee in issue.assignees]:
44+
continue
45+
46+
# search for open issues only
47+
query = f"repo:{repo.full_name} is:issue is:open assignee:{user}"
48+
issues_assigned_to_user = g.search_issues(query)
49+
assigned_count = issues_assigned_to_user.totalCount
50+
51+
if assigned_count >= 2:
52+
# link to issue
53+
assigned_issues_list = [
54+
f"[#{assigned_issue.number}]({assigned_issue.html_url})"
55+
for assigned_issue in issues_assigned_to_user
56+
]
57+
58+
comment_message = (
59+
f"@{user}, you already have {assigned_count} open issues assigned. "
60+
"Users without write access are limited to self-assigning two"
61+
"issues.\n\n"
62+
"Here are the open issues assigned to you:\n"
63+
+ "\n".join(
64+
f"- {issue_link}" for issue_link in assigned_issues_list
65+
)
66+
)
67+
issue.create_comment(comment_message)
68+
else:
69+
issue.add_to_assignees(user)

0 commit comments

Comments
 (0)