diff options
author | Michael Kubacki <michael.kubacki@microsoft.com> | 2024-08-01 01:51:12 +0300 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-08-05 22:30:26 +0300 |
commit | e86647decda974aff8a4356f67adc730eddea111 (patch) | |
tree | a47941a26da577fcdb75961c670d7edab19e8dbf | |
parent | eaf2b82eda199260022504a1a0f7966b0dd56944 (diff) | |
download | edk2-e86647decda974aff8a4356f67adc730eddea111.tar.xz |
.github/request-reviews.yml: Update PR reviewer exclusion
Updates logic to:
- Not request reviews from reviewers that have already left a review
on the PR. Previously, the reviewers review (e.g. approval) would
remain on the PR, but they would be notified on each change to the
PR. This approach follows the expected notification process for
requesting reviews which is one time. Maintainers and reviewers can
set up their own notifications for more granular updates on PR
activity separately.
- Add the collaborator reviewers if a reviewer(s) is found to not be
a collaborator. This is an improvement to today's behavior which is
to not add any reviewers if a single reviewer is not a collaborator
of the repo.
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
-rw-r--r-- | .github/scripts/GitHub.py | 22 | ||||
-rw-r--r-- | .github/workflows/request-reviews.yml | 31 |
2 files changed, 43 insertions, 10 deletions
diff --git a/.github/scripts/GitHub.py b/.github/scripts/GitHub.py index 43eb5c7e4f..bc0f355206 100644 --- a/.github/scripts/GitHub.py +++ b/.github/scripts/GitHub.py @@ -202,12 +202,20 @@ def add_reviewers_to_pr( pr_author = pr.user.login.strip()
- while pr_author in user_names:
- user_names.remove(pr_author)
+ current_pr_requested_reviewers = [
+ r.login.strip() for r in pr.get_review_requests()[0]
+ ]
+ current_pr_reviewed_reviewers = [r.user.login.strip() for r in pr.get_reviews()]
+ current_pr_reviewers = list(
+ set(current_pr_requested_reviewers + current_pr_reviewed_reviewers)
+ )
repo_collaborators = [c.login.strip() for c in repo_gh.get_collaborators()]
non_collaborators = [u for u in user_names if u not in repo_collaborators]
+ excluded_pr_reviewers = [pr_author] + current_pr_reviewers + non_collaborators
+ new_pr_reviewers = [u for u in user_names if u not in excluded_pr_reviewers]
+
if non_collaborators:
print(
f"::error title=User is not a Collaborator!::{', '.join(non_collaborators)}"
@@ -225,6 +233,12 @@ def add_reviewers_to_pr( f"Users requested:\n{', '.join(user_names)}",
)
- pr.create_review_request(reviewers=user_names)
+ # Add any new reviewers to the PR if needed.
+ if new_pr_reviewers:
+ print(
+ f"::debug title=Adding New PR Reviewers::" f"{', '.join(new_pr_reviewers)}"
+ )
+
+ pr.create_review_request(reviewers=new_pr_reviewers)
- return user_names
+ return new_pr_reviewers
diff --git a/.github/workflows/request-reviews.yml b/.github/workflows/request-reviews.yml index b358ae089f..9b0d126649 100644 --- a/.github/workflows/request-reviews.yml +++ b/.github/workflows/request-reviews.yml @@ -84,9 +84,28 @@ jobs: reviewers = GitHub.get_reviewers_for_range(WORKSPACE_PATH, GET_MAINTAINER_LOCAL_PATH, pr_commit_sha, pr_commit_sha)
if not reviewers:
- print("::notice title=No Reviewers Found!::No reviewers found for this PR.")
- sys.exit(1)
-
- print(f"::notice title=Reviewer List::Reviewers found for PR {os.environ['PR_NUMBER']}:\n{', '.join(reviewers)}")
-
- GitHub.add_reviewers_to_pr(os.environ['GH_TOKEN'], os.environ['ORG_NAME'], os.environ['REPO_NAME'], int(os.environ['PR_NUMBER']), reviewers)
+ print("::notice title=No New Reviewers Found!::No reviewers found for this PR.")
+ sys.exit(0)
+
+ print(
+ f"::notice title=Preliminary Reviewer List::Total reviewer candidates for "
+ f"PR {os.environ['PR_NUMBER']}: {', '.join(reviewers)}"
+ )
+
+ new_reviewers = GitHub.add_reviewers_to_pr(
+ os.environ["GH_TOKEN"],
+ os.environ["ORG_NAME"],
+ os.environ["REPO_NAME"],
+ int(os.environ["PR_NUMBER"]),
+ reviewers,
+ )
+ if new_reviewers:
+ print(
+ f"::notice title=New Reviewers Added::New reviewers requested for PR "
+ f"{os.environ['PR_NUMBER']}: {', '.join(new_reviewers)}"
+ )
+ else:
+ print(
+ "::notice title=No New Reviewers Added::No reviewers were found that "
+ "should be newly requested."
+ )
|