Skip to content

Commit c322291

Browse files
Ramana-RajaRamana-Raja
authored andcommitted
[MNT,ENH] Assign-bot (Allow users to type alternative phrases for assingment) (#2704)
* added extra features * added comments * optimized code * optimized code * made changes requested by moderators * fixed conflicts * fixed conflicts * fixed conflicts --------- Co-authored-by: Ramana-Raja <ramanarajakesavaraja@gamil.com>
1 parent 4235288 commit c322291

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

.github/utilities/issue_assign.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,52 @@
2424
issue = repo.get_issue(number=issue_number)
2525
comment_body = context_dict["event"]["comment"]["body"]
2626
pr = context_dict["event"]["issue"].get("pull_request")
27+
commenter = context_dict["event"]["comment"]["user"]["login"]
2728

28-
# Assign tagged used to the issue if the comment includes the trigger phrase
2929
body = comment_body.lower()
30-
if "@aeon-actions-bot" in body and "assign" in body and not pr:
31-
mentioned_users = re.findall(r"@[a-zA-Z0-9_-]+", comment_body)
32-
mentioned_users = [user[1:] for user in mentioned_users]
33-
mentioned_users.remove("aeon-actions-bot")
30+
if "@aeon-actions-bot" in body and not pr:
31+
# Assign commenter if comment includes "assign me"
32+
if "assign me" in body:
33+
issue.add_to_assignees(commenter)
34+
# Assign tagged used to the issue if the comment includes the trigger phrase
35+
elif "assign" in body:
36+
mentioned_users = re.findall(r"@[a-zA-Z0-9_-]+", comment_body)
37+
mentioned_users = [user[1:] for user in mentioned_users]
38+
mentioned_users.remove("aeon-actions-bot")
3439

35-
for user in mentioned_users:
36-
user_obj = g.get_user(user)
37-
permission = repo.get_collaborator_permission(user_obj)
40+
for user in mentioned_users:
41+
user_obj = g.get_user(user)
42+
permission = repo.get_collaborator_permission(user_obj)
3843

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
44+
if permission in ["admin", "write"]:
45+
issue.add_to_assignees(user)
46+
else:
47+
# First check if the user is already assigned to this issue
48+
if user in [assignee.login for assignee in issue.assignees]:
49+
continue
4550

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
51+
# search for open issues only
52+
query = f"repo:{repo.full_name} is:issue is:open assignee:{user}"
53+
issues_assigned_to_user = g.search_issues(query)
54+
assigned_count = issues_assigned_to_user.totalCount
5055

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-
]
56+
if assigned_count >= 2:
57+
# link to issue
58+
assigned_issues_list = [
59+
f"[#{assigned_issue.number}]({assigned_issue.html_url})"
60+
for assigned_issue in issues_assigned_to_user
61+
]
5762

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
63+
comment_message = (
64+
f"@{user}, you already have {assigned_count} "
65+
f"open issues assigned."
66+
"Users without write access are limited to self-assigning two"
67+
"issues.\n\n"
68+
"Here are the open issues assigned to you:\n"
69+
+ "\n".join(
70+
f"- {issue_link}" for issue_link in assigned_issues_list
71+
)
6572
)
66-
)
67-
issue.create_comment(comment_message)
68-
else:
69-
issue.add_to_assignees(user)
73+
issue.create_comment(comment_message)
74+
else:
75+
issue.add_to_assignees(user)

0 commit comments

Comments
 (0)