Homebrew / actions

🚀 Homebrew's GitHub Actions
BSD 2-Clause "Simplified" License
122 stars 39 forks source link

limit-pull-requests: do not use `gh pr list` #499

Closed ZhongRuoyu closed 8 months ago

ZhongRuoyu commented 8 months ago

gh pr list does not list any PRs from users with a private profile (cli/cli#6879), so let's use another method to count PRs.

This allows us to have a limit higher than 99 too, though not quite necessary.

Before:

$ gh pr list --state=open --author=BrewTestBot --json=number --jq=length --limit=100
23

After:

$ gh api \
  --method GET \
  --header 'Accept: application/vnd.github+json' \
  --header 'X-GitHub-Api-Version: 2022-11-28' \
  --field state=open \
  --paginate \
  '/repos/Homebrew/homebrew-core/pulls' |
  jq \
    --raw-output \
    --arg USER 'BrewTestBot' \
    'map(select(.user.login == $USER)) | length'
23
Bo98 commented 8 months ago

Honestly we probably should just use Octokit.js instead in actions like this as it has much less quirks and this is not the first time we've been bitten by gh doing a ton of extra logic we don't want.