55347f962c
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 15s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 16s
AI Code Review / AI Code Review (pull_request) Failing after 23s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 49s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 1m55s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m52s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 3m17s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m31s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 3m56s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 20s
新增 scripts/ci/chatops/ 目录,Python实现,纯工具链扩展不动业务代码。 3个核心模块: - ci_query.py - 查询CI状态(分支/PR/失败详情) - ci_trigger.py - 触发重跑(rerun失败job/整个workflow/取消) - feishu_notify.py - CI事件飞书通知(失败/恢复/E2E摘要) 配套基础设施: - config.py - 配置化,所有token/webhook走环境变量 - gitea_client.py - Gitea API统一封装(urllib实现,无第三方依赖) - webhook_server.py - FastAPI webhook接收服务(可选依赖) 通知规则(最高频使用场景): - main/develop分支CI失败 → 飞书告警卡片(含失败摘要+一键重跑) - 分支从失败恢复 → 绿色恢复通知(含故障时长) - E2E测试失败 → 单独摘要通知 - 连续失败不重复告警(状态缓存去重) 飞书交互命令(第一版已实现解析+执行): - /ci status [branch] - 查询分支CI状态 - /ci rerun <run-id> - 重跑失败jobs - /ci rerun latest [branch] - 重跑最近一次失败的run - /ci help - 帮助 black+ruff全绿,与现有ci脚本风格一致。
56 lines
2.7 KiB
Python
Executable File
56 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
ChatOps 配置管理 - 统一从环境变量读取配置,不硬编码任何敏感信息
|
|
|
|
环境变量:
|
|
GITEA_URL Gitea 地址 (默认 https://git.xiaoxiajianji.com)
|
|
GITEA_REPO 仓库路径 (默认 xiaoxia/xiaoxia-saas)
|
|
GITEA_TOKEN Gitea API Token (优先使用)
|
|
GITEA_USERNAME Gitea 用户名 (密码认证时)
|
|
GITEA_PASSWORD Gitea 密码 (密码认证时)
|
|
FEISHU_WEBHOOK_URL 飞书自定义机器人 webhook 地址
|
|
FEISHU_APP_ID 飞书应用 App ID (应用机器人模式,预留)
|
|
FEISHU_APP_SECRET 飞书应用 App Secret (应用机器人模式,预留)
|
|
CHATOPS_NOTIFY_BRANCHES 触发通知的分支,逗号分隔 (默认 main,develop)
|
|
CHATOPS_WEBHOOK_PORT webhook 服务监听端口 (默认 8090)
|
|
CHATOPS_WEBHOOK_SECRET Gitea webhook 密钥 (校验签名,可选)
|
|
"""
|
|
|
|
import os
|
|
|
|
# ── Gitea 配置 ────────────────────────────────────────
|
|
GITEA_URL = os.environ.get("GITEA_URL", "https://git.xiaoxiajianji.com").rstrip("/")
|
|
GITEA_REPO = os.environ.get("GITEA_REPO", "xiaoxia/xiaoxia-saas")
|
|
GITEA_TOKEN = os.environ.get("GITEA_TOKEN", "")
|
|
GITEA_USERNAME = os.environ.get("GITEA_USERNAME", "")
|
|
GITEA_PASSWORD = os.environ.get("GITEA_PASSWORD", "")
|
|
|
|
# ── 飞书配置 ──────────────────────────────────────────
|
|
FEISHU_WEBHOOK_URL = os.environ.get("FEISHU_WEBHOOK_URL", "")
|
|
FEISHU_APP_ID = os.environ.get("FEISHU_APP_ID", "")
|
|
FEISHU_APP_SECRET = os.environ.get("FEISHU_APP_SECRET", "")
|
|
|
|
# ── 通知配置 ──────────────────────────────────────────
|
|
NOTIFY_BRANCHES = [b.strip() for b in os.environ.get("CHATOPS_NOTIFY_BRANCHES", "main,develop").split(",") if b.strip()]
|
|
|
|
# ── Webhook 服务配置 ──────────────────────────────────
|
|
WEBHOOK_PORT = int(os.environ.get("CHATOPS_WEBHOOK_PORT", "8090"))
|
|
WEBHOOK_SECRET = os.environ.get("CHATOPS_WEBHOOK_SECRET", "")
|
|
|
|
# ── 常量 ──────────────────────────────────────────────
|
|
PAGE_LIMIT = 50 # Gitea API 每页最大数量
|
|
|
|
|
|
def has_gitea_auth() -> bool:
|
|
"""检查是否配置了 Gitea 认证信息"""
|
|
if GITEA_TOKEN:
|
|
return True
|
|
if GITEA_USERNAME and GITEA_PASSWORD:
|
|
return True
|
|
return False
|
|
|
|
|
|
def has_feishu_webhook() -> bool:
|
|
"""检查是否配置了飞书 webhook"""
|
|
return bool(FEISHU_WEBHOOK_URL)
|