Skip to content

ref(providers): Route requests through a central template registry#113

Draft
billyvg wants to merge 1 commit into
mainfrom
refactor/github-route-registry
Draft

ref(providers): Route requests through a central template registry#113
billyvg wants to merge 1 commit into
mainfrom
refactor/github-route-registry

Conversation

@billyvg

@billyvg billyvg commented Jul 10, 2026

Copy link
Copy Markdown
Member

What

Introduces a shared Route/FormattedRoute helper (src/scm/providers/routes.py) and converts both the GitHub and GitLab providers to a central, inline route-template registry (class GitHub / class GitLab, both using Route(...)).

A Route couples a low-cardinality template (e.g. /repos/{repo}/issues/{issue_id}) with the concrete path it formats. The request layer unwraps the concrete path for the wire and attaches the template to any raised error via a typed exc.scm_route seam on SCMCodedError.

Why

Both providers built paths from inline f-strings, so the only route information available at error time was the fully-interpolated path — high cardinality, and for GitHub impossible to reliably template after the fact (file paths, branches, and refs contain literal slashes, so reverse-parsing an interpolated path is ambiguous). Carrying the template with the request makes the route reliably recoverable, giving a clean low-cardinality dimension for Sentry issue tagging/grouping.

This is structural readiness: scm_route is made available at the error seam but is deliberately not emitted here — it is kept off extra_attributes. Wiring it into error context lands when this merges with the RPC error-envelope work.

Behavior

  • No behavior change. Concrete request paths are byte-identical; the existing GitHub + GitLab provider suites are unchanged and green.
  • Scope: REST paths that flow through request() (including /graphql). Out of scope: _web_base_url builders and GraphQL query bodies.

Tests

  • tests/unit/provider/test_routes.pyRoute formatting, template preservation, and the slash-containing-param reliability property.
  • Per-provider seam tests asserting exc.scm_route carries the template on a >= 400.
  • Full suite: 791 passed; mypy and ruff clean.

🤖 Generated with Claude Code

Both providers built request paths from inline f-strings, so the only
route information reaching an error was the fully-interpolated path — high
cardinality and, for GitHub, impossible to reliably template after the fact
(file paths, branches, and refs contain literal slashes).

Introduce a shared Route/FormattedRoute helper and give each provider a
central inline route registry (class GitHub / class GitLab). A Route carries
its low-cardinality template alongside the concrete path, so the template
travels with the request instead of being reverse-parsed. The request layer
unwraps the concrete path for the wire and attaches the template to any
raised error via a typed exc.scm_route seam on SCMCodedError, making the
route reliably available at error time for Sentry tagging without emitting
per-request paths.

No behavior change: concrete request paths are byte-identical and the
existing provider suites are unchanged. Adds Route unit tests and a
per-provider seam test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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