Skip to content

Rewrite Python services in Go - #20

Open
tamalsaha wants to merge 1 commit into
masterfrom
rewrite/go
Open

tamalsaha wants to merge 1 commit into
masterfrom
rewrite/go

Conversation

@tamalsaha

Copy link
Copy Markdown

Summary

  • Replaces the FastAPI bot/ and Django web_api/ with a single Go module at the repo root. Both binaries plus three job binaries (ingest-events, aggregate-pr-activity, aggregate-user-activity) build cleanly under cmd/.
  • Moves the original Python sources to legacy/ as porting reference. web_ui/ (React) and docs/ (Docusaurus) are unchanged.
  • Bot port covers webhook HMAC verify, JWT app auth + installation token cache, REST methods, the full GetEventInfo GraphQL query, the per-installation webhook queue and per-repo merge queue on Redis sorted sets (with restart restoration), and the complete Mergeable() decision tree from evaluation.py (branch protection, paywall, auto-approve, automerge label, conflict handling, blacklists, BLOCKED/BEHIND review counting with the travis-ci special case, skippable contexts, optimistic vs status-check prioritization, do_not_merge, prioritize_ready_to_merge).
  • Web API port covers chi router with every route from core/urls.py, HMAC-signed session cookies in place of Django sessions, pgx store layer, and end-to-end implementations of oauth_login, ping, logout, accounts, current_account, and activity. Stripe billing handlers (update_subscription, start_checkout, cancel_subscription, etc.) and the OAuth token exchange portion of oauth_complete are intentionally HTTP 501 with one-line TODOs pointing at the corresponding legacy view — they need stripe-go wiring.
  • Dockerfiles: multi-stage Go + distroless at the repo root (Dockerfile.bot, Dockerfile.webapi). CI: new .github/workflows/go.yml and a rewritten .circleci/config.yml that drops the old bot_*/web_api_* jobs and adds go_build + go_docker_*.

go build ./... && go vet ./... && go test ./... is clean.

Test plan

  • go build ./... && go vet ./... pass on CI
  • docker build -f Dockerfile.bot . and docker build -f Dockerfile.webapi . succeed
  • Bot smoke test: send a signed pull_request webhook to a local cmd/bot and confirm a WebhookEvent lands on the webhook:<installation_id> Redis sorted set
  • Web API smoke test: hit GET /v1/ping (200), GET /v1/oauth_login (302 to GitHub), GET /v1/accounts without a session cookie (401)
  • Confirm the legacy Python services under legacy/bot/ and legacy/web_api/ are git-tracked but no longer referenced by any active CI job
  • Follow-up: port Stripe billing handlers (9 endpoints) and the oauth_complete token exchange before retiring the legacy services in production

Replaces the FastAPI bot and Django dashboard API with Go binaries built
from a single module rooted at the repo top level. The original Python
sources move to legacy/ as porting reference; web_ui/ and docs/ are
untouched.

New binaries (all under cmd/):

  - bot                       webhook receiver + per-PR merge evaluator
  - webapi                    dashboard API (chi + pgx + signed sessions)
  - ingest-events             Redis→Postgres webhook envelope ingestor
  - aggregate-pr-activity     per-day PR rollup
  - aggregate-user-activity   per-user PR rollup

Bot internals (internal/bot/):

  - JWT App auth + cached installation tokens
  - GitHub REST methods (merge, update branch, comment, labels, check
    runs, collaborator permission)
  - Full GetEventInfo GraphQL query and response parser
  - Per-installation webhook queue and per-repo merge queue on Redis
    sorted sets, with restart restoration via the *_queue_names sets
  - Full Mergeable() decision tree ported from evaluation.py — config
    validation, branch protection, push allowances, paywall, auto-approve,
    automerge label, conflict handling, blacklists, draft state, BLOCKED
    /BEHIND review counting with travis-ci special case, skippable
    contexts with retry budget, optimistic update vs status-check
    prioritization, do_not_merge, prioritize_ready_to_merge, queue
    position rendering
  - MergeBody builder including PR-number suffix and co-author trailers

Web API internals (internal/webapi/):

  - chi router with every route from core/urls.py
  - HMAC-signed session cookies in place of Django sessions
  - pgx store layer over typed row structs in models/
  - OAuth login redirect, ping, accounts, current_account, activity
    handlers wired end-to-end. Stripe billing handlers and the OAuth
    token exchange are explicit HTTP 501 stubs with one-line TODOs
    pointing at their legacy implementations.
  - SQL rollups for pull_request_activity and user_pull_request_activity

Build / CI:

  - Dockerfile.bot and Dockerfile.webapi (multi-stage Go + distroless)
  - .github/workflows/go.yml runs build/vet/test + image builds
  - .circleci/config.yml rewritten: replaces bot_*/web_api_* Python
    jobs with go_build + go_docker_bot + go_docker_webapi; docs/web_ui
    pipelines unchanged

Signed-off-by: Tamal Saha <tamal@appscode.com>
@tamalsaha
tamalsaha changed the base branch from master to pr/187 June 11, 2026 04:54
@tamalsaha
tamalsaha changed the base branch from pr/187 to master June 11, 2026 04:54
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.

1 participant