Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

55 lines
1.8 KiB
Python

"""GitHub API helpers with caching."""
from __future__ import annotations
import shutil
import subprocess
_team_slugs: set[str] | None = None
_fetch_err: str = ""
_fetch_attempted: bool = False
_ORG = "Insights"
def get_team_slugs() -> tuple[set[str] | None, str]:
"""Fetch GitHub team slugs visible in the Insights org. Cached after the first call.
Uses ``/orgs/{org}/teams`` (requires ``members: read``) rather than the
repo-collaborator endpoint ``/repos/{repo}/teams``. The repo endpoint would
be the tighter check semantically (the reviewer assignment API only accepts
repo collaborator teams), but the assign-reviewers GitHub App doesn't have
the scope for it. The "team exists in org but lacks repo access" gap is
covered defensively by assign-reviewers.js's 422 fallback, which retries
each team individually and logs the bad slugs.
Returns ``(slugs, error_message)``. ``slugs`` is ``None`` when the fetch failed.
"""
global _team_slugs, _fetch_err, _fetch_attempted
if _fetch_attempted:
return _team_slugs, _fetch_err
_fetch_attempted = True
if not shutil.which("gh"):
_fetch_err = "gh CLI not found — install it to validate owner team slugs"
return None, _fetch_err
try:
result = subprocess.run(
["gh", "api", f"orgs/{_ORG}/teams", "--paginate", "--jq", ".[].slug"],
capture_output=True,
text=True,
timeout=15,
)
if result.returncode == 0 and result.stdout.strip():
_team_slugs = set(result.stdout.strip().split("\n"))
return _team_slugs, ""
_fetch_err = f"gh api failed (rc={result.returncode}): {result.stderr.strip()}"
return None, _fetch_err
except subprocess.TimeoutExpired:
_fetch_err = "gh api timed out after 15s"
return None, _fetch_err