@zhin.js/adapter-github 0.1.58 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -44
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -44,9 +44,7 @@ pnpm add @zhin.js/adapter-github
|
|
|
44
44
|
- Issue comment、Pull request、Pull request review、Pull request review comment
|
|
45
45
|
- Push、Star、Fork(用于通知)
|
|
46
46
|
6. 创建后记录 **App ID**,点击 **Generate a private key** 下载 `.pem` 文件
|
|
47
|
-
7.
|
|
48
|
-
8. 在 App 设置页配置 **Callback URL**: `https://your-domain/pub/github/oauth/callback`
|
|
49
|
-
9. 安装 App 到目标仓库/组织
|
|
47
|
+
7. 安装 App 到目标仓库/组织
|
|
50
48
|
|
|
51
49
|
## 配置
|
|
52
50
|
|
|
@@ -57,25 +55,21 @@ bots:
|
|
|
57
55
|
name: my-github-bot
|
|
58
56
|
app_id: 123456
|
|
59
57
|
private_key: ./data/github-app.pem # PEM 文件路径或直接粘贴内容
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# client_id: Iv1.xxxxxxxxxx # 可选,OAuth 用户绑定
|
|
63
|
-
# client_secret: xxxxxxxxxxxx # 可选,配合 client_id 使用
|
|
64
|
-
# public_url: https://bot.example.com # 可选,OAuth 回调和绑定链接的公开地址
|
|
58
|
+
webhook_secret: your-secret # 可选;配置后启用 Webhook
|
|
59
|
+
webhook_path: /pub/github/webhook # 可选;默认 /github/webhook,/pub/* 可绕过 Bearer
|
|
65
60
|
|
|
66
61
|
plugins:
|
|
62
|
+
- database
|
|
67
63
|
- "@zhin.js/adapter-github"
|
|
68
|
-
- "@zhin.js/host-router"
|
|
64
|
+
- "@zhin.js/host-router" # Webhook 需要
|
|
69
65
|
```
|
|
70
66
|
|
|
71
|
-
`.env` 文件:
|
|
72
67
|
```env
|
|
73
68
|
GITHUB_APP_ID=123456
|
|
74
69
|
GITHUB_WEBHOOK_SECRET=your-secret
|
|
75
|
-
GITHUB_CLIENT_ID=Iv1.xxxxxxxxxx
|
|
76
|
-
GITHUB_CLIENT_SECRET=xxxxxxxxxxxx
|
|
77
70
|
# MCP server-github(适配器自动 addMcp,与 App 认证独立)
|
|
78
71
|
GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxx
|
|
72
|
+
# 或 ai.githubMcp.token / ai.mcpServers
|
|
79
73
|
```
|
|
80
74
|
|
|
81
75
|
或在 `zhin.config.yml` 中设置 `ai.githubMcp.token`(优先于环境变量)。
|
|
@@ -150,9 +144,9 @@ Headers:
|
|
|
150
144
|
- `X-GitHub-Event`: 事件类型
|
|
151
145
|
- `X-Hub-Signature-256`: 签名(配置了 secret 时)
|
|
152
146
|
|
|
153
|
-
## OAuth
|
|
147
|
+
## OAuth 用户绑定(Device Flow)
|
|
154
148
|
|
|
155
|
-
|
|
149
|
+
用户通过工具 **`github_bind`** 绑定 GitHub 账号([OAuth Device Flow](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow)),**不是**浏览器 OAuth 回调页面。
|
|
156
150
|
|
|
157
151
|
### 认证策略
|
|
158
152
|
|
|
@@ -162,31 +156,20 @@ Headers:
|
|
|
162
156
|
| 评论(bot 发言) | App JWT | 以机器人身份发言 |
|
|
163
157
|
| star / unstar | User OAuth | 个人行为 |
|
|
164
158
|
| fork | User OAuth | 个人行为 |
|
|
165
|
-
| 创建 issue / PR | 视场景选择 | 已绑定用用户 token,未绑定用 App |
|
|
166
159
|
|
|
167
160
|
### 绑定流程
|
|
168
161
|
|
|
169
|
-
1.
|
|
170
|
-
2. Bot
|
|
171
|
-
3.
|
|
172
|
-
4.
|
|
173
|
-
5. 服务端交换 code → access_token,获取用户信息,存入数据库
|
|
174
|
-
6. 用户看到"绑定成功"页面
|
|
162
|
+
1. 用户在聊天中触发 `github_bind`(或说「绑定 GitHub」)
|
|
163
|
+
2. Bot 返回 **verification URI** 与 **user code**(GitHub Device Flow)
|
|
164
|
+
3. 用户在浏览器打开链接并输入 code 完成授权
|
|
165
|
+
4. Token 写入 `github_oauth_users` 表;可用 `github_whoami` / `github_unbind` 管理
|
|
175
166
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
| 路由 | 说明 |
|
|
179
|
-
|------|------|
|
|
180
|
-
| `GET /pub/github/oauth?state=xxx` | 发起 GitHub 授权重定向 |
|
|
181
|
-
| `GET /pub/github/oauth/callback?code=xxx&state=xxx` | GitHub 回调,完成绑定 |
|
|
182
|
-
|
|
183
|
-
> OAuth 路由注册在 `/github/` 而非 `/api/` 下,因此不受 API Token 认证限制,用户浏览器可直接访问。
|
|
167
|
+
**Client ID**:从 GitHub App 的 `/app` API 自动获取(`GhClient.getClientId()`),**无需**在 bot 配置里写 `client_id` / `client_secret`。
|
|
184
168
|
|
|
185
169
|
### 前置条件
|
|
186
170
|
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
- GitHub App 设置页中的 Callback URL 须指向 `https://your-domain/pub/github/oauth/callback`
|
|
171
|
+
- 需要 **`database`** 插件(`github_oauth_users` 模型)
|
|
172
|
+
- Device Flow 在 IM 内完成,**不依赖** `/pub/github/oauth` HTTP 路由
|
|
190
173
|
|
|
191
174
|
## 数据库表
|
|
192
175
|
|
|
@@ -216,29 +199,30 @@ Headers:
|
|
|
216
199
|
| 字段 | 类型 | 说明 |
|
|
217
200
|
|------|------|------|
|
|
218
201
|
| id | integer | 主键 |
|
|
219
|
-
| platform | text | 聊天平台
|
|
220
|
-
| platform_uid | text |
|
|
202
|
+
| platform | text | 聊天平台 |
|
|
203
|
+
| platform_uid | text | 平台用户 ID |
|
|
221
204
|
| github_login | text | GitHub 用户名 |
|
|
222
|
-
|
|
|
223
|
-
|
|
|
224
|
-
| scope | text | 授权范围 |
|
|
225
|
-
| created_at | date | 创建时间 |
|
|
226
|
-
| updated_at | date | 更新时间 |
|
|
205
|
+
| access_token | text | Device Flow 获得的 token |
|
|
206
|
+
| created_at | integer | 创建时间戳 |
|
|
227
207
|
|
|
228
208
|
## 架构说明
|
|
229
209
|
|
|
230
210
|
```
|
|
231
211
|
adapter-github/
|
|
232
212
|
├── src/
|
|
233
|
-
│ ├── index.ts
|
|
234
|
-
│ ├──
|
|
235
|
-
│
|
|
213
|
+
│ ├── index.ts # 插件入口:provide、useContext、模型表
|
|
214
|
+
│ ├── adapter.ts # GitHubAdapter
|
|
215
|
+
│ ├── bot.ts # GitHubBot(Issue/PR 频道)
|
|
216
|
+
│ ├── gh-client.ts # GitHub REST(App JWT / Installation Token)
|
|
217
|
+
│ ├── register-github-mcp.ts # orchestrator.addMcp(server-github)
|
|
218
|
+
│ ├── agent-prompt.ts # 平台 prompt / deferred 工具筛选
|
|
219
|
+
│ └── types.ts # BotConfig、Webhook payload、Channel ID
|
|
236
220
|
├── package.json
|
|
237
221
|
└── README.md
|
|
238
222
|
```
|
|
239
223
|
|
|
240
|
-
- **无 `@zhin.js/host-router`
|
|
241
|
-
- **有 `@zhin.js/host-router`
|
|
224
|
+
- **无 `@zhin.js/host-router` 时**:REST 工具与轮询仍可用,但无法注册 Webhook
|
|
225
|
+
- **有 `@zhin.js/host-router` 时**:注册 Webhook;MCP 通过 `orchestrator.addMcp`(需 PAT 或 `ai.githubMcp.token`)
|
|
242
226
|
|
|
243
227
|
## 许可证
|
|
244
228
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-github",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "Zhin.js adapter for GitHub (gh CLI) — treat issues/PRs as chat channels, full repo management, webhook notifications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^6.0.3",
|
|
49
|
-
"zhin.js": "1.0.
|
|
49
|
+
"zhin.js": "1.0.89"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@zhin.js/host-router": "0.0.
|
|
53
|
-
"zhin.js": "1.0.
|
|
52
|
+
"@zhin.js/host-router": "0.0.2",
|
|
53
|
+
"zhin.js": "1.0.89"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"@zhin.js/host-router": {
|