-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
workflows/eval: fix maintainer requests #370456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0371b7f
ci/request-reviews: split off a more reusable reviewer processing script
infinisil 0ebab0b
workflows/eval: Reuse process-reviewers.sh
infinisil ab248be
workflows/eval: Minor cleanup
infinisil 077007a
ci/request-reviews: Don't request reviews from non-repo-collaborators
infinisil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Process reviewers for a PR, reading line-separated usernames on stdin, | ||
| # returning a JSON suitable to be consumed by the API endpoint to request reviews: | ||
| # https://docs.github.com/en/rest/pulls/review-requests?apiVersion=2022-11-28#request-reviewers-for-a-pull-request | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| log() { | ||
| echo "$@" >&2 | ||
| } | ||
|
|
||
| if (( "$#" < 3 )); then | ||
| log "Usage: $0 BASE_REPO PR_NUMBER PR_AUTHOR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| baseRepo=$1 | ||
| prNumber=$2 | ||
| prAuthor=$3 | ||
|
|
||
| tmp=$(mktemp -d) | ||
| trap 'rm -rf "$tmp"' exit | ||
|
|
||
| declare -A users=() | ||
| while read -r handle && [[ -n "$handle" ]]; do | ||
| users[$handle]= | ||
| done | ||
|
|
||
| # Cannot request a review from the author | ||
| if [[ -v users[${prAuthor,,}] ]]; then | ||
| log "One or more files are owned by the PR author, ignoring" | ||
| unset 'users[${prAuthor,,}]' | ||
| fi | ||
|
|
||
| gh api \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| "/repos/$baseRepo/pulls/$prNumber/reviews" \ | ||
| --jq '.[].user.login' > "$tmp/already-reviewed-by" | ||
wolfgangwalther marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # And we don't want to rerequest reviews from people who already reviewed | ||
| while read -r user; do | ||
| if [[ -v users[${user,,}] ]]; then | ||
| log "User $user is a code owner but has already left a review, ignoring" | ||
| unset 'users[${user,,}]' | ||
| 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" \ | ||
| "/repos/$baseRepo/collaborators/$user" >&2; then | ||
| log "User $user is not a repository collaborator, probably missed the automated invite to the maintainers team (see <https://github.com/NixOS/nixpkgs/issues/234293>), ignoring" | ||
JohnRTitor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| unset 'users[$user]' | ||
| fi | ||
| done | ||
|
|
||
| # Turn it into a JSON for the GitHub API call to request PR reviewers | ||
| jq -n \ | ||
| --arg users "${!users[*]}" \ | ||
| '{ | ||
| reviewers: $users | split(" "), | ||
| }' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.