Skip to content

Commit 36166f7

Browse files
OhmSpectatorrouming
authored andcommitted
github/actions: exclude PR author from code owners review request.
The workflow has been updated to exclude the pull request author from the list of potential reviewers. This change addresses a GitHub API error where review requests failed if the author was also a code owner and thus included in the review request payload. The fix iterates over the list of reviewers and removes the PR author before constructing the JSON payload for the review request API call. Signed-off-by: Nikolay Martyanov <[email protected]>
1 parent b1fd32d commit 36166f7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

.github/workflows/request_codeowners_review.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ jobs:
5353
# Remove @ from reviewers (it stays in the beginning of the username)
5454
reviewers_cleaned=${reviewers//@/}
5555
IFS=' ' read -ra reviewers_array <<< "$reviewers_cleaned"
56-
json_array=$(printf ',\"%s\"' "${reviewers_array[@]}")
57-
json_array="[${json_array:1}]" # Remove the leading comma
58-
echo "JSON array: $json_array"
59-
60-
if [ -n "$reviewers" ]; then
61-
echo "Requesting review from: ${reviewers_array[*]}"
56+
# Get username of PR author to exclude from reviewers
57+
pr_author="${{ github.event.pull_request.user.login }}"
58+
# Remove PR author from reviewers
59+
filtered_reviewers=()
60+
for reviewer in ${reviewers_array[@]}; do
61+
if [[ "$reviewer" != "$pr_author" ]]; then
62+
filtered_reviewers+=("$reviewer")
63+
fi
64+
done
65+
if [ ${#filtered_reviewers[@]} -gt 0 ]; then
66+
json_array=$(printf ',\"%s\"' "${filtered_reviewers[@]}")
67+
json_array="[${json_array:1}]" # Remove the leading comma
68+
echo "JSON array: $json_array"
69+
echo "Requesting review from: ${filtered_reviewers[*]}"
6270
echo https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers
6371
curl -L \
6472
-D - \

0 commit comments

Comments
 (0)