GitHub 操作技能:仓库管理、Pull Request、Actions、Issue 和文件操作。
让开发者能够通过自然语言与 GitHub API 交互,快速完成日常开发任务。
在 ~/.openclaw/workspace/.env 中配置:
# 必填
GITHUB_TOKEN=your-github-personal-access-token
GITHUB_OWNER=koderover # 组织名或用户名- 打开 https://github.com/settings/tokens
- 点击 "Generate new token (classic)"
- 填写 Note(如 "OpenClaw")
- 勾选权限:
repo- 完整仓库访问workflow- Actions 权限read:org- 读取组织
- 点击 "Generate token"
- 复制并配置到
.env
| 模块 | 功能 |
|---|---|
| 仓库 | 列出、创建、管理仓库 |
| Pull Request | 创建、审查、合并 PR |
| Issue | 创建、标签、分配 Issue |
| Actions | 触发、监控工作流 |
| 文件 | 读取、更新仓库文件 |
# ~/.openclaw/workspace/.env
GITHUB_TOKEN=ghp_xxxxxxxxxxxx
GITHUB_OWNER=your-org# 列出仓库
gh repo list
# 创建 PR
gh pr create --title "Feature: 新功能" --body "描述"
# 触发 Actions
gh run list当分支开发完成后自动创建 PR:
# 创建 PR 并获取链接
PR_URL=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
-d '{"title":"Feature: 新功能","body":"实现 xxx 功能","head":"feature-xxx","base":"main"}' \
"https://api.github.com/repos/$GITHUB_OWNER/REPO/pulls" | \
jq -r '.html_url')
echo "PR created: $PR_URL"触发部署流水线并等待结果:
# 触发 Workflow
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
-d '{"ref":"main"}' \
"https://api.github.com/repos/$GITHUB_OWNER/REPO/actions/workflows/deploy.yml/dispatches"
# 等待完成
RUN_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_OWNER/REPO/actions/runs?status=in_progress" | \
jq -r '.workflow_runs[0].id')
while true; do
STATUS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_OWNER/REPO/actions/runs/$RUN_ID" | \
jq -r '.conclusion')
[[ "$STATUS" == "success" || "$STATUS" == "failure" ]] && break
sleep 15
done
echo "Run $STATUS"批量修改多个仓库的配置文件:
REPOS=("repo1" "repo2" "repo3")
for REPO in "${REPOS[@]}"; do
SHA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_OWNER/$REPO/contents/ci.yml" | \
jq -r '.sha')
curl -s -X PUT -H "Authorization: token $GITHUB_TOKEN" \
-d '{"message":"Update CI","content":"'$(base64 -w0 ci.yml)'","sha":"'$SHA'","branch":"main"}' \
"https://api.github.com/repos/$GITHUB_OWNER/$REPO/contents/ci.yml"
done# 安装
brew install gh
# 登录
gh auth login
# 仓库操作
gh repo list
gh repo create new-repo --public
# PR 操作
gh pr list
gh pr create --title "Feature" --body "描述"
gh pr merge --admin --squash
# Issue 操作
gh issue list
gh issue create --title "Bug" --body "描述"
# Actions 操作
gh run list
gh run view RUN_ID- SKILL.md - Agent 使用说明(含完整 API 示例)
- GitHub REST API 文档
- GitHub Actions 文档