新增了完整的GitHub集成插件,包含认证、会话管理、Webhook处理、消息收发、反应支持等核心功能,支持Issues、Discussions、Pull Request的交互与通知。
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.channel.protocols import SessionResolution
|
|
|
|
|
|
class GitHubSessionAdapter:
|
|
|
|
def resolve_session(self, msg: object) -> SessionResolution:
|
|
group = getattr(msg, "group", None)
|
|
if not group or not hasattr(group, "id"):
|
|
sender = getattr(msg, "sender", None)
|
|
if sender and hasattr(sender, "id"):
|
|
return SessionResolution(kind="direct", conversation_id=f"github:dm:{sender.id}")
|
|
return SessionResolution(kind="direct", conversation_id="github:unknown")
|
|
|
|
return SessionResolution(
|
|
kind="group",
|
|
conversation_id=group.id,
|
|
label=getattr(group, "name", ""),
|
|
)
|
|
|
|
@staticmethod
|
|
def build_session_key(repo_full_name: str, kind: str, number: int) -> str:
|
|
return f"github:{repo_full_name}:{kind}:{number}"
|
|
|
|
@staticmethod
|
|
def parse_session_key(session_key: str) -> tuple[str, str, int] | None:
|
|
parts = session_key.split(":")
|
|
if len(parts) < 5 or parts[0] != "github":
|
|
return None
|
|
return parts[1], parts[3], int(parts[4])
|