From f617b6ee0eb81853b50fd50ea71dd1b2ceb9b9a5 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Wed, 31 Jul 2024 18:54:55 -0400 Subject: .github/request-reviews.yml: Only post non-collab message once Enhances the flow that adds a comment on a PR if a non-collaborator is in the reviewer list by checking if a comment was previously left on the PR. If it was for the same set of non-collaborators, another comment is not created. If a new non-collaborator is discovered, the message will be left identifying that new user account. Signed-off-by: Michael Kubacki --- .github/scripts/GitHub.py | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) (limited to '.github') diff --git a/.github/scripts/GitHub.py b/.github/scripts/GitHub.py index 5db2060ca9..6c755c2415 100644 --- a/.github/scripts/GitHub.py +++ b/.github/scripts/GitHub.py @@ -221,30 +221,40 @@ def add_reviewers_to_pr( f"::error title=User is not a Collaborator!::{', '.join(non_collaborators)}" ) - repo_admins = [ - a.login for a in repo_gh.get_collaborators(permission="admin") - ] - - leave_pr_comment( - token, - owner, - repo, - pr_number, - f"⚠ **WARNING: Cannot add some reviewers**: A user " - f"specified as a reviewer for this PR is not a collaborator " - f"of the repository. Please add them as a collaborator to " - f"the repository so they can be requested in the future.\n\n" - f"Non-collaborators requested:\n" - f"{'\n'.join([f'- @{c}' for c in non_collaborators])}" - f"\n\nAttn Admins:\n" - f"{'\n'.join([f'- @{a}' for a in repo_admins])}\n---\n" - f"**Admin Instructions:**\n" - f"- Add the non-collaborators as collaborators to the " - f"appropriate team(s) listed in " - f"[teams](https://github.com/orgs/tianocore/teams)\n" - f"- If they are no longer needed as reviewers, remove them " - f"from [`Maintainers.txt`](https://github.com/tianocore/edk2/blob/HEAD/Maintainers.txt)", - ) + for comment in pr.get_issue_comments(): + # If a comment has already been made for these non-collaborators, + # do not make another comment. + if ( + comment.user.login == "github-actions[bot]" + and "WARNING: Cannot add some reviewers" in comment.body + and all(u in comment.body for u in non_collaborators) + ): + break + else: + repo_admins = [ + a.login for a in repo_gh.get_collaborators(permission="admin") + ] + + leave_pr_comment( + token, + owner, + repo, + pr_number, + f"⚠ **WARNING: Cannot add some reviewers**: A user " + f"specified as a reviewer for this PR is not a collaborator " + f"of the repository. Please add them as a collaborator to " + f"the repository so they can be requested in the future.\n\n" + f"Non-collaborators requested:\n" + f"{'\n'.join([f'- @{c}' for c in non_collaborators])}" + f"\n\nAttn Admins:\n" + f"{'\n'.join([f'- @{a}' for a in repo_admins])}\n---\n" + f"**Admin Instructions:**\n" + f"- Add the non-collaborators as collaborators to the " + f"appropriate team(s) listed in " + f"[teams](https://github.com/orgs/tianocore/teams)\n" + f"- If they are no longer needed as reviewers, remove them " + f"from [`Maintainers.txt`](https://github.com/tianocore/edk2/blob/HEAD/Maintainers.txt)", + ) # Add any new reviewers to the PR if needed. if new_pr_reviewers: -- cgit