Skip to content

Add shared public JSON fetch helper for maintenance scripts (#1144)#1174

Open
yanyishuai wants to merge 1 commit into
ramimbo:mainfrom
yanyishuai:fix/issue-1144-shared-json-fetch
Open

Add shared public JSON fetch helper for maintenance scripts (#1144)#1174
yanyishuai wants to merge 1 commit into
ramimbo:mainfrom
yanyishuai:fix/issue-1144-shared-json-fetch

Conversation

@yanyishuai

Copy link
Copy Markdown

Summary

Adds scripts/public_json_fetch.py exposing one load_public_json helper plus a PublicJsonError for read-only public JSON fetches. Migrates scripts/claim_inventory.py to call the new helper while preserving its existing _get_json wrapper (callers see no behaviour change). Adds tests/test_public_json_fetch.py covering the happy path, default headers, HTTP error, timeout, invalid JSON, and custom timeout.

Why

Five maintenance scripts (claim_inventory, submission_quality_gate, proposed_work_triage, check_bounty_issue_states, check_live_bounty_closing_refs) each implemented their own small public-JSON fetch helper around urllib.request.urlopen. They did not agree on Accept headers, timeout values, or error wording. A future bugfix to any of those details had to be copy-pasted across files and the error wording silently diverged. This PR ships the helper plus one concrete migration so the contract is proven on a real caller; the remaining scripts can be migrated in follow-up PRs.

Behavior

  • New: load_public_json(url, description=None, timeout=30, user_agent="mergework-maintenance-script", accept="application/json") -> Any.
  • New: PublicJsonError raised on HTTP error, network/timeout failure, or invalid JSON, with a uniform "{description} unavailable: ..." message.
  • Migrated: scripts/claim_inventory.py::_get_json now delegates to load_public_json and threads the existing GH_TIMEOUT_SECONDS constant.

Tests

  • New tests/test_public_json_fetch.py (6 cases).
  • Full suite: 919 passed.

Out of scope

  • Migrating the other four scripts to the new helper; that is follow-up work.

Closes #1144

Solana wallet for bounty payout: Do4v7foHJvRJLpRRoGaVPWX6DDEjX3yTK7J91gpwUQpE

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@yanyishuai, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 52 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4b2996d7-d4d6-4d1a-927d-5f422ac41a00

📥 Commits

Reviewing files that changed from the base of the PR and between 3bc87d2 and 4038298.

📒 Files selected for processing (5)
  • app/work_discovery.py
  • scripts/claim_inventory.py
  • scripts/public_json_fetch.py
  • tests/test_public_json_fetch.py
  • tests/test_work_discovery.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qingfeng312 qingfeng312 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding:

  • [P1] Fix the ruff failures introduced by the new public JSON helper before merge. The current head 31692e94afc796a6256c17d084ab5c038acf3b05 passes pytest (911 passed, 1 warning), but CI fails at ruff check . with six issues: scripts/claim_inventory.py still imports unused urllib.request, its local script imports are unsorted, tests/test_public_json_fetch.py has a quoted _FakeResponse return annotation, and three nested with patch(...): with pytest.raises(...) blocks trigger SIM117. Please remove the stale import, organize the imports, and apply the test-style cleanups so the lint gate passes.

Evidence checked:

  • PR #1174 is open, non-draft, and authored by another account.
  • Inspected scripts/claim_inventory.py, scripts/public_json_fetch.py, and tests/test_public_json_fetch.py.
  • Checked CI run 28329923637: pytest passed, formatting passed, then ruff check . failed with the listed errors.

Scope boundary: review evidence only. No wallet signing, treasury mutation, payout execution, exchange, bridge, private data, credentials, or secrets involved.

@yanyishuai yanyishuai force-pushed the fix/issue-1144-shared-json-fetch branch from 31692e9 to 4038298 Compare June 29, 2026 04:42
@yanyishuai

Copy link
Copy Markdown
Author

@qingfeng312 Ruff issues fixed.

  • Removed stale urllib.request import from migrated claim_inventory.py
  • Sorted imports, fixed SIM117 nested-with blocks and UP037 in tests/test_public_json_fetch.py

Latest head: 40382987dbf7. CI: pass. Please re-review.

@yanyishuai

Copy link
Copy Markdown
Author

@qingfeng312 CI is green on the latest head (40382987dbf7) for #1144. Could you take another look when you have a moment?

1 similar comment
@yanyishuai

Copy link
Copy Markdown
Author

@qingfeng312 CI is green on the latest head (40382987dbf7) for #1144. Could you take another look when you have a moment?

@qingfeng312 qingfeng312 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on current head 40382987dbf7bebd1f75ce85981c3d6f88297799.

The earlier Ruff lint blocker has been resolved. I rechecked scripts/public_json_fetch.py, the claim_inventory migration, and tests/test_public_json_fetch.py.

The new helper centralizes public JSON fetching without changing the existing _get_json caller contract, preserves the timeout wiring, and covers HTTP, timeout, invalid JSON, custom timeout, and header behavior in focused tests.

Validation checked: GitHub CI Quality, readiness, docs, and image checks passed on run 28349126882; CodeRabbit status is success on this head. I did not find a remaining blocker for the scoped #1144 change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposed work: consolidate shared public JSON fetch helper for maintenance scripts

2 participants