Skip to content

Commit 184994b

Browse files
[MNT] Prevents assignment on Restricted Labels (#2706)
* restricted labels * set * resolve conflicts * merge assign PRs and small change --------- Co-authored-by: MatthewMiddlehurst <pfm15hbu@gmail.com>
1 parent 777ee3a commit 184994b

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

.github/utilities/issue_assign.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
67
Users without write access can only have up to 2 open issues assigned.
78
Users with write access (or admin) are exempt from this limit.
89
If a non-write user already has 2 or more open issues, the bot
@@ -22,20 +23,32 @@
2223
repo = g.get_repo(repo)
2324
issue_number = context_dict["event"]["issue"]["number"]
2425
issue = repo.get_issue(number=issue_number)
25-
comment_body = context_dict["event"]["comment"]["body"]
26+
issue_labels = {label.name.lower() for label in issue.labels}
2627
pr = context_dict["event"]["issue"].get("pull_request")
28+
comment_body = context_dict["event"]["comment"]["body"]
2729
commenter = context_dict["event"]["comment"]["user"]["login"]
2830

31+
restricted_labels = {"meta-issue"}
32+
33+
# Assign tagged used to the issue if the comment includes the trigger phrase
2934
body = comment_body.lower()
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:
35+
if "@aeon-actions-bot" in body and "assign" in body and not pr:
36+
# Check if the issue has any restricted labels for auto assignment
37+
label_intersect = issue_labels & restricted_labels
38+
if len(label_intersect) > 0:
39+
issue.create_comment(
40+
f"This issue contains the following restricted label(s): "
41+
f"{', '.join(label_intersect)}. Cannot assign to users."
42+
)
43+
else:
44+
# collect any mentioned (@username) users
3645
mentioned_users = re.findall(r"@[a-zA-Z0-9_-]+", comment_body)
3746
mentioned_users = [user[1:] for user in mentioned_users]
3847
mentioned_users.remove("aeon-actions-bot")
48+
# Assign commenter if comment includes "assign me"
49+
if "assign me" in body:
50+
mentioned_users.append(commenter)
51+
mentioned_users = set(mentioned_users)
3952

4053
for user in mentioned_users:
4154
user_obj = g.get_user(user)
@@ -53,19 +66,18 @@
5366
issues_assigned_to_user = g.search_issues(query)
5467
assigned_count = issues_assigned_to_user.totalCount
5568

56-
if assigned_count >= 2:
69+
if assigned_count >= 3:
5770
# link to issue
5871
assigned_issues_list = [
5972
f"[#{assigned_issue.number}]({assigned_issue.html_url})"
6073
for assigned_issue in issues_assigned_to_user
6174
]
6275

6376
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"
77+
f"@{user}, already has {assigned_count} open issues assigned."
78+
"Users without write access are limited to self-assigning "
79+
"three issues.\n\n"
80+
"Here are the open issues assigned:\n"
6981
+ "\n".join(
7082
f"- {issue_link}" for issue_link in assigned_issues_list
7183
)

0 commit comments

Comments
 (0)