Skip to content

Commit

Permalink
[WIP] Check permission
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Martyanov <[email protected]>
  • Loading branch information
OhmSpectator authored and eriknordmark committed Nov 2, 2023
1 parent 25d98d2 commit 2b92689
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/request_codeowners_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 2b92689

Please sign in to comment.