Files
OpenHands/enterprise/storage/gitlab_webhook.py
chuckbutkus d5e66b4f3a SAAS: Introducing orgs (phase 1) (#11265)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: rohitvinodmalhotra@gmail.com <rohitvinodmalhotra@gmail.com>
Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com>
Co-authored-by: Tim O'Farrell <tofarr@gmail.com>
2026-01-15 22:03:31 -05:00

52 lines
1.6 KiB
Python

import sys
from enum import IntEnum
from sqlalchemy import (
ARRAY,
Boolean,
Column,
DateTime,
Integer,
String,
Text,
text,
)
from storage.base import Base
class WebhookStatus(IntEnum):
PENDING = 0 # Conditions for installation webhook need checking
VERIFIED = 1 # Conditions are met for installing webhook
RATE_LIMITED = 2 # API was rate limited, failed to check
INVALID = 3 # Unexpected error occur when checking (keycloak connection, etc)
class GitlabWebhook(Base): # type: ignore
"""
Represents a Gitlab webhook configuration for a repository or group.
"""
__tablename__ = 'gitlab_webhook'
id = Column(Integer, primary_key=True, autoincrement=True)
group_id = Column(String, nullable=True)
project_id = Column(String, nullable=True)
user_id = Column(String, nullable=False)
webhook_exists = Column(Boolean, nullable=False)
webhook_url = Column(String, nullable=True)
webhook_secret = Column(String, nullable=True)
webhook_uuid = Column(String, nullable=True)
# Use Text for tests (SQLite compatibility) and ARRAY for production (PostgreSQL)
scopes = Column(Text if 'pytest' in sys.modules else ARRAY(Text), nullable=True)
last_synced = Column(
DateTime,
server_default=text('CURRENT_TIMESTAMP'),
onupdate=text('CURRENT_TIMESTAMP'),
nullable=True,
)
def __repr__(self) -> str:
return (
f'<GitlabWebhook(id={self.id}, group_id={self.group_id}, '
f'project_id={self.project_id}, last_synced={self.last_synced})>'
)