Search code examples
github-cli

How to capture github-cli pr list


In a shell script I would like to capture result of

output=$(gh pr list --search "review:required user-review-requested:@me")
echo "output : $output"

unfortunately output is empty.

I tried to set pager but failed to do it properly.

gh config set pager more
gh config set pager cat
gh config set pager ''

Have you any clue ?


Solution

  • Are you trying to query the repo that you have cloned locally?

    If so

    output=$(gh pr list --search "review-requested:@me")
    echo ${output}
    ...lists prs requested from me...
    

    (That query derived from the one listed in the UI for https://github.com/pulls/review-requested)

    Or all of github?

    If trying to list in all of github you need to do something slightly different as the above API is repo specific

    If you want to get a list of pull requests across all repos you can use gh api directly, an the help for that actually gives search/issues as an example. Pull requests in GH nomenclature are issues of a certain type (the issue and PR numbers come out of the same enumeration).

    Didn't quite follow from your question what it is that you wanted to list about the PRs.

    To dump all the data in json:

    gh api -X GET search/issues -f q='review:required user-review-requested:@me'
    

    If you wanted to narrow it down to list of PR URLs you could add a `jq expression:

    gh api -X GET search/issues \
        -f q='review:required user-review-requested:@me' \
        --jq '.items[].html_url'
    

    [Can continue discussion of what specifically you want to see in output once you clarify the question]