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

43 lines
1008 B
Python

from __future__ import annotations
import re
GLFM_CHUNK_LIMIT = 65000
_FENCED_BLOCK_RE = re.compile(r"^```")
def sanitize_glfm(text: str) -> str:
return text.replace("\x00", "")
def chunk_glfm_markdown(text: str, limit: int = GLFM_CHUNK_LIMIT) -> list[str]:
if len(text) <= limit:
return [text]
chunks: list[str] = []
in_fenced_block = False
current = ""
for line in text.split("\n"):
if _FENCED_BLOCK_RE.match(line):
in_fenced_block = not in_fenced_block
candidate = current + line + "\n"
if len(candidate) > limit and not in_fenced_block:
chunks.append(current.rstrip())
current = line + "\n"
else:
current = candidate
if current.strip():
chunks.append(current.rstrip())
return chunks if chunks else [text]
def safe_glfm_body(text: str, max_length: int = 950000) -> str:
if len(text) > max_length:
return text[: max_length - 3] + "..."
return text