@zhin.js/adapter-github 0.1.40 → 0.1.41
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/lib/gh-client.d.ts +0 -162
- package/lib/gh-client.d.ts.map +1 -1
- package/lib/gh-client.js +0 -101
- package/lib/gh-client.js.map +1 -1
- package/lib/index.js +0 -508
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/skills/github/SKILL.md +205 -47
- package/src/gh-client.ts +0 -136
- package/src/index.ts +0 -463
- package/LICENSE +0 -21
package/src/index.ts
CHANGED
|
@@ -109,469 +109,6 @@ useContext('github', (adapter) => {
|
|
|
109
109
|
// ── Tool 工具注册 ─────────────────────────────────────────────────────────
|
|
110
110
|
useContext('tool', 'github', (toolService: ToolFeature, adapter: GitHubAdapter) => {
|
|
111
111
|
const tools: Tool[] = [
|
|
112
|
-
// --- PR ---
|
|
113
|
-
{
|
|
114
|
-
name: 'github_pr',
|
|
115
|
-
description: 'GitHub PR 操作:list/view/diff/merge/create/review/close',
|
|
116
|
-
parameters: {
|
|
117
|
-
type: 'object' as const,
|
|
118
|
-
properties: {
|
|
119
|
-
action: { type: 'string' as const, description: 'list|view|diff|merge|create|review|close', enum: ['list','view','diff','merge','create','review','close'] },
|
|
120
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
121
|
-
number: { type: 'number' as const, description: 'PR 编号' },
|
|
122
|
-
title: { type: 'string' as const, description: 'PR 标题 (create)' },
|
|
123
|
-
body: { type: 'string' as const, description: 'PR 描述 / Review 评语' },
|
|
124
|
-
head: { type: 'string' as const, description: '源分支 (create)' },
|
|
125
|
-
base: { type: 'string' as const, description: '目标分支 (create,默认 main)' },
|
|
126
|
-
state: { type: 'string' as const, description: 'open/closed/all (list)' },
|
|
127
|
-
approve: { type: 'boolean' as const, description: 'review 时 approve' },
|
|
128
|
-
method: { type: 'string' as const, description: 'squash/merge/rebase (merge)' },
|
|
129
|
-
},
|
|
130
|
-
required: ['action', 'repo'],
|
|
131
|
-
},
|
|
132
|
-
platforms: ['github'],
|
|
133
|
-
tags: ['github'],
|
|
134
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
135
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
136
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
137
|
-
const { action, repo, number: num, title, body, head, base, state, approve, method } = args;
|
|
138
|
-
switch (action) {
|
|
139
|
-
case 'list': {
|
|
140
|
-
const r = await api.listPRs(repo, state || 'open');
|
|
141
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
142
|
-
if (!r.data.length) return `📭 没有 ${state || 'open'} 状态的 PR`;
|
|
143
|
-
return r.data.map((p: any) =>
|
|
144
|
-
`#${p.number} ${p.draft ? '[Draft] ' : ''}${p.title}\n 👤 ${p.user.login} | 🌿 ${p.head.ref} → ${p.base.ref} | ${p.state}`
|
|
145
|
-
).join('\n\n');
|
|
146
|
-
}
|
|
147
|
-
case 'view': {
|
|
148
|
-
if (!num) return '❌ 请提供 PR 编号';
|
|
149
|
-
const r = await api.getPR(repo, num);
|
|
150
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
151
|
-
const p = r.data;
|
|
152
|
-
return [
|
|
153
|
-
`#${p.number} ${p.title}`,
|
|
154
|
-
`👤 ${p.user.login} | ${p.state} | 🌿 ${p.head.ref} → ${p.base.ref}`,
|
|
155
|
-
`📅 ${p.created_at?.split('T')[0]} | +${p.additions} -${p.deletions} (${p.changed_files} files)`,
|
|
156
|
-
p.body ? `\n${p.body.slice(0, 500)}${p.body.length > 500 ? '...' : ''}` : '',
|
|
157
|
-
`\n🔗 ${p.html_url}`,
|
|
158
|
-
].filter(Boolean).join('\n');
|
|
159
|
-
}
|
|
160
|
-
case 'diff': {
|
|
161
|
-
if (!num) return '❌ 请提供 PR 编号';
|
|
162
|
-
const r = await api.getPRDiff(repo, num);
|
|
163
|
-
if (!r.ok) return '❌ 获取 diff 失败';
|
|
164
|
-
const lines = r.data.split('\n');
|
|
165
|
-
return lines.length > 100 ? lines.slice(0, 100).join('\n') + `\n\n... (共 ${lines.length} 行)` : r.data;
|
|
166
|
-
}
|
|
167
|
-
case 'merge': {
|
|
168
|
-
if (!num) return '❌ 请提供 PR 编号';
|
|
169
|
-
const r = await api.mergePR(repo, num, method || 'squash');
|
|
170
|
-
return r.ok ? `✅ PR #${num} 已合并` : `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
171
|
-
}
|
|
172
|
-
case 'create': {
|
|
173
|
-
if (!title) return '❌ 请提供 PR 标题';
|
|
174
|
-
if (!head) return '❌ 请提供源分支 (head)';
|
|
175
|
-
const r = await api.createPR(repo, title, body || '', head, base || 'main');
|
|
176
|
-
return r.ok ? `✅ PR 已创建: ${r.data.html_url}` : `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
177
|
-
}
|
|
178
|
-
case 'review': {
|
|
179
|
-
if (!num) return '❌ 请提供 PR 编号';
|
|
180
|
-
const event = approve ? 'APPROVE' : 'COMMENT';
|
|
181
|
-
const r = await api.createPRReview(repo, num, event as any, body || undefined);
|
|
182
|
-
return r.ok ? `✅ PR #${num} ${approve ? '已批准' : '已评论'}` : `❌ ${r.data?.message}`;
|
|
183
|
-
}
|
|
184
|
-
case 'close': {
|
|
185
|
-
if (!num) return '❌ 请提供 PR 编号';
|
|
186
|
-
const r = await api.closePR(repo, num);
|
|
187
|
-
return r.ok ? `✅ PR #${num} 已关闭` : `❌ ${r.data?.message}`;
|
|
188
|
-
}
|
|
189
|
-
default: return `❌ 未知操作: ${action}`;
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
// --- Issue ---
|
|
194
|
-
{
|
|
195
|
-
name: 'github_issue',
|
|
196
|
-
description: 'GitHub Issue 操作:list/view/create/close/comment',
|
|
197
|
-
parameters: {
|
|
198
|
-
type: 'object' as const,
|
|
199
|
-
properties: {
|
|
200
|
-
action: { type: 'string' as const, description: 'list|view|create|close|comment', enum: ['list','view','create','close','comment'] },
|
|
201
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
202
|
-
number: { type: 'number' as const, description: 'Issue 编号' },
|
|
203
|
-
title: { type: 'string' as const, description: 'Issue 标题 (create)' },
|
|
204
|
-
body: { type: 'string' as const, description: 'Issue 内容 / 评论内容' },
|
|
205
|
-
labels: { type: 'string' as const, description: '标签,逗号分隔 (create)' },
|
|
206
|
-
state: { type: 'string' as const, description: 'open/closed/all (list)' },
|
|
207
|
-
},
|
|
208
|
-
required: ['action', 'repo'],
|
|
209
|
-
},
|
|
210
|
-
platforms: ['github'],
|
|
211
|
-
tags: ['github'],
|
|
212
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
213
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
214
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
215
|
-
const { action, repo, number: num, title, body, labels, state } = args;
|
|
216
|
-
switch (action) {
|
|
217
|
-
case 'list': {
|
|
218
|
-
const r = await api.listIssues(repo, state || 'open');
|
|
219
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
220
|
-
const issues = r.data.filter((i: any) => !i.pull_request);
|
|
221
|
-
if (!issues.length) return `📭 没有 ${state || 'open'} 状态的 Issue`;
|
|
222
|
-
return issues.map((i: any) => {
|
|
223
|
-
const lbls = i.labels?.map((l: any) => l.name).join(', ') || '';
|
|
224
|
-
return `#${i.number} ${i.title}\n 👤 ${i.user.login}${lbls ? ` | 🏷️ ${lbls}` : ''} | ${i.state}`;
|
|
225
|
-
}).join('\n\n');
|
|
226
|
-
}
|
|
227
|
-
case 'view': {
|
|
228
|
-
if (!num) return '❌ 请提供 Issue 编号';
|
|
229
|
-
const r = await api.getIssue(repo, num);
|
|
230
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
231
|
-
const i = r.data;
|
|
232
|
-
return [
|
|
233
|
-
`#${i.number} ${i.title}`,
|
|
234
|
-
`👤 ${i.user.login} | ${i.state} | 📅 ${i.created_at?.split('T')[0]}`,
|
|
235
|
-
i.labels?.length ? `🏷️ ${i.labels.map((l: any) => l.name).join(', ')}` : null,
|
|
236
|
-
i.body ? `\n${i.body.slice(0, 500)}${i.body.length > 500 ? '...' : ''}` : '',
|
|
237
|
-
`\n🔗 ${i.html_url}`,
|
|
238
|
-
].filter(Boolean).join('\n');
|
|
239
|
-
}
|
|
240
|
-
case 'create': {
|
|
241
|
-
if (!title) return '❌ 请提供 Issue 标题';
|
|
242
|
-
const labelArr = labels ? labels.split(',').map((s: string) => s.trim()) : undefined;
|
|
243
|
-
const r = await api.createIssue(repo, title, body || undefined, labelArr);
|
|
244
|
-
return r.ok ? `✅ Issue 已创建: ${r.data.html_url}` : `❌ ${r.data?.message}`;
|
|
245
|
-
}
|
|
246
|
-
case 'close': {
|
|
247
|
-
if (!num) return '❌ 请提供 Issue 编号';
|
|
248
|
-
const r = await api.closeIssue(repo, num);
|
|
249
|
-
return r.ok ? `✅ Issue #${num} 已关闭` : `❌ ${r.data?.message}`;
|
|
250
|
-
}
|
|
251
|
-
case 'comment': {
|
|
252
|
-
if (!num) return '❌ 请提供 Issue 编号';
|
|
253
|
-
if (!body) return '❌ 请提供评论内容';
|
|
254
|
-
const r = await api.createIssueComment(repo, num, body);
|
|
255
|
-
return r.ok ? `✅ 已评论 Issue #${num}` : `❌ ${JSON.stringify(r.data)}`;
|
|
256
|
-
}
|
|
257
|
-
default: return `❌ 未知操作: ${action}`;
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
// --- Repo ---
|
|
262
|
-
{
|
|
263
|
-
name: 'github_repo',
|
|
264
|
-
description: 'GitHub 仓库查询:info/branches/releases/runs(CI)/stars',
|
|
265
|
-
parameters: {
|
|
266
|
-
type: 'object' as const,
|
|
267
|
-
properties: {
|
|
268
|
-
action: { type: 'string' as const, description: 'info|branches|releases|runs|stars', enum: ['info','branches','releases','runs','stars'] },
|
|
269
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
270
|
-
limit: { type: 'number' as const, description: '返回数量,默认 10' },
|
|
271
|
-
},
|
|
272
|
-
required: ['action', 'repo'],
|
|
273
|
-
},
|
|
274
|
-
platforms: ['github'],
|
|
275
|
-
tags: ['github'],
|
|
276
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
277
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
278
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
279
|
-
const { action, repo, limit: lim } = args;
|
|
280
|
-
const limit = lim || 10;
|
|
281
|
-
switch (action) {
|
|
282
|
-
case 'info': {
|
|
283
|
-
const r = await api.getRepo(repo);
|
|
284
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
285
|
-
const d = r.data;
|
|
286
|
-
return [
|
|
287
|
-
`📦 ${d.full_name}${d.private ? ' 🔒' : ''}`,
|
|
288
|
-
d.description ? `📝 ${d.description}` : null,
|
|
289
|
-
`⭐ ${d.stargazers_count} | 🍴 ${d.forks_count} | 👀 ${d.watchers_count}`,
|
|
290
|
-
`🌿 默认分支: ${d.default_branch}`,
|
|
291
|
-
d.license ? `📄 ${d.license.name}` : null,
|
|
292
|
-
d.homepage ? `🌐 ${d.homepage}` : null,
|
|
293
|
-
`📅 创建: ${d.created_at?.split('T')[0]} | 推送: ${d.pushed_at?.split('T')[0]}`,
|
|
294
|
-
].filter(Boolean).join('\n');
|
|
295
|
-
}
|
|
296
|
-
case 'branches': {
|
|
297
|
-
const r = await api.listBranches(repo, limit);
|
|
298
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
299
|
-
return r.data.length
|
|
300
|
-
? `🌿 分支 (${r.data.length}):\n${r.data.map((b: any) => ` • ${b.name}${b.protected ? ' 🔒' : ''}`).join('\n')}`
|
|
301
|
-
: '没有找到分支';
|
|
302
|
-
}
|
|
303
|
-
case 'releases': {
|
|
304
|
-
const r = await api.listReleases(repo, limit);
|
|
305
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
306
|
-
if (!r.data.length) return '📭 暂无发布';
|
|
307
|
-
return r.data.map((rel: any) =>
|
|
308
|
-
`${rel.prerelease ? '🧪' : '📦'} ${rel.tag_name} — ${rel.name || '(no title)'}\n 📅 ${rel.published_at?.split('T')[0]} | 👤 ${rel.author?.login}`
|
|
309
|
-
).join('\n\n');
|
|
310
|
-
}
|
|
311
|
-
case 'runs': {
|
|
312
|
-
const r = await api.listWorkflowRuns(repo, limit);
|
|
313
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
314
|
-
const runs = r.data.workflow_runs || [];
|
|
315
|
-
if (!runs.length) return '📭 暂无 CI 记录';
|
|
316
|
-
return runs.map((run: any) => {
|
|
317
|
-
const icon = run.conclusion === 'success' ? '✅' : run.conclusion === 'failure' ? '❌' : run.status === 'in_progress' ? '🔄' : '⏳';
|
|
318
|
-
return `${icon} #${run.id} ${run.display_title}\n 🌿 ${run.head_branch} | ${run.status}${run.conclusion ? '/' + run.conclusion : ''}`;
|
|
319
|
-
}).join('\n\n');
|
|
320
|
-
}
|
|
321
|
-
case 'stars': {
|
|
322
|
-
const r = await api.getRepo(repo);
|
|
323
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
324
|
-
return `⭐ ${r.data.stargazers_count} stars | 🍴 ${r.data.forks_count} forks`;
|
|
325
|
-
}
|
|
326
|
-
default: return `❌ 未知查询: ${action}`;
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
// --- Search ---
|
|
331
|
-
{
|
|
332
|
-
name: 'github_search',
|
|
333
|
-
description: 'GitHub 搜索:在 issues/repos/code 中搜索',
|
|
334
|
-
parameters: {
|
|
335
|
-
type: 'object' as const,
|
|
336
|
-
properties: {
|
|
337
|
-
action: { type: 'string' as const, description: 'issues|repos|code', enum: ['issues', 'repos', 'code'] },
|
|
338
|
-
query: { type: 'string' as const, description: '搜索关键词' },
|
|
339
|
-
limit: { type: 'number' as const, description: '返回数量,默认 10' },
|
|
340
|
-
},
|
|
341
|
-
required: ['action', 'query'],
|
|
342
|
-
},
|
|
343
|
-
platforms: ['github'],
|
|
344
|
-
tags: ['github'],
|
|
345
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
346
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
347
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
348
|
-
const { action, query: q, limit: lim } = args;
|
|
349
|
-
const limit = lim || 10;
|
|
350
|
-
switch (action) {
|
|
351
|
-
case 'issues': {
|
|
352
|
-
const r = await api.searchIssues(q, limit);
|
|
353
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
354
|
-
if (!r.data.items.length) return '📭 没有匹配的 Issue/PR';
|
|
355
|
-
return `🔍 共 ${r.data.total_count} 条,显示前 ${r.data.items.length}:\n\n` +
|
|
356
|
-
r.data.items.map((i: any) =>
|
|
357
|
-
`${i.pull_request ? '🔀' : '🐛'} ${i.repository_url.replace('https://api.github.com/repos/', '')}#${i.number}\n ${i.title}\n 👤 ${i.user.login} | ${i.state}`
|
|
358
|
-
).join('\n\n');
|
|
359
|
-
}
|
|
360
|
-
case 'repos': {
|
|
361
|
-
const r = await api.searchRepos(q, limit);
|
|
362
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
363
|
-
if (!r.data.items.length) return '📭 没有匹配的仓库';
|
|
364
|
-
return `🔍 共 ${r.data.total_count} 条,显示前 ${r.data.items.length}:\n\n` +
|
|
365
|
-
r.data.items.map((repo: any) =>
|
|
366
|
-
`📦 ${repo.full_name}${repo.private ? ' 🔒' : ''}\n ${repo.description || '(无描述)'}\n ⭐ ${repo.stargazers_count} | 🍴 ${repo.forks_count} | 📝 ${repo.language || '?'}`
|
|
367
|
-
).join('\n\n');
|
|
368
|
-
}
|
|
369
|
-
case 'code': {
|
|
370
|
-
const r = await api.searchCode(q, limit);
|
|
371
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
372
|
-
if (!r.data.items.length) return '📭 没有匹配的代码';
|
|
373
|
-
return `🔍 共 ${r.data.total_count} 条,显示前 ${r.data.items.length}:\n\n` +
|
|
374
|
-
r.data.items.map((c: any) =>
|
|
375
|
-
`📄 ${c.repository.full_name}/${c.path}\n 🔗 ${c.html_url}`
|
|
376
|
-
).join('\n\n');
|
|
377
|
-
}
|
|
378
|
-
default: return `❌ 未知搜索类型: ${action}`;
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
// --- Label ---
|
|
383
|
-
{
|
|
384
|
-
name: 'github_label',
|
|
385
|
-
description: 'GitHub 标签管理:查看/添加/移除 Issue/PR 标签',
|
|
386
|
-
parameters: {
|
|
387
|
-
type: 'object' as const,
|
|
388
|
-
properties: {
|
|
389
|
-
action: { type: 'string' as const, description: 'list|add|remove', enum: ['list', 'add', 'remove'] },
|
|
390
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
391
|
-
number: { type: 'number' as const, description: 'Issue/PR 编号 (add/remove 必填)' },
|
|
392
|
-
labels: { type: 'string' as const, description: '标签名,逗号分隔 (add/remove)' },
|
|
393
|
-
},
|
|
394
|
-
required: ['action', 'repo'],
|
|
395
|
-
},
|
|
396
|
-
platforms: ['github'],
|
|
397
|
-
tags: ['github'],
|
|
398
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
399
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
400
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
401
|
-
const { action, repo, number: num, labels } = args;
|
|
402
|
-
switch (action) {
|
|
403
|
-
case 'list': {
|
|
404
|
-
const r = await api.listLabels(repo);
|
|
405
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
406
|
-
if (!r.data.length) return '📭 仓库没有标签';
|
|
407
|
-
return `🏷️ ${repo} 标签 (${r.data.length}):\n` +
|
|
408
|
-
r.data.map((l: any) => ` • ${l.name}${l.description ? ` — ${l.description}` : ''}`).join('\n');
|
|
409
|
-
}
|
|
410
|
-
case 'add': {
|
|
411
|
-
if (!num) return '❌ 请提供 Issue/PR 编号';
|
|
412
|
-
if (!labels) return '❌ 请提供标签名';
|
|
413
|
-
const labelArr = labels.split(',').map((s: string) => s.trim());
|
|
414
|
-
const r = await api.addLabels(repo, num, labelArr);
|
|
415
|
-
return r.ok ? `✅ 已添加标签: ${labelArr.join(', ')}` : `❌ ${JSON.stringify(r.data)}`;
|
|
416
|
-
}
|
|
417
|
-
case 'remove': {
|
|
418
|
-
if (!num) return '❌ 请提供 Issue/PR 编号';
|
|
419
|
-
if (!labels) return '❌ 请提供要移除的标签名';
|
|
420
|
-
const labelArr = labels.split(',').map((s: string) => s.trim());
|
|
421
|
-
const results: string[] = [];
|
|
422
|
-
for (const label of labelArr) {
|
|
423
|
-
const r = await api.removeLabel(repo, num, label);
|
|
424
|
-
results.push(r.ok ? `✅ ${label}` : `❌ ${label}: ${r.data?.message || 'failed'}`);
|
|
425
|
-
}
|
|
426
|
-
return results.join('\n');
|
|
427
|
-
}
|
|
428
|
-
default: return `❌ 未知操作: ${action}`;
|
|
429
|
-
}
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
// --- Assign ---
|
|
433
|
-
{
|
|
434
|
-
name: 'github_assign',
|
|
435
|
-
description: 'GitHub 指派管理:给 Issue/PR 添加/移除指派人',
|
|
436
|
-
parameters: {
|
|
437
|
-
type: 'object' as const,
|
|
438
|
-
properties: {
|
|
439
|
-
action: { type: 'string' as const, description: 'add|remove', enum: ['add', 'remove'] },
|
|
440
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
441
|
-
number: { type: 'number' as const, description: 'Issue/PR 编号 (必填)' },
|
|
442
|
-
assignees: { type: 'string' as const, description: '用户名,逗号分隔 (必填)' },
|
|
443
|
-
},
|
|
444
|
-
required: ['action', 'repo', 'number', 'assignees'],
|
|
445
|
-
},
|
|
446
|
-
platforms: ['github'],
|
|
447
|
-
tags: ['github'],
|
|
448
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
449
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
450
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
451
|
-
const { action, repo, number: num, assignees } = args;
|
|
452
|
-
const assigneeArr = assignees.split(',').map((s: string) => s.trim());
|
|
453
|
-
if (action === 'add') {
|
|
454
|
-
const r = await api.addAssignees(repo, num, assigneeArr);
|
|
455
|
-
return r.ok ? `✅ 已指派: ${assigneeArr.join(', ')}` : `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
456
|
-
} else {
|
|
457
|
-
const r = await api.removeAssignees(repo, num, assigneeArr);
|
|
458
|
-
return r.ok ? `✅ 已移除指派: ${assigneeArr.join(', ')}` : `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
},
|
|
462
|
-
// --- File ---
|
|
463
|
-
{
|
|
464
|
-
name: 'github_file',
|
|
465
|
-
description: '读取 GitHub 仓库中的文件内容',
|
|
466
|
-
parameters: {
|
|
467
|
-
type: 'object' as const,
|
|
468
|
-
properties: {
|
|
469
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
470
|
-
path: { type: 'string' as const, description: '文件路径 (必填)' },
|
|
471
|
-
ref: { type: 'string' as const, description: '分支/tag/commit SHA (可选,默认主分支)' },
|
|
472
|
-
},
|
|
473
|
-
required: ['repo', 'path'],
|
|
474
|
-
},
|
|
475
|
-
platforms: ['github'],
|
|
476
|
-
tags: ['github'],
|
|
477
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
478
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
479
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
480
|
-
const r = await api.getFileContent(args.repo, args.path, args.ref);
|
|
481
|
-
if (!r.ok) return `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
482
|
-
if (Array.isArray(r.data)) {
|
|
483
|
-
return `📂 ${args.path} (目录,${r.data.length} 项):\n` +
|
|
484
|
-
r.data.map((f: any) => ` ${f.type === 'dir' ? '📁' : '📄'} ${f.name}`).join('\n');
|
|
485
|
-
}
|
|
486
|
-
if (r.data.type === 'file' && r.data.content) {
|
|
487
|
-
const decoded = Buffer.from(r.data.content, 'base64').toString('utf-8');
|
|
488
|
-
const maxLen = 3000;
|
|
489
|
-
const truncated = decoded.length > maxLen;
|
|
490
|
-
return `📄 ${r.data.path} (${r.data.size} bytes)\n\n${decoded.slice(0, maxLen)}${truncated ? `\n\n... (截断,共 ${decoded.length} 字符)` : ''}`;
|
|
491
|
-
}
|
|
492
|
-
return `📄 ${r.data.path} — ${r.data.type} (${r.data.size} bytes)\n🔗 ${r.data.html_url}`;
|
|
493
|
-
},
|
|
494
|
-
},
|
|
495
|
-
// --- Commits ---
|
|
496
|
-
{
|
|
497
|
-
name: 'github_commits',
|
|
498
|
-
description: 'GitHub 提交查询:列出提交记录或对比两个分支',
|
|
499
|
-
parameters: {
|
|
500
|
-
type: 'object' as const,
|
|
501
|
-
properties: {
|
|
502
|
-
action: { type: 'string' as const, description: 'list|compare', enum: ['list', 'compare'] },
|
|
503
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
504
|
-
sha: { type: 'string' as const, description: '分支/SHA (list)' },
|
|
505
|
-
path: { type: 'string' as const, description: '按文件路径过滤 (list)' },
|
|
506
|
-
base: { type: 'string' as const, description: '基准分支 (compare)' },
|
|
507
|
-
head: { type: 'string' as const, description: '目标分支 (compare)' },
|
|
508
|
-
limit: { type: 'number' as const, description: '返回数量,默认 10' },
|
|
509
|
-
},
|
|
510
|
-
required: ['action', 'repo'],
|
|
511
|
-
},
|
|
512
|
-
platforms: ['github'],
|
|
513
|
-
tags: ['github'],
|
|
514
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
515
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
516
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
517
|
-
const { action, repo, sha, path, base, head, limit: lim } = args;
|
|
518
|
-
if (action === 'list') {
|
|
519
|
-
const r = await api.listCommits(repo, sha, path, lim || 10);
|
|
520
|
-
if (!r.ok) return `❌ ${JSON.stringify(r.data)}`;
|
|
521
|
-
if (!r.data.length) return '📭 没有找到提交记录';
|
|
522
|
-
return r.data.map((c: any) =>
|
|
523
|
-
`• ${c.sha.substring(0, 7)} ${c.commit.message.split('\n')[0]}\n 👤 ${c.commit.author?.name || '?'} | 📅 ${c.commit.author?.date?.split('T')[0] || '?'}`
|
|
524
|
-
).join('\n\n');
|
|
525
|
-
} else {
|
|
526
|
-
if (!base || !head) return '❌ compare 需要 base 和 head 参数';
|
|
527
|
-
const r = await api.compareCommits(repo, base, head);
|
|
528
|
-
if (!r.ok) return `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
529
|
-
const d = r.data;
|
|
530
|
-
return [
|
|
531
|
-
`🔀 ${base} ← ${head}`,
|
|
532
|
-
`📊 ${d.status} | ${d.ahead_by} ahead, ${d.behind_by} behind`,
|
|
533
|
-
`📝 ${d.total_commits} commits | ${d.files?.length || 0} files changed`,
|
|
534
|
-
d.commits?.length ? '\n最近提交:\n' + d.commits.slice(0, 5).map((c: any) =>
|
|
535
|
-
` • ${c.sha.substring(0, 7)} ${c.commit.message.split('\n')[0]}`
|
|
536
|
-
).join('\n') : '',
|
|
537
|
-
].filter(Boolean).join('\n');
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
// --- Edit (Issue/PR) ---
|
|
542
|
-
{
|
|
543
|
-
name: 'github_edit',
|
|
544
|
-
description: '编辑 GitHub Issue 或 PR 的标题、正文、状态',
|
|
545
|
-
parameters: {
|
|
546
|
-
type: 'object' as const,
|
|
547
|
-
properties: {
|
|
548
|
-
type: { type: 'string' as const, description: 'issue|pr', enum: ['issue', 'pr'] },
|
|
549
|
-
repo: { type: 'string' as const, description: 'owner/repo (必填)' },
|
|
550
|
-
number: { type: 'number' as const, description: 'Issue/PR 编号 (必填)' },
|
|
551
|
-
title: { type: 'string' as const, description: '新标题' },
|
|
552
|
-
body: { type: 'string' as const, description: '新正文' },
|
|
553
|
-
state: { type: 'string' as const, description: 'open|closed' },
|
|
554
|
-
},
|
|
555
|
-
required: ['type', 'repo', 'number'],
|
|
556
|
-
},
|
|
557
|
-
platforms: ['github'],
|
|
558
|
-
tags: ['github'],
|
|
559
|
-
execute: async (args: Record<string, any>, context?: ToolContext) => {
|
|
560
|
-
const api = await adapter.getUserOrDefaultAPI(context?.platform, context?.senderId);
|
|
561
|
-
if (!api) return '❌ 没有可用的 GitHub bot';
|
|
562
|
-
const { type: itemType, repo, number: num, title, body, state } = args;
|
|
563
|
-
const data: any = {};
|
|
564
|
-
if (title) data.title = title;
|
|
565
|
-
if (body) data.body = body;
|
|
566
|
-
if (state) data.state = state;
|
|
567
|
-
if (!Object.keys(data).length) return '❌ 请至少提供一个要修改的字段 (title/body/state)';
|
|
568
|
-
const r = itemType === 'pr'
|
|
569
|
-
? await api.updatePR(repo, num, data)
|
|
570
|
-
: await api.updateIssue(repo, num, data);
|
|
571
|
-
if (!r.ok) return `❌ ${r.data?.message || JSON.stringify(r.data)}`;
|
|
572
|
-
return `✅ ${itemType === 'pr' ? 'PR' : 'Issue'} #${num} 已更新\n🔗 ${r.data.html_url}`;
|
|
573
|
-
},
|
|
574
|
-
},
|
|
575
112
|
// --- Star ---
|
|
576
113
|
{
|
|
577
114
|
name: 'github_star',
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 凉菜
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|