首页/探索/GitHub API Plugin

Asset Detail

插件v1.0.0

GitHub API Plugin

NZSZ🎖️47740 次下载

安装命令
openclawmp install plugin/@u-a553402ca21449db9813/github-api

标签

README

GitHub API Plugin

为 OpenClaw Agent 提供 GitHub REST API 集成能力。


功能

  • 🔍 搜索仓库(searchRepos
  • 📋 查询 Issues(getIssues
  • ➕ 创建 Issue(createIssue
  • 🔀 查询 Pull Requests(getPullRequests
  • ✅ 合并 PR(mergePullRequest
  • 📜 获取提交记录(getCommits

安装

# 1. 生成 GitHub Personal Access Token
# 去 https://github.com/settings/tokens 生成,勾选 repo 权限

# 2. 设置环境变量
export GITHUB_TOKEN=ghp_your_token_here

# 3. 安装插件
openclawmp install plugin/@your-username/github-api

配置 Agent

{
  "plugins": [
    {
      "id": "github-api",
      "config": {
        "token": "${GITHUB_TOKEN}",
        "apiUrl": "https://api.github.com"
      }
    }
  ]
}

工具列表

1. searchRepos(query, sort='stars', order='desc', perPage=30)

搜索 GitHub 仓库。

参数:

  • query (string): 搜索关键词,如 "openclaw language:typescript"
  • sort (string): 排序方式:starsforksupdated
  • order (string): 顺序:descasc
  • perPage (number): 每页数量(1-100)

返回:

{
  "total_count": 1234,
  "items": [
    {
      "full_name": "owner/repo",
      "description": "...",
      "stars": 1000,
      "language": "TypeScript",
      "url": "https://github.com/owner/repo"
    }
  ]
}

示例:

调用: searchRepos("openclaw agent", "stars", "desc", 5)

2. getIssues(owner, repo, state='open', labels=[], perPage=30)

获取仓库的 Issues 列表。

参数:

  • owner (string): 仓库所有者
  • repo (string): 仓库名
  • state (string): openclosedall
  • labels (string[]): 标签过滤
  • perPage (number): 每页数量

返回:

[
  {
    "number": 123,
    "title": "Bug: something broken",
    "state": "open",
    "user": { "login": "author" },
    "created_at": "2025-03-01T10:00:00Z",
    "html_url": "https://github.com/owner/repo/issues/123"
  }
]

3. createIssue(owner, repo, title, body='', labels=[])

创建新 Issue。

参数:

  • owner (string)
  • repo (string)
  • title (string)
  • body (string): 内容(Markdown)
  • labels (string[]): 标签列表

返回:

{
  "number": 456,
  "html_url": "https://github.com/owner/repo/issues/456",
  "title": "..."
}

4. getPullRequests(owner, repo, state='open', head='', base='', perPage=30)

获取 Pull Requests。

参数:

  • owner (string)
  • repo (string)
  • state (string): openclosedall
  • head (string): 头分支(如 "user:branch"
  • base (string): 基础分支(如 "main"
  • perPage (number)

返回: PR 对象数组(含 numbertitleuserstatehtml_url


5. mergePullRequest(owner, repo, pullNumber, mergeMethod='merge')

合并 PR。

参数:

  • owner (string)
  • repo (string)
  • pullNumber (number)
  • mergeMethod (string): merge(合并提交)、squash(压缩)、rebase(变基)

返回:

{
  "sha": "abc123...",
  "merged": true,
  "message": "Pull Request successfully merged"
}

6. getCommits(owner, repo, ref='main', perPage=30)

获取提交记录。

参数:

  • owner (string)
  • repo (string)
  • ref (string): 分支名或 commit SHA
  • perPage (number)

返回:

[
  {
    "sha": "abc123...",
    "commit": {
      "author": { "name": "Alice", "date": "..." },
      "message": "Fix bug"
    },
    "author": { "login": "alice" },
    "html_url": "https://github.com/owner/repo/commit/abc123"
  }
]

使用示例

场景 1:搜索热门的 OpenClaw 插件

使用 github-api 插件: 搜索 stars > 100 的 TypeScript 写的 OpenClaw 插件 call searchRepos("openclaw plugin language:typescript stars:>100", "stars", "desc", 10)

场景 2:自动回复 Issue

读取最新 Issue call getIssues("myorg/myrepo", "open", [], 5) 如果 Issue 标题包含 "bug",自动回复: call createIssue("myorg/myrepo", "Acknowledged: {{title}}", "We'll look into this.", ["acknowledged"])

场景 3:每周自动合并 PR

获取所有 PR call getPullRequests("myorg/myrepo", "open", base="main") 全部合并(谨慎使用) for pr in prs: mergePullRequest(owner, repo, pr.number, "squash")

错误处理

常见错误码:

  • 401: Token 无效或过期
  • 403: 权限不足(检查 scopes)
  • 404: 仓库/Issue 不存在
  • 422: 参数错误(如合并冲突)

插件会抛出异常,Agent 可捕获并重试或通知用户。


安全建议

  • 🔐 Token 存储为环境变量,不要硬编码
  • 🔐 使用最小权限 token(如仅 public_repo
  • 🧹 定期清理旧 token

License

MIT © 2026

相关推荐