🐙 GitHub 自动化管理
💡 效果: 自动检查 CI 状态、创建 Issue、管理 PR、审查代码,解放开发者时间。
🎯 自动化场景
日常工作流
- 早晨检查: 查看夜间 CI 运行状态
- PR 审查: 自动审查新提交的 PR
- Issue 管理: 分类和分配新 Issue
- 代码审查: 初步代码质量检查
📋 前置准备
- OpenClaw 已安装
- 已安装技能:
github,code-review - GitHub Personal Access Token
🔧 配置步骤
步骤 1: 配置 GitHub 凭证
# 创建 GitHub Token
# 访问 https://github.com/settings/tokens
# 勾选权限:repo, workflow, read:org
# 配置 OpenClaw
openclaw config set github.token ghp_xxxxxxxxxxxx
步骤 2: 创建 CI 检查脚本
#!/bin/bash
# 检查指定仓库的 CI 状态
REPO="owner/repo"
# 获取最近的 CI 运行
ci_runs=$(openclaw run github \
--action list-runs \
--repo $REPO \
--status completed \
--limit 10)
# 检查失败的运行
failed_runs=$(echo "$ci_runs" | jq '.[] | select(.conclusion == "failure")')
if [ -n "$failed_runs" ]; then
# 发送通知
openclaw message --channel feishu \
--text "❌ CI 失败通知\n\n$failed_runs"
fi
步骤 3: PR 自动审查
#!/bin/bash
# 获取新 PR 列表
new_prs=$(openclaw run github \
--action list-prs \
--repo owner/repo \
--state open \
--sort created \
--direction desc)
# 对每个 PR 进行初步审查
echo "$new_prs" | jq -r '.[] | .number' | while read pr_number; do
openclaw run github \
--action review-pr \
--repo owner/repo \
--pr $pr_number \
--auto-comment
done
步骤 4: Issue 自动分类
#!/bin/bash
# 获取新 Issue
new_issues=$(openclaw run github \
--action list-issues \
--repo owner/repo \
--state open \
--filter "created:>24h")
# AI 分类并添加标签
echo "$new_issues" | jq -r '.[] | .number' | while read issue_number; do
openclaw run github \
--action auto-label \
--repo owner/repo \
--issue $issue_number \
--model claude-sonnet-4
done
📊 定时任务配置
# 编辑 crontab
crontab -e
# 每 30 分钟检查 CI 状态
*/30 * * * * /path/to/scripts/ci-check.sh
# 每天早上 9 点审查 PR
0 9 * * 1-5 /path/to/scripts/pr-review.sh
# 每小时分类 Issue
0 * * * * /path/to/scripts/issue-label.sh
💡 高级用法
自动化 Release Notes
# 生成 Release Notes
openclaw run github \
--action generate-release-notes \
--repo owner/repo \
--from v1.0.0 \
--to v1.1.0 \
--output release-notes.md
依赖更新检查
# 检查依赖更新
openclaw run github \
--action check-dependencies \
--repo owner/repo \
--create-pr true
📈 效果展示
📊 GitHub 日报 - 2026 年 3 月 9 日
📦 仓库:owner/repo
✅ CI 状态
- 成功:15 次
- 失败:2 次 (已通知)
🔀 Pull Requests
- 新增:3 个
- 合并:5 个
- 待审查:2 个
📋 Issues
- 新增:8 个
- 已关闭:12 个
- 待处理:15 个
🏷️ 自动标签
- bug: 2
- feature: 3
- question: 3
🐛 常见问题
Q: GitHub API 限流?
A: 使用 Personal Access Token 可提高限流(5000 次/小时),或降低检查频率。
Q: 如何跳过某些 PR?
A: 在脚本中添加过滤条件,如 --label "WIP" 跳过进行中的 PR。
Q: 审查评论太啰嗦?
A: 调整 AI 模型参数,设置 max_tokens 限制评论长度。