hkusu / review-assign-action

GitHub Actions to automatically set assignees and reviewers on pull requests.
MIT License
34 stars 7 forks source link

Question: how to set the reviewers as assignees? #16

Open ebramirez opened 2 years ago

ebramirez commented 2 years ago

Is it possible to reuse the current PR reviewers value as the assignees of an Action run?

The use case would be when the author of the PR pushes more commits as a result of a review, the assignment returns to the reviewers. Example:

on:
  pull_request:
    types: [synchronized]

jobs:
  assign:
    runs-on: ubuntu-latest
    steps:
      - uses: hkusu/review-assign-action@v1
        with:
          assignees: ${{ github.event.pull_request.reviewers ??? }}
hkusu commented 1 year ago

For the same as #15, it is not possible, because this Action can only set the assignee when the pull request is opened.

In the same way, I think you can use the GitHub CLI to do something like:

- run: |
    reviewersJson='${{ toJson(github.event.pull_request.requested_reviewers.*.login) }}'
    reviewers=$(echo $reviewersJson | jq -r '.[]')
    reviewers=$(echo $reviewers) # remove newline
    reviewers=${reviewers// /,} # spaces to commas
    gh pr edit ${{ github.event.number }} --add-assignee $reviewers --repo ${{ github.repository }}
  env:
    GITHUB_TOKEN: ${{ github.token }}