Skip to content
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

ci/request-reviews: Avoid duplicates with different casings #348030

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ci/request-reviews/get-reviewers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ log "This PR touches ${#touchedFiles[@]} files"
git -C "$gitRepo" show "$baseRef":"$ownersFile" > "$tmp"/codeowners

# Associative array with the user as the key for easy de-duplication
# Make sure to always lowercase keys to avoid duplicates with different casings
declare -A users=()

for file in "${touchedFiles[@]}"; do
Expand Down Expand Up @@ -87,20 +88,20 @@ for file in "${touchedFiles[@]}"; do
log "Team $entry has these members: ${members[*]}"

for user in "${members[@]}"; do
users[$user]=
users[${user,,}]=
done
else
# Everything else is a user
users[$entry]=
users[${entry,,}]=
fi
done

done

# Cannot request a review from the author
if [[ -v users[$prAuthor] ]]; then
if [[ -v users[${prAuthor,,}] ]]; then
log "One or more files are owned by the PR author, ignoring"
unset 'users[$prAuthor]'
unset 'users[${prAuthor,,}]'
fi

gh api \
Expand All @@ -111,9 +112,9 @@ gh api \

# And we don't want to rerequest reviews from people who already reviewed
while read -r user; do
if [[ -v users[$user] ]]; then
if [[ -v users[${user,,}] ]]; then
log "User $user is a code owner but has already left a review, ignoring"
unset 'users[$user]'
unset 'users[${user,,}]'
fi
done < "$tmp/already-reviewed-by"

Expand Down