diff --git a/app/main.py b/app/main.py index ead4bf1..369c577 100644 --- a/app/main.py +++ b/app/main.py @@ -248,6 +248,7 @@ def get_user(user_id: int, db: Session = Depends(get_db)): @app.on_event("startup") def startup(): from app.core.config import Base, engine + from app.models import webhook Base.metadata.create_all(bind=engine) diff --git a/app/models/webhook.py b/app/models/webhook.py new file mode 100644 index 0000000..57785a1 --- /dev/null +++ b/app/models/webhook.py @@ -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())