When your code depends on GitHub (or other remote) APIs, pagination and per-item mutations are often the dominant performance cost. Structure workflows/scripts to avoid redundant full scans and to prevent N+1 API patterns unless the workload is provably small.
Apply this standard:
gh api --paginate.Example pattern (avoid re-paginating; pass comment_id forward):
- name: Post status comment
id: post_status
if: ${{ always() }}
run: |
set -euo pipefail
MARKER='<!-- autofix-status -->'
# Locate or create status comment, then output its id
STATUS_ID=$(gh api "repos/${REPO}/issues/${PR}/comments" --paginate \
| jq -rs --arg m "$MARKER" --arg ab "$AUTOFIX_BOT" \
'[.[][] | select((.user.login // "") == $ab) | select((.body // "") | contains($m))] | last | .id // empty')
if [[ -z "$STATUS_ID" ]]; then
STATUS_ID=$(gh api "repos/${REPO}/issues/${PR}/comments" -f body="..." --jq '.id')
else
gh api --method PATCH "repos/${REPO}/issues/comments/${STATUS_ID}" -f body="..." >/dev/null
fi
echo "comment_id=$STATUS_ID" >> "$GITHUB_OUTPUT"
- name: Finalize
if: ${{ always() }}
run: |
set -euo pipefail
STATUS_ID='${{ steps.post_status.outputs.comment_id }}'
# Use STATUS_ID directly; do NOT re-run --paginate here.
echo "Using status comment id: $STATUS_ID"
This reduces execution time, API usage, and flakiness from rate limits—especially across repeated rounds or high-comment PRs.
Enter the URL of a public GitHub repository