From b1924a1ea7b4996eba41b1fbc7891802cd3f571f Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 3 Jan 2025 03:24:37 +0100 Subject: [PATCH] ci/request-reviews: Don't request reviews from users not part of the org Fixes this problem for maintainer-based reviews when the maintainer didn't yet accept or missed the automated invite: gh: Reviews may only be requested from collaborators. One or more of the users or teams you specified is not a collaborator of the NixOS/nixpkgs repository. (HTTP 422) --- .github/workflows/eval.yml | 2 +- ci/request-reviews/process-reviewers.sh | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/eval.yml b/.github/workflows/eval.yml index 52edcd9e67a23b..2e99bb17b8bb82 100644 --- a/.github/workflows/eval.yml +++ b/.github/workflows/eval.yml @@ -287,7 +287,7 @@ jobs: # There appears to be no API to request reviews based on GitHub IDs jq -r 'keys[]' comparison/maintainers.json \ | while read -r id; do gh api /user/"$id" --jq .login; done \ - | GH_TOKEN=${{ steps.app-token.outputs.token }} base/process-reviewers.sh "$REPOSITORY" "$NUMBER" "$AUTHOR" \ + | GH_TOKEN=${{ steps.app-token.outputs.token }} result/bin/process-reviewers.sh "$REPOSITORY" "$NUMBER" "$AUTHOR" \ > reviewers.json # Request reviewers from maintainers of changed output paths diff --git a/ci/request-reviews/process-reviewers.sh b/ci/request-reviews/process-reviewers.sh index b70a1a7fc4519d..e1051cdc93cfb2 100755 --- a/ci/request-reviews/process-reviewers.sh +++ b/ci/request-reviews/process-reviewers.sh @@ -19,11 +19,13 @@ baseRepo=$1 prNumber=$2 prAuthor=$3 +org=${baseRepo%%/*} + tmp=$(mktemp -d) trap 'rm -rf "$tmp"' exit declare -A users=() -while read -r handle; do +while read -r handle && [[ -n "$handle" ]]; do users[$handle]= done @@ -47,6 +49,16 @@ while read -r user; do fi done < "$tmp/already-reviewed-by" +for user in "${!users[@]}"; do + if ! gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/$org/members/$user" >&2; then + log "User $user is not part of the $org org, probably missed the automated invite (see https://github.com/NixOS/nixpkgs/issues/234293), ignoring.." + unset 'users[$user]' + fi +done + # Turn it into a JSON for the GitHub API call to request PR reviewers jq -n \ --arg users "${!users[*]}" \