把 GitHub 接入 OpenClaw,让 AI 帮你监控仓库活动—— 新 PR 自动摘要、Issues 智能分类、CI 失败立刻告警, 所有通知都到 Telegram,不用盯着邮件。
集成方式
OpenClaw 支持两种接入方式:
| 方式 | 特点 |
|---|---|
| GitHub App(推荐) | 细粒度权限,支持 Webhook 推送 |
| Personal Access Token | 配置简单,主动轮询 |
方式一:Personal Access Token(快速上手)
bash
# 1. 生成 Token:GitHub -> Settings -> Developer settings
# -> Personal access tokens (fine-grained)
# 权限:repo:read, pull_requests:read, issues:read
# 2. OpenClaw 配置json
{
"integrations": {
"github": {
"enabled": true,
"token": "github_pat_你的token",
"watchRepos": [
"your-org/frontend",
"your-org/backend",
"your-org/infra"
],
"pollIntervalMinutes": 5
}
}
}方式二:GitHub Webhook(实时推送)
bash
# 1. 仓库 Settings -> Webhooks -> Add webhook
# Payload URL: https://你的openclaw域名/webhook/github
# Content type: application/json
# Secret: 设置一个随机字符串
# 2. 选择事件:pull_request, issues, push, workflow_runjson
{
"integrations": {
"github": {
"enabled": true,
"webhookSecret": "你设置的secret",
"webhookPath": "/webhook/github"
}
}
}HEARTBEAT 仓库监控配置
markdown
# HEARTBEAT.md
## GitHub 监控规则
### PR 监控
每次心跳检查新的 PR 状态变化:
- 新 PR 创建:生成 AI 摘要(变更内容、影响范围)发 Telegram
- PR 被 approve:通知 + 询问是否合并
- PR CI 失败:立刻告警,附失败步骤
### Issues 监控
- 新 Issue(label: bug):立刻通知,分类优先级
- Issue 被分配给我:提醒我查看
- 超过 7 天无回复的 Issue:每周五汇总提醒
### CI/CD 告警
- workflow_run 失败:立刻发告警,包含:
- 哪个仓库哪个分支
- 失败的 step
- 触发人
- 链接具体工作流示例
自动 PR 摘要
新 PR 创建时,自动生成:
🔔 新 PR:[feat] 添加用户支付功能
仓库:company/backend | 作者:@developer | #342
📝 AI 摘要:
• 新增 PaymentService 处理 Stripe 付款流程
• 修改 User 模型,添加 paymentMethod 字段
• 3 个新 API 端点:/payment/init, /payment/confirm, /payment/refund
• 新增 12 个测试用例,覆盖率 87%
⚠️ 注意点:
• payment_secret 是否使用了环境变量?(需确认)
• 退款逻辑缺少幂等性检查
👉 https://github.com/company/backend/pull/342
CI 失败告警
🚨 CI 失败!
仓库:company/frontend
分支:feature/new-dashboard
触发:push by @developer at 14:32
❌ 失败步骤:Unit Tests
错误:TypeError: Cannot read property 'data' of undefined
at UserDashboard.test.tsx:45
📎 完整日志:https://github.com/...
每日仓库日报
bash
# 每天 18:00 发今日活动汇总
openclaw cron add --schedule "0 18 * * 1-5" --task "读取今天所有 watch 的 GitHub 仓库活动,生成日报:
- 合并的 PR(数量 + 摘要)
- 新建/关闭的 Issues
- Deploy 状态
发 Telegram"用 OpenClaw 触发 GitHub Actions
反向操作:通过对话触发 CI/CD:
你:帮我触发 production 部署
助手:确认触发 company/backend 的 production 部署工作流?
当前 main 分支最新 commit: abc1234 "fix: payment bug"
[确认] [取消]
你:确认
助手:✅ 已触发 production 部署
实时状态:https://github.com/...
我会在完成后通知你结果
配置示例(完整版)
json
{
"integrations": {
"github": {
"enabled": true,
"token": "github_pat_...",
"watchRepos": ["org/repo1", "org/repo2"],
"notify": {
"prCreated": true,
"prMerged": true,
"prCiFailure": true,
"issueCreated": {"labels": ["bug", "urgent"]},
"releasePublished": true,
"workflowFailed": true
},
"aiSummary": {
"pr": true,
"maxDiffLines": 500
}
}
}
}来源:OpenClaw 官方文档 | GitHub API 文档