From 2b92689cfa227727c9f29c7271db433dbfa634c6 Mon Sep 17 00:00:00 2001 From: Nikolay Martyanov Date: Fri, 13 Oct 2023 14:10:26 +0200 Subject: [PATCH] [WIP] Check permission Signed-off-by: Nikolay Martyanov --- .../workflows/request_codeowners_review.yml | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/request_codeowners_review.yml b/.github/workflows/request_codeowners_review.yml index bce384d216..66422938c3 100644 --- a/.github/workflows/request_codeowners_review.yml +++ b/.github/workflows/request_codeowners_review.yml @@ -9,7 +9,7 @@ jobs: auto_request_review: runs-on: ubuntu-latest permissions: - pull-requests: "write" + pull-requests: write steps: - name: Calculate fetch-depth id: calc @@ -51,15 +51,21 @@ jobs: if [ -n "$reviewers" ]; then # Remove @ from reviewers (it stays in the beginning of the username) reviewers_cleaned=${reviewers//@/} - # Convert reviewers to comma separated list - reviewers_comma_separated=$(echo "$reviewers_cleaned" | tr ' ' ',') - echo "Requesting review from: $reviewers_comma_separated" - curl \ + # Convert the space-separated usernames into a Bash array + IFS=' ' read -ra reviewers_array <<< "$reviewers_cleaned" + # Convert the Bash array into a JSON array string + json_array="[\"$(echo "${reviewers_array[@]}" | tr ' ' '","' )\"]" + echo "Requesting review from: ${reviewers_array[*]}" + echo "JSON array: $json_array" + echo https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers + curl -L \ + -D - \ -X POST \ - -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \ - -d '{"reviewers": ["'"$reviewers_comma_separated"'"]}' + -d "{\"reviewers\": $json_array}" else echo "No reviewers found for the changed files." fi