Extract bounty API routes from app.main#393
Conversation
Moves bounty listing, CRUD, payment, close, and reconciliation route
registration out of the main application module into a focused
app/bounty_api module.
What moved:
- list_bounties_by_status search/filter logic
- GET /api/v1/bounties and /api/v1/bounties/summary
- GET /api/v1/bounties/{bounty_id}
- POST /api/v1/bounties (create)
- POST /api/v1/bounties/{bounty_id}/pay
- POST /api/v1/bounties/{bounty_id}/close
- GET /api/v1/reconciliation/payouts
- GET /api/v1/admin/webhook-events
- Payout response shaping helpers
main.py drops from 1427 to 1196 lines. The bounty page routes in
main.py now call through the returned functions from
register_bounty_api_routes, keeping the same public behavior.
13 new route-level tests cover status filtering, query search,
auth gating on admin-only endpoints, and error responses.
Checks: 384 passed, ruff format/check clean, mypy clean.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors bounty-related REST API endpoints from ChangesBounty API Module Extraction
Sequence DiagramsequenceDiagram
participant Admin
participant BountyAPI
participant Ledger
Admin->>BountyAPI: POST /api/v1/bounties/{id}/pay
BountyAPI->>BountyAPI: validate_public_url(), normalize input
BountyAPI->>Ledger: pay_bounty() with verifier
alt Already paid
Ledger-->>BountyAPI: LedgerError("submission already paid")
BountyAPI->>BountyAPI: _existing_payout_proof_for_submission()
BountyAPI-->>Admin: HTTP 409 already_paid payload
else Success
Ledger-->>BountyAPI: Proof object
BountyAPI->>BountyAPI: _payout_response_from_proof()
BountyAPI-->>Admin: HTTP 200 payout response
else Validation error
Ledger-->>BountyAPI: LedgerError
BountyAPI-->>Admin: HTTP 400 error detail
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
MolhamHamwi
left a comment
There was a problem hiding this comment.
Reviewed current head $(git rev-parse --short HEAD) for the bounty API route extraction.
Evidence checked:
- Inspected
app/bounty_api.py,app/main.py, andtests/test_bounty_api.py; the extracted registration keeps the existing route dependencies explicit (require_admin_token, JSON/body validators, settings, and db URL) and returns the callback hooks thatapp.mainstill uses for bounty pages. - Verified search/status behavior remains covered in the new focused test file, including query escaping/status filtering and issue-number search paths.
- Re-ran the focused behavior and static checks locally:
python -m pytest tests/test_bounty_api.py tests/test_bounty_pages.py tests/test_bounty_attempts.py -q-> 24 passedpython -m ruff check app/bounty_api.py app/main.py tests/test_bounty_api.py-> passedpython -m ruff format --check app/bounty_api.py app/main.py tests/test_bounty_api.py-> passedpython -m mypy app/main.py app/bounty_api.py-> passedgit diff --check origin/main...HEAD-> passed
No blockers found.
tolga-tom-nook
left a comment
There was a problem hiding this comment.
Reviewed current head 0111eaa for PR #393. No blockers from this pass.
Evidence checked:
- Inspected
app/bounty_api.py, the removed bounty/admin/reconciliation route registrations inapp/main.py, andtests/test_bounty_api.py. - Verified the extracted
register_bounty_api_routes()keeps the existing listing, summary, detail, admin webhook-events, create, pay, close, and payout reconciliation route shapes wired through injected helpers/settings. - Checked the payout idempotency path still returns the existing proof payload on
submission already paid, and that invalid bounty ids still pass throughpositive_bounty_id()before DB access. - Confirmed the new focused tests cover public list/detail validation plus auth gates for create/pay/close/reconciliation/webhook-events.
Validation run locally on head 0111eaa:
./.venv/bin/python -m pytest tests/test_bounty_api.py tests/test_api_mcp.py::test_health_status_and_bounty_api tests/test_api_mcp.py::test_bounty_api_reports_multi_award_capacity tests/test_api_mcp.py::test_bounty_api_reports_paid_multi_award_as_exhausted tests/test_api_mcp.py::test_bounty_api_reports_closed_multi_award_as_unavailable -q-> 17 passed./.venv/bin/python -m pytest -q-> 384 passed./.venv/bin/python -m ruff check app/bounty_api.py app/main.py tests/test_bounty_api.py-> passed./.venv/bin/python -m ruff format --check app/bounty_api.py app/main.py tests/test_bounty_api.py-> passed./.venv/bin/python -m mypy app-> passed
Problem
app/main.pywas 1427 lines with bounty listing, CRUD, payment, close, reconciliation, and webhook-events routes all defined inline. This made the file harder to navigate and review independently from page routes, wallet routes, auth routes, etc.Changes
Moved bounty API route registration into
app/bounty_api.py:list_bounties_by_status()— search/filter with status normalization, LIKE escaping, and issue-number lookupGET /api/v1/bountiesand/api/v1/bounties/summaryGET /api/v1/bounties/{bounty_id}POST /api/v1/bounties(create, admin-only)POST /api/v1/bounties/{bounty_id}/pay(admin-only)POST /api/v1/bounties/{bounty_id}/close(admin-only)GET /api/v1/reconciliation/payouts(admin-only)GET /api/v1/admin/webhook-events(admin-only)_payout_response_from_proof()and_existing_payout_proof_for_submission()helpersThe extracted
register_bounty_api_routes()returnslist_bounties_by_statusandget_bounty_detailso page routes inapp/main.pycan call them without duplicating the search logic.Complexity reduced
app/main.pydrops from 1427 to 1196 lines (−231 lines). Bounty CRUD/payment/close routes are now independently reviewable. The pattern matches existing extraction modules (register_account_routes,register_activity_routes,register_bounty_attempt_routes).Verification
No public API, MCP, ledger, wallet, webhook, admin, or page behavior changed.
Refs #390
Summary by CodeRabbit
Release Notes
New Features
Tests