新增了完整的GitHub集成插件,包含认证、会话管理、Webhook处理、消息收发、反应支持等核心功能,支持Issues、Discussions、Pull Request的交互与通知。
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.github.auth import verify_credentials
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class GitHubStatusAdapter:
|
|
|
|
async def probe(self, account: dict) -> bool:
|
|
result = await verify_credentials(account)
|
|
return result is not None
|
|
|
|
def build_summary(self, snapshot: object) -> dict:
|
|
webhook_path = getattr(snapshot, "webhook_path", None) or "/api/webhook/github"
|
|
running = getattr(snapshot, "running", False)
|
|
return {
|
|
"channel": "github",
|
|
"webhook_path": webhook_path,
|
|
"webhook_registered": running,
|
|
}
|
|
|
|
def build_account_summary(self, account: dict, probe_result: dict | None = None) -> dict:
|
|
summary: dict = {
|
|
"account_id": account.get("account_id", ""),
|
|
"configured": all([
|
|
account.get("app_id"),
|
|
account.get("private_key"),
|
|
account.get("installation_id"),
|
|
account.get("webhook_secret"),
|
|
]),
|
|
"dm_policy": account.get("dm_policy", "open"),
|
|
"group_policy": account.get("group_policy", "open"),
|
|
"repositories": account.get("repositories", []),
|
|
}
|
|
if probe_result:
|
|
summary["rate_limit"] = probe_result.get("rate_limit", 5000)
|
|
summary["rate_remaining"] = probe_result.get("rate_remaining", 5000)
|
|
summary["online"] = True
|
|
return summary
|