initial commit
Some checks failed
CI / Run tests (push) Has been cancelled
CI / Docker build test (push) Has been cancelled
CI / Lint (ruff + mypy) (push) Has been cancelled

This commit is contained in:
2026-03-30 16:46:26 +07:00
commit 2a7dfa95c8
67 changed files with 5864 additions and 0 deletions

View File

View File

@@ -0,0 +1,17 @@
from fastapi import FastAPI
from glitchup_bot.api.webhook import router as webhook_router
def create_app() -> FastAPI:
application = FastAPI(title="GlitchUp Bot", version="0.1.0")
application.include_router(webhook_router)
@application.get("/health")
async def health() -> dict[str, str]:
return {"status": "ok"}
return application
app = create_app()

View File

@@ -0,0 +1,25 @@
from pydantic import BaseModel, Field
class WebhookField(BaseModel):
title: str
value: str
short: bool = False
class WebhookAttachment(BaseModel):
title: str
title_link: str | None = None
text: str | None = None
image_url: str | None = None
color: str | None = None
fields: list[WebhookField] | None = None
mrkdown_in: list[str] | None = None
class GlitchTipWebhookPayload(BaseModel):
text: str
attachments: list[WebhookAttachment] = Field(default_factory=list)
def is_uptime_alert(self) -> bool:
return "uptime" in self.text.lower()

View File

@@ -0,0 +1,25 @@
import logging
from fastapi import APIRouter, Header, HTTPException, Request
from glitchup_bot.config import settings
from glitchup_bot.services.alert_processor import process_webhook_payload
router = APIRouter(prefix="/webhooks", tags=["webhooks"])
logger = logging.getLogger(__name__)
@router.post("/glitchtip")
async def glitchtip_webhook(
request: Request,
x_webhook_secret: str | None = Header(None),
):
if settings.webhook_secret and x_webhook_secret != settings.webhook_secret:
raise HTTPException(status_code=403, detail="Invalid webhook secret")
payload = await request.json()
logger.info("Received GlitchTip webhook: %s", payload.get("text", "unknown"))
await process_webhook_payload(payload)
return {"status": "accepted"}