从入门到精通

GitHub 集成

与 GitCode 对称:OAuth App + Bot PAT + 独立 webhook 路径。

前置

需要什么 为什么 怎么确认
一个能建 GitHub OAuth App 与 PAT 的账号 OAuth 与 Bot PAT 是两套凭据 GitHub Developer settings
知道平台对外域名 redirect_uri 需与 GitHub 上登记的一致 server_base_url
能改 configs/ 并重启服务 渠道卡随仓库发布;凭据在登录渠道页配置(加密入库) 重启后管理面能看到该渠道

与 GitCode 集成 完全对称,只是凭据换成 GitHub OAuth App + Bot PAT,webhook 走独立路径。

接入步骤

步骤 做什么 完成标志
第 1 步 在 GitHub Settings → Developer settings 创建 OAuth App 拿到 client_id / client_secret
第 2 步 在 Admin → 登录渠道填写 GitHub 凭据 登录页出现 GitHub 入口
第 3 步 在 Admin → 代码托管平台配置 Bot PAT Issue 评论显示 Bot 身份
第 4 步 托管仓库并确认 Webhook 仓库显示已托管,Webhook 返回 200
第 5 步 创建 Issue / 评论,确认事件进入 Grape 事件页出现记录,流水线可启动

GitHub OAuth Apps 入口:没有应用时注册新应用

第 1 步:创建 GitHub OAuth App

在 GitHub Settings → Developer settings → OAuth Apps → New OAuth App 创建应用,Authorization callback URL 填:

https://<你的域名>/api/auth/callback/github

scope 使用渠道卡默认的 read:user user:email repo。记下 client_id 与 client_secret。

第 2 步:配置登录渠道

在 Admin → 登录渠道 填写 GitHub 的 client_id / client_secret,保存后加密入库。生产环境 redirect_uri 必须显式配置,并与 GitHub 登记地址完全一致。

第 3 步:配置 Bot Token

在 Admin → 代码托管平台 → GitHub 卡 配置 Bot PAT(classic,勾选 repo 权限)和 github_bot_username。Bot 用于创建/关闭/评论 Issue,不用登录令牌写仓库。

第 4 步:托管仓库并确认 Webhook

托管仓库时 Grape 会自动创建 Webhook;手工新增时在 Settings → Webhooks → Add webhook 填:

https://<你的域名>/webhook/github

Content type 选 application/json,Secret 使用该仓库的 webhook_secret。GitHub 用 X-Hub-Signature-256 做 HMAC-SHA256 校验。

第 5 步:验证事件与写操作

在托管仓库创建或评论一条 Issue:GitHub webhook 的 Recent deliveries 应出现 200,Grape 事件页出现对应事件,Agent 评论作者为 Bot 账号。

OAuth App(用户登录)

在哪配:github 渠道卡在 configs/oauth-providers.json(随仓库发布,不需要复制 example);client_id / client_secret 在 Admin → 登录渠道 填,加密存 grape_t_oauth_channels,写文件会被剥离;生产环境 redirect_uri 必须显式配置。

  • 在 GitHub Settings → Developer settings → OAuth Apps 创建应用,Authorization callback URL 填 https://<你的域名>/api/auth/callback/github(与 redirect_uri 完全一致)。
  • scope 用渠道卡默认值 read:user user:email repo(用户信息 + 仓库范围)。登录令牌不再用于仓库写操作——仓库读写一律用仓库 bot PAT,因此不需要 admin:repo_hook 或 offline_access。

如何验证:Grape 登录页出现 GitHub 入口 → 点击 → GitHub 授权后回跳并登录成功。

Bot Token 与用户名(写操作)

在哪配:configs/global-bot-token.json 只作启动迁移种子(迁移读一次);之后在 Admin → 代码托管平台 → GitHub 卡 的 Bot 凭据里配置(只写不读,留空=不修改)。

配置示例:

{
  "github_bot_token": "<your-github-bot-pat>",
  "github_bot_username": "<your-bot-username>"
}
  • github_bot_token:GitHub Bot 账号的 PAT(classic,勾选 repo 权限),用于创建/关闭/评论 Issue 等写操作。
  • github_bot_username:Bot 账号用户名(协作者管理等场景使用)。

如何验证:托管一个 GitHub 仓库并触发一次 Issue 处理——Agent 的评论出现在 GitHub 且作者为 Bot 账号,即 Token 有效。

Webhook(事件接入)

在哪配:GitHub 仓库 Settings → Webhooks → Add webhook;Grape 侧接收路径固定为 POST /webhook/github。

配置示例:

  • Payload URL:https://<your-grape-domain>/webhook/github
  • Content type:application/json
  • Secret:填该仓库的 webhook_secret(托管 GitHub 仓库时 Grape 自动建 hook 并写入;手工建 hook 需从仓库配置复制,内部接口 /internal/repos/{repo_key}/webhook-config 可查)。Grape 用 X-Hub-Signature-256 对该仓库密钥做 HMAC-SHA256 校验,不一致直接 403;不存在全局共用密钥。

如何验证:GitHub webhook 详情页显示绿色 ✓(Recent deliveries 有 200 记录)→ 在该仓库创建一条 Issue → Grape「事件」页出现对应事件,即接入成功。

注意

GitHub PAT 与 webhook Secret 均为敏感值:文档与配置示例中一律使用 <placeholder> 占位,真实值只存放在仓库凭据(DB 加密列)与 Admin 代码托管平台卡。

怎么算成功

做这一步 应该看到 依据
登录页 出现 GitHub 入口 登录页按钮
webhook 走独立路径 GitHub 事件能进事件流,且不影响 GitCode 通道 事件列表来源字段