From 60773fe3c402137cda6c4bf5f93d670f6bc5ad84 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 22 Oct 2025 17:52:16 +0200 Subject: [PATCH] ci/request-reviews/get-code-owners.sh: First-class code owner team review requests --- ci/request-reviews/get-code-owners.sh | 40 ++++----------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/ci/request-reviews/get-code-owners.sh b/ci/request-reviews/get-code-owners.sh index 13a377429b92..e49bb5409828 100755 --- a/ci/request-reviews/get-code-owners.sh +++ b/ci/request-reviews/get-code-owners.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Get the code owners of the files changed by a PR, returning one username per line +# Get the code owners of the files changed by a PR, returning one GitHub user/team handle per line set -euo pipefail @@ -29,9 +29,9 @@ log "This PR touches ${#touchedFiles[@]} files" # remove code owners to avoid pinging them git -C "$gitRepo" show "$baseRef":"$ownersFile" > "$tmp"/codeowners -# Associative array with the user as the key for easy de-duplication +# Associative array with the user/team as the key for easy de-duplication # Make sure to always lowercase keys to avoid duplicates with different casings -declare -A users=() +declare -A finalOwners=() for file in "${touchedFiles[@]}"; do result=$(codeowners --file "$tmp"/codeowners "$file") @@ -59,39 +59,9 @@ for file in "${touchedFiles[@]}"; do # The first regex match is everything after the @ entry=${BASH_REMATCH[1]} - if [[ "$entry" =~ (.*)/(.*) ]]; then - # Teams look like $org/$team - org=${BASH_REMATCH[1]} - team=${BASH_REMATCH[2]} - - # Instead of requesting a review from the team itself, - # we request reviews from the individual users. - # This is because once somebody from a team reviewed the PR, - # the API doesn't expose that the team was already requested for a review, - # so we wouldn't be able to avoid rerequesting reviews - # without saving some some extra state somewhere - - # We could also consider implementing a more advanced heuristic - # in the future that e.g. only pings one team member, - # but escalates to somebody else if that member doesn't respond in time. - gh api \ - --cache=1h \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/orgs/$org/teams/$team/members" \ - --jq '.[].login' > "$tmp/team-members" - readarray -t members < "$tmp/team-members" - log "Team $entry has these members: ${members[*]}" - - for user in "${members[@]}"; do - users[${user,,}]= - done - else - # Everything else is a user - users[${entry,,}]= - fi + finalOwners[${entry,,}]= done done -printf "%s\n" "${!users[@]}" +printf "%s\n" "${!finalOwners[@]}"