mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 08:03:15 +00:00
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""Per-repository opt-ins for automatic reviewer verdicts."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from datetime import UTC, datetime
|
|
|
|
from langgraph_sdk import get_client
|
|
|
|
from .review_styles import normalize_repo_full_name
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
AUTO_VERDICT_REPOS_NAMESPACE: list[str] = ["auto_verdict_repos"]
|
|
AUTO_VERDICT_REPOS_KEY = "default"
|
|
|
|
|
|
def _client():
|
|
return get_client()
|
|
|
|
|
|
async def list_auto_verdict_repos() -> list[str]:
|
|
try:
|
|
item = await _client().store.get_item(AUTO_VERDICT_REPOS_NAMESPACE, AUTO_VERDICT_REPOS_KEY)
|
|
except Exception as e:
|
|
logger.debug("auto-verdict repos lookup failed: %s", e)
|
|
return []
|
|
if item is None:
|
|
return []
|
|
value = item.get("value") if isinstance(item, dict) else getattr(item, "value", None)
|
|
if not isinstance(value, dict):
|
|
return []
|
|
repos = value.get("repos")
|
|
if not isinstance(repos, list):
|
|
return []
|
|
return [repo for repo in repos if isinstance(repo, str)]
|
|
|
|
|
|
async def set_auto_verdict_repo_enabled(full_name: str, enabled: bool) -> list[str]:
|
|
full_name = normalize_repo_full_name(full_name)
|
|
current = set(await list_auto_verdict_repos())
|
|
if enabled:
|
|
current.add(full_name)
|
|
else:
|
|
current.discard(full_name)
|
|
repos = sorted(current)
|
|
await _client().store.put_item(
|
|
AUTO_VERDICT_REPOS_NAMESPACE,
|
|
AUTO_VERDICT_REPOS_KEY,
|
|
{"repos": repos, "updated_at": datetime.now(UTC).isoformat()},
|
|
)
|
|
return repos
|
|
|
|
|
|
async def is_auto_verdict_repo_enabled(owner: str, name: str) -> bool:
|
|
if not owner or not name:
|
|
return False
|
|
full_name = f"{owner.lower()}/{name.lower()}"
|
|
enabled = await list_auto_verdict_repos()
|
|
return any(repo.lower() == full_name for repo in enabled)
|