fix(ci): use --jq '.[]' to flatten gh api --paginate output

The check-duplicate workflow's auto-close step failed with:

  json.decoder.JSONDecodeError: Unterminated string starting at:
  line 1 column 2856598

`gh api --paginate` without --jq concatenates each page's response as a
pretty-printed JSON array spanning many lines; splitting that on newlines
and feeding individual lines to json.loads cannot work. Pass --jq '.[]'
so each issue is emitted as a single line of JSON, which the line-by-line
parser handles correctly.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-05-19 19:51:21 +00:00
parent 727a471ae9
commit 846e60a319
No known key found for this signature in database

View file

@ -47,20 +47,19 @@ def fetch_open_issues(repo: str | None) -> list[dict]:
)
else:
endpoint = "repos/{owner}/{repo}/issues?state=open&per_page=100&sort=created&direction=asc"
cmd = ["api", "--paginate", endpoint]
# Use --jq '.[]' so each page is flattened to one JSON object per line.
# Without --jq, gh prints each page as a pretty-printed JSON array spanning
# many lines, and across multiple pages the arrays are concatenated — which
# is not parseable as a single JSON document nor as line-delimited JSON.
cmd = ["api", "--paginate", endpoint, "--jq", ".[]"]
raw = gh(*cmd)
# gh --paginate concatenates JSON arrays, so we may get multiple arrays
issues = []
for line in raw.strip().splitlines():
for line in raw.splitlines():
line = line.strip()
if not line:
continue
parsed = json.loads(line)
if isinstance(parsed, list):
issues.extend(parsed)
else:
issues.append(parsed)
issues.append(json.loads(line))
# Filter out pull requests (they also appear in the issues endpoint)
return [i for i in issues if "pull_request" not in i]