|
3 | 3 | It checks if a comment on an issue or PR includes the trigger
|
4 | 4 | phrase (as defined) and a mentioned user.
|
5 | 5 | If it does, it assigns the issue to the mentioned user.
|
| 6 | +
|
6 | 7 | Users without write access can only have up to 2 open issues assigned.
|
7 | 8 | Users with write access (or admin) are exempt from this limit.
|
8 | 9 | If a non-write user already has 2 or more open issues, the bot
|
|
22 | 23 | repo = g.get_repo(repo)
|
23 | 24 | issue_number = context_dict["event"]["issue"]["number"]
|
24 | 25 | 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} |
26 | 27 | pr = context_dict["event"]["issue"].get("pull_request")
|
| 28 | +comment_body = context_dict["event"]["comment"]["body"] |
27 | 29 | commenter = context_dict["event"]["comment"]["user"]["login"]
|
28 | 30 |
|
| 31 | +restricted_labels = {"meta-issue"} |
| 32 | + |
| 33 | +# Assign tagged used to the issue if the comment includes the trigger phrase |
29 | 34 | 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 |
36 | 45 | mentioned_users = re.findall(r"@[a-zA-Z0-9_-]+", comment_body)
|
37 | 46 | mentioned_users = [user[1:] for user in mentioned_users]
|
38 | 47 | 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) |
39 | 52 |
|
40 | 53 | for user in mentioned_users:
|
41 | 54 | user_obj = g.get_user(user)
|
|
53 | 66 | issues_assigned_to_user = g.search_issues(query)
|
54 | 67 | assigned_count = issues_assigned_to_user.totalCount
|
55 | 68 |
|
56 |
| - if assigned_count >= 2: |
| 69 | + if assigned_count >= 3: |
57 | 70 | # link to issue
|
58 | 71 | assigned_issues_list = [
|
59 | 72 | f"[#{assigned_issue.number}]({assigned_issue.html_url})"
|
60 | 73 | for assigned_issue in issues_assigned_to_user
|
61 | 74 | ]
|
62 | 75 |
|
63 | 76 | 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" |
69 | 81 | + "\n".join(
|
70 | 82 | f"- {issue_link}" for issue_link in assigned_issues_list
|
71 | 83 | )
|
|
0 commit comments