Skip to content

Commit c460f4f

Browse files
committed
refactored sentry app
1 parent 8d9a674 commit c460f4f

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

src/__init__.py

Whitespace-only changes.

src/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import os
2+
from distutils.util import strtobool
13
from functools import lru_cache
24

35
from pydantic import BaseSettings
46

57

68
class Settings(BaseSettings):
9+
DEBUG: bool = bool(strtobool(os.getenv('DEBUG', 'False')))
10+
711
BASECAMP_ACCOUNT_ID: str = 'bc-acc-id'
812
BASECAMP_CHATBOT_KEY: str = 'bc-bot-key'
913

1014
class Config:
11-
env_file = '.env'
15+
env_file = 'src/.env'
1216

1317

1418
@lru_cache()

src/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fastapi import FastAPI
2+
3+
from config import get_settings
4+
from sentry.api import api_router
5+
6+
7+
settings = get_settings()
8+
9+
app = FastAPI(
10+
debug=settings.DEBUG,
11+
)
12+
13+
app.include_router(api_router)

src/sentry/__init__.py

Whitespace-only changes.

src/sentry/main.py renamed to src/sentry/api.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
from typing import Any, Mapping
21
from fastapi.requests import Request
32
from fastapi.responses import Response
4-
from uuid import UUID
53

6-
from fastapi import FastAPI
74
from fastapi import status
8-
from pydantic.config import Extra
9-
from pydantic.main import BaseModel
5+
from fastapi import APIRouter
106

11-
app = FastAPI()
7+
from sentry.types import Webhook
128

139

14-
class Installation(BaseModel):
15-
uuid: UUID
10+
api_router = APIRouter()
1611

1712

18-
class Webhook(BaseModel, extra=Extra.allow):
19-
action: str
20-
data: Mapping[str, Any]
21-
installation: Installation
22-
23-
24-
@app.post("/api/sentry/webhook", status_code=status.HTTP_200_OK)
13+
@api_router.post("/api/sentry/webhook", status_code=status.HTTP_200_OK)
2514
async def sentry_webhook(webhook: Webhook, request: Request):
2615
if request.headers.get('sentry-hook-resource') == 'issue':
2716

src/sentry/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from fastapi.testclient import TestClient
3-
from sentry.main import app
3+
from main import app
44
from sentry.tests.request_data import event, issue
55

66

src/sentry/types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Any, Mapping
2+
from uuid import UUID
3+
4+
from pydantic import BaseModel
5+
from pydantic.config import Extra
6+
7+
8+
class Installation(BaseModel):
9+
uuid: UUID
10+
11+
12+
class Webhook(BaseModel, extra=Extra.allow):
13+
action: str
14+
data: Mapping[str, Any]
15+
installation: Installation

0 commit comments

Comments
 (0)