fix: remaining ruff formatting issues and robust gitea auth
Ampel / ampel (push) Successful in 23s

This commit is contained in:
Hitonabi
2026-08-07 16:25:27 +02:00
parent e16f0140f7
commit ee456de713
4 changed files with 51 additions and 12 deletions
+1 -1
View File
@@ -33,11 +33,11 @@ from routers import (
maintenance, maintenance,
models, models,
routing, routing,
skills,
system, system,
voice, voice,
wissen, wissen,
zeitmaschine, zeitmaschine,
skills,
) )
from routers import reminders as reminders_router from routers import reminders as reminders_router
from services import metrics_history, reminders, sentry, warmer from services import metrics_history, reminders, sentry, warmer
+3 -2
View File
@@ -1,8 +1,9 @@
from fastapi import APIRouter
from pydantic import BaseModel
import os import os
import subprocess import subprocess
from fastapi import APIRouter
from pydantic import BaseModel
router = APIRouter(prefix="/api") router = APIRouter(prefix="/api")
class RunSkillRequest(BaseModel): class RunSkillRequest(BaseModel):
+18
View File
@@ -64,6 +64,24 @@ _FETCH_EVERY = 30.0 # s — Gitea nicht bei jedem UI-Poll anfragen
_CI_CACHE: dict = {} # { (repo, branch, head_sha): {"status": "success", "ts": time} } _CI_CACHE: dict = {} # { (repo, branch, head_sha): {"status": "success", "ts": time} }
def _gitea_creds() -> tuple | None: def _gitea_creds() -> tuple | None:
# 1. Fallback: Versuch via git credential manager (zukunftsfähig & plattformübergreifend)
try:
import subprocess
p = subprocess.run(
["git", "credential", "fill"],
input=b"protocol=https\nhost=git.tobisniceshomelab.ddnsfree.com\n",
capture_output=True,
check=True
)
out = p.stdout.decode(errors="replace")
u_match = re.search(r"username=(.+)", out)
p_match = re.search(r"password=(.+)", out)
if u_match and p_match:
return u_match.group(1).strip(), p_match.group(1).strip()
except Exception:
pass
# 2. Fallback: Datei (hauptsächlich auf der AI-Box genutzt)
try: try:
cred = Path("~/.git-credentials").expanduser() cred = Path("~/.git-credentials").expanduser()
for line in cred.read_text(encoding="utf-8").splitlines(): for line in cred.read_text(encoding="utf-8").splitlines():
+22 -2
View File
@@ -278,6 +278,26 @@ def apply_update(kind: str) -> str:
def get_ci_status() -> str: def get_ci_status() -> str:
"""Prüft den letzten CI-Build-Status auf der AI-Box via Gitea API. """Prüft den letzten CI-Build-Status auf der AI-Box via Gitea API.
Nützlich, um nach einem Push zu verifizieren, ob das Frontend und Backend grün gebaut haben.""" Nützlich, um nach einem Push zu verifizieren, ob das Frontend und Backend grün gebaut haben."""
token = ""
# 1. Fallback: Versuch via git credential manager (zukunftsfähig & plattformübergreifend)
try:
import subprocess
p = subprocess.run(
["git", "credential", "fill"],
input=b"protocol=https\nhost=git.tobisniceshomelab.ddnsfree.com\n",
capture_output=True,
check=True
)
out = p.stdout.decode(errors="replace")
import re
p_match = re.search(r"password=(.+)", out)
if p_match:
token = p_match.group(1).strip()
except Exception:
pass
# 2. Fallback: Datei (hauptsächlich auf der AI-Box genutzt)
if not token:
token_path = os.path.expanduser("~/.git-credentials") token_path = os.path.expanduser("~/.git-credentials")
try: try:
with open(token_path, "r") as f: with open(token_path, "r") as f:
@@ -289,7 +309,7 @@ def get_ci_status() -> str:
token = "" token = ""
if not token: if not token:
return "❌ Gitea Token in ~/.git-credentials nicht gefunden. CI Status kann nicht geprüft werden." return "❌ Gitea Token konnte nicht via 'git credential' oder ~/.git-credentials geladen werden. CI Status kann nicht geprüft werden."
# Gitea URL von der Box aus intern erreichbar # Gitea URL von der Box aus intern erreichbar
repo_url = "http://192.168.178.153:3000/api/v1/repos/Hitonabi/mission-control-v2/actions/runs?limit=1" repo_url = "http://192.168.178.153:3000/api/v1/repos/Hitonabi/mission-control-v2/actions/runs?limit=1"
@@ -312,7 +332,7 @@ def get_ci_status() -> str:
else: else:
return f"️ CI-Build ({name} @ {sha}) Status: {status}" return f"️ CI-Build ({name} @ {sha}) Status: {status}"
except Exception as e: except Exception as e:
return f"❌ Fehler bei der Gitea-API Abfrage: {str(e)}" return f"❌ Fehler bei der Gitea-API Abfrage: {e!s}"
# ── Erinnerungen & Routinen (A3): die Box sagt dem Commander zur Zeit aktiv Bescheid ───────── # ── Erinnerungen & Routinen (A3): die Box sagt dem Commander zur Zeit aktiv Bescheid ─────────
@mcp.tool() @mcp.tool()