ForcePilot/backend/package/yuxi/channel/extensions/gitlab/session.py
Kris 4a4e256955 feat(gitlab): 新增完整 GitLab 渠道插件支持
实现了 GitLab 全功能集成,包含 Webhook 处理、API 客户端、消息收发、会话管理、安全校验、限流器等完整模块,支持 Issues、Merge Requests、流水线等事件监听与交互。
2026-05-21 10:49:01 +08:00

45 lines
1.3 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
@dataclass
class GitLabSessionResolution:
project_id: int
project_path: str
noteable_type: str
noteable_iid: int
label: str
@property
def conversation_id(self) -> str:
return f"gitlab:{self.project_id}:{self.noteable_type}:{self.noteable_iid}"
def resolve_session_from_unified(msg) -> GitLabSessionResolution | None:
metadata = getattr(msg, "metadata", {}) or {}
project_id = int(metadata.get("project_id", 0))
project_path = str(metadata.get("project_path", ""))
noteable_type = str(metadata.get("noteable_type", "Issue"))
noteable_iid = int(metadata.get("noteable_iid", 0))
if project_id <= 0 or noteable_iid <= 0:
return None
return GitLabSessionResolution(
project_id=project_id,
project_path=project_path,
noteable_type=noteable_type,
noteable_iid=noteable_iid,
label=f"{project_path}#{noteable_iid}",
)
def build_session_label(project_path: str, noteable_type: str, noteable_iid: int, title: str = "") -> str:
symbol = "#" if noteable_type == "Issue" else "!"
base = f"{project_path}{symbol}{noteable_iid}"
if title:
return f"{base}{title}"
return base