1

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 ?

Tyteck
  • 135
  • 2
  • 12
  • I had the same issue. The solution for me was found here: https://stackoverflow.com/questions/72731726/how-do-i-capture-output-of-the-following-command-gh-workflow-run-id – Eyal Gerber Jul 03 '22 at 13:00

1 Answers1

3

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]

nhed
  • 5,774
  • 3
  • 30
  • 44
  • 1
    using following command line (on zsh) `output=$(gh pr list --search "review-requested:@me") && echo "--${output}--"` I'm getting `----` – Tyteck Jan 18 '22 at 08:27
  • 1
    by the way your last solution is working fine `output=$(gh api -X GET search/issues -f q='review:required user-review-requested:@me') && echo "$output"` is getting me `{"total_count":0,"incomplete_results":false,"items":[]}` so – Tyteck Jan 18 '22 at 08:40
  • @Tyteck I'm still not following if you are trying to get results for one specific repo or across github. – nhed Jan 18 '22 at 21:01
  • I want to get all PRs on all repos. eventually I want to have same level of informations you have on https://github.com/pulls/review-requested. – Tyteck Jan 19 '22 at 08:18
  • so yeah in that case i think the only option is that REST API bit in the second part of my answer as the `gh pr` (if not all subcommands aside for `api`) seem to be rep specific. – nhed Jan 21 '22 at 15:47