Search code examples
githubgithub-apigithub-cli

Request PR review from team via CLI


GitHub's API has an endpoint to request reviewers for a pull request. Reviewers can be individual users (reviewers) or entire teams (team_reviewers) (teams can be created at the org level).

For instance, the following will request a PR review from Stack Overflow's SRE team:

curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/StackExchange/dnscontrol/pulls/930/requested_reviewers \
  -d '{"team_reviewers":["SRE"]}'

Similarly, in GitHub's CLI, the gh pr create command to create a pull request has a --reviewer flag, equivalent to the reviewers API parameter. So, as stated in the documentation, you can do the following to request a PR review from individual users:

$ gh pr create --reviewer monalisa,hubot

However, there doesn't appear to be a flag which is equivalent to the team_reviewers API parameter.

Is it possible to request a PR review from a team via the GitHub CLI?

UPDATE looking at the source of the CLI, --reviewer should just accept team names in the format org/teamname. I was just able to confirm it locally, but it's failing in a GitHub Actions workflow. Digging more...


Solution

  • Unlike the API, the CLI doesn't have a separate parameter. --reviewer just accepts team names in the format org/teamname as well. For example:

    $ gh pr create --reviewer stackexchange/sre
    

    (PR to document this a little better)

    Note that when doing this in GitHub Actions workflow, GITHUB_TOKEN won't have enough permissions to request a PR review from a team. You'll have to use a personal access token with additional permissions.