Skip to content

refactor(analytics): extract _resolve_source_or_404 to shared analytics helper #3440

@mrveiss

Description

@mrveiss

Problem

_resolve_source_or_404 is copy-pasted into all 4 analytics modules introduced in #3436:

  • api/analytics_quality.py
  • api/analytics_evolution.py
  • api/analytics_code_review.py
  • api/analytics_code_generation.py

The copies are also inconsistent: two lazy-import HTTPException inside the function body while two rely on a module-level import — the docstring says "lazy import" in all four which is misleading.

Fix

Extract to a single shared location, e.g. a new autobot-backend/api/analytics_shared.py:

```python
async def resolve_source_or_404(source_id: Optional[str]) -> None:
"""Raise HTTP 404 if source_id is provided but not found."""
if source_id is None:
return
from api.codebase_analytics.endpoints.shared import resolve_source_root
source_root = await resolve_source_root(source_id)
if not source_root:
raise HTTPException(status_code=404, detail=f"Source '{source_id}' not found")
```

Import from there in each of the 4 modules and remove the local copies.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions