feat: add webhook + webhook_log models
This commit is contained in:
@@ -248,6 +248,7 @@ def get_user(user_id: int, db: Session = Depends(get_db)):
|
|||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
def startup():
|
def startup():
|
||||||
from app.core.config import Base, engine
|
from app.core.config import Base, engine
|
||||||
|
from app.models import webhook
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
40
app/models/webhook.py
Normal file
40
app/models/webhook.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, Enum as SAEnum
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from app.core.config import Base
|
||||||
|
import enum
|
||||||
|
|
||||||
|
|
||||||
|
class WebhookEvent(str, enum.Enum):
|
||||||
|
ISSUE_CREATED = "issue.created"
|
||||||
|
ISSUE_UPDATED = "issue.updated"
|
||||||
|
ISSUE_CLOSED = "issue.closed"
|
||||||
|
ISSUE_DELETED = "issue.deleted"
|
||||||
|
COMMENT_CREATED = "comment.created"
|
||||||
|
RESOLUTION_CREATED = "resolution.created"
|
||||||
|
MEMBER_ADDED = "member.added"
|
||||||
|
MEMBER_REMOVED = "member.removed"
|
||||||
|
|
||||||
|
|
||||||
|
class Webhook(Base):
|
||||||
|
__tablename__ = "webhooks"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
url = Column(String(500), nullable=False)
|
||||||
|
secret = Column(String(255), nullable=True)
|
||||||
|
events = Column(Text, nullable=False) # comma-separated events
|
||||||
|
project_id = Column(Integer, nullable=True) # null = global
|
||||||
|
is_active = Column(Boolean, default=True)
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
|
||||||
|
|
||||||
|
class WebhookLog(Base):
|
||||||
|
__tablename__ = "webhook_logs"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
webhook_id = Column(Integer, nullable=False)
|
||||||
|
event = Column(String(50), nullable=False)
|
||||||
|
payload = Column(Text, nullable=False)
|
||||||
|
response_status = Column(Integer, nullable=True)
|
||||||
|
response_body = Column(Text, nullable=True)
|
||||||
|
success = Column(Boolean, default=False)
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
Reference in New Issue
Block a user