|
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 | +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. |
6 | 10 | """
|
7 | 11 |
|
8 | 12 | import json
|
|
29 | 33 | mentioned_users.remove("aeon-actions-bot")
|
30 | 34 |
|
31 | 35 | 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