GitHub API 工具

👤 gaoren36-arch 📦 v1.0.0 ⭐ 4.1 ⬇️ 1.3K 下載
💻 開發程式設計 免費 🔑 需 API Key

📖 技能介紹


name: github description: GitHub 操作工具 - 通過 GitHub API 管理倉庫、Issues、PRs、Actions 等 triggers: - github - GitHub - github issue - github pr - github repo

小蔥技能7w4.net有完整的技能分類。


GitHub 操作工具

通過 GitHub REST API 管理倉庫、Issues、PRs、Actions 等。

認證

需要設定 GitHub Token 環境變數:

# 在 openclaw 配置中設定
GITHUB_TOKEN=your_github_personal_access_token

Token 許可權要求: - repo - 完整倉庫操作 - read:user - 讀取使用者資訊 - workflow - GitHub Actions 操作

核心功能

功能 說明
倉庫資訊 獲取倉庫詳情、統計資訊
Issues 列表、檢視、建立、關閉、編輯
PR 列表、檢視、建立、合併、審查
Commits 檢視提交歷史
Actions 檢視 workflow、執行狀態
搜尋 搜尋倉庫、程式碼
檔案操作 讀取檔案內容
使用者資訊 獲取使用者資料

使用方式

1. 設定 Token

~/.openclaw/openclaw.json 中配置:

{
  "env": {
    "GITHUB_TOKEN": "ghp_xxxxxxxxxxxx"
  }
}

2. 倉庫操作

# 獲取倉庫資訊
github_get_repo owner=octocat repo=hello-world

# 獲取倉庫統計資料
github_get_repo_stats owner=octocat repo=hello-world

# 列出使用者倉庫
github_list_repos user=octocat type=all sort=updated

3. Issues 操作

# 列出倉庫 issues
github_list_issues owner=octocat repo=hello-world state=open

# 檢視單個 issue
github_get_issue owner=octocat repo=hello-world issue_number=1

# 建立 issue
github_create_issue owner=octocat repo=hello-world title="Bug: 登入失敗" body="復現步驟..."

# 關閉 issue
github_close_issue owner=octocat repo=hello-world issue_number=1

# 編輯 issue
github_edit_issue owner=octocat repo=hello-world issue_number=1 title="新標題"

4. Pull Request 操作

# 列出 PRs
github_list_pulls owner=octocat repo=hello-world state=open

# 檢視 PR
github_get_pull owner=octocat repo=hello-world pull_number=1

# 建立 PR
github_create_pull title="feat: 新功能" body="描述..." head=feature-branch base=main owner=octocat repo=hello-world

# 合併 PR
github_merge_pull owner=octocat repo=hello-world pull_number=1 merge_method=squash

# 檢視 PR 檔案變更
github_list_pull_files owner=octocat repo=hello-world pull_number=1

5. Commits 操作

# 獲取提交歷史
github_list_commits owner=octocat repo=hello-world per_page=10

# 檢視單個提交
github_get_commit owner=octocat repo=hello-world ref=abc123

6. GitHub Actions

# 列出 workflows
github_list_workflows owner=octocat repo=hello-world

# 檢視 workflow runs
github_list_workflow_runs owner=octocat repo=hello-world workflow_id=build

# 觸發 workflow
github_dispatch_workflow owner=octocat repo=hello-world workflow_id=build ref=main

7. 搜尋

# 搜尋倉庫
github_search_repos query="tetris language:javascript" sort=stars order=desc

# 搜尋程式碼
github_search_code q="octocat filename:package.json"

# 搜尋 issues
github_search_issues q="bug state:open repo:octocat/Hello-World"

8. 檔案操作

# 獲取檔案內容
github_get_file owner=octocat repo=hello-world path=README.md

# 獲取檔案元資訊(含 SHA)
github_get_file owner=octocat repo=hello-world path=README.md ref=main

9. 使用者資訊

# 獲取當前使用者
github_get_user

# 獲取其他使用者
github_get_user username=octocat

API 呼叫方式

使用 exec 工具呼叫 GitHub API:

# 格式
curl -H "Authorization: token $GITHUB_TOKEN" \
     -H "Accept: application/vnd.github.v3+json" \
     https://api.github.com/{endpoint}

# 示例:獲取倉庫資訊
curl -H "Authorization: token $GITHUB_TOKEN" \
     -H "Accept: application/vnd.github.v3+json" \
     https://api.github.com/repos/octocat/hello-world

常用 API 端點

端點 說明
/repos/{owner}/{repo} 倉庫資訊
/repos/{owner}/{repo}/issues Issues 列表
/repos/{owner}/{repo}/pulls PRs 列表
/repos/{owner}/{repo}/commits 提交歷史
/repos/{owner}/{repo}/actions/workflows Actions
/search/repositories 搜尋倉庫
/search/code 搜尋程式碼
/user 當前使用者

常見工作流

建立一個 Issue 並標記

1. github_create_issue 建立 issue
2. github_add_labels 新增標籤
3. github_assign 新增負責人

審查 PR

1. github_get_pull 獲取 PR 資訊
2. github_list_pull_files 檢視檔案變更
3. github_create_review 建立審查意見

觸發 CI/CD

1. github_list_workflows 檢視可用 workflows
2. github_dispatch_workflow 觸發指定 workflow

注意事項

  1. Rate Limits:未認證請求 60次/小時,認證後 5000次/小時
  2. Token 安全:不要把 token 暴露在程式碼中
  3. Pagination:大量資料需要分頁處理
  4. API Version:使用 application/vnd.github.v3+json Accept header

錯誤處理

常見錯誤:

狀態碼 說明
401 Token 無效或過期
403 許可權不足或 rate limit
404 資源不存在
422 驗證失敗

快速命令模板

# 檢視倉庫
curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/{owner}/{repo}

# 列出 open issues
curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/{owner}/{repo}/issues?state=open"

# 建立 issue
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"title":"標題","body":"內容"}' \
     https://api.github.com/repos/{owner}/{repo}/issues

🤖 AI 評測

這個 Skill 文件質量不錯,功能覆蓋範圍廣,GitHub 操作的各類場景都有涉及,說明也很詳細。但它更像一份使用手冊,而不是可以直接用的工具,因為它只告訴你怎麼用,並沒有提供實際能執行的程式碼。如果你想要一個能直接操作的 GitHub 助手,目前這個版本還不夠完善。

📊 多維度評分

適應性4.3
規範性4
有效性4.4
可靠性3.5
可信度4.5

📁 包含檔案 (2 個)

📄 SKILL.md 5.6 KB
📄 _meta.json 134 B