koishi-plugin-githubsth 1.0.2-test1 → 1.0.2-test2
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/commands/subscribe.js +60 -4
- package/package.json +1 -1
|
@@ -4,8 +4,33 @@ exports.apply = apply;
|
|
|
4
4
|
function apply(ctx) {
|
|
5
5
|
const logger = ctx.logger('githubsth');
|
|
6
6
|
const repoRegex = /^[\w-]+\/[\w-\.]+$/;
|
|
7
|
+
const validEvents = [
|
|
8
|
+
'push', 'issues', 'issue_comment', 'pull_request',
|
|
9
|
+
'pull_request_review', 'star', 'fork', 'release',
|
|
10
|
+
'discussion', 'workflow_run'
|
|
11
|
+
];
|
|
7
12
|
ctx.command('githubsth.subscribe <repo> [events:text]', '订阅 GitHub 仓库')
|
|
8
13
|
.alias('gh.sub')
|
|
14
|
+
.usage(`
|
|
15
|
+
订阅 GitHub 仓库通知。
|
|
16
|
+
如果不指定事件,默认订阅: push, issues, issue_comment, pull_request, pull_request_review, release, star, fork
|
|
17
|
+
|
|
18
|
+
可选事件:
|
|
19
|
+
- push: 代码推送
|
|
20
|
+
- issues: Issue 创建/关闭/重开
|
|
21
|
+
- issue_comment: Issue 评论
|
|
22
|
+
- pull_request: PR 创建/关闭/重开
|
|
23
|
+
- pull_request_review: PR 审查
|
|
24
|
+
- star: 标星
|
|
25
|
+
- fork: 仓库 Fork
|
|
26
|
+
- release: 发布新版本
|
|
27
|
+
- discussion: 讨论区更新
|
|
28
|
+
- workflow_run: Workflow 运行
|
|
29
|
+
|
|
30
|
+
示例:
|
|
31
|
+
gh.sub koishijs/koishi
|
|
32
|
+
gh.sub koishijs/koishi push,issues,star
|
|
33
|
+
`)
|
|
9
34
|
.action(async ({ session }, repo, eventsStr) => {
|
|
10
35
|
if (!repo)
|
|
11
36
|
return '请指定仓库名称 (owner/repo)。';
|
|
@@ -19,15 +44,46 @@ function apply(ctx) {
|
|
|
19
44
|
return '该仓库不在信任列表中,无法订阅。请联系管理员添加。';
|
|
20
45
|
}
|
|
21
46
|
// Parse events
|
|
22
|
-
|
|
47
|
+
let events;
|
|
48
|
+
if (eventsStr) {
|
|
49
|
+
// Split by comma, Chinese comma, or whitespace
|
|
50
|
+
events = eventsStr.split(/[,,\s]+/).map(e => e.trim()).filter(Boolean);
|
|
51
|
+
// Normalize events (kebab-case to snake_case)
|
|
52
|
+
events = events.map(e => e.replace(/-/g, '_'));
|
|
53
|
+
// Validate events
|
|
54
|
+
const invalidEvents = events.filter(e => !validEvents.includes(e) && e !== '*');
|
|
55
|
+
if (invalidEvents.length > 0) {
|
|
56
|
+
return `无效的事件类型: ${invalidEvents.join(', ')}。\n可选事件: ${validEvents.join(', ')}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Default events
|
|
61
|
+
events = ['push', 'issues', 'issue_comment', 'pull_request', 'pull_request_review', 'release', 'star', 'fork'];
|
|
62
|
+
}
|
|
23
63
|
try {
|
|
24
|
-
|
|
64
|
+
// Check if subscription exists
|
|
65
|
+
const existing = await ctx.database.get('github_subscription', {
|
|
25
66
|
repo,
|
|
26
67
|
channelId: session.channelId,
|
|
27
68
|
platform: session.platform || 'unknown',
|
|
28
|
-
events,
|
|
29
69
|
});
|
|
30
|
-
|
|
70
|
+
if (existing.length > 0) {
|
|
71
|
+
// Update existing subscription
|
|
72
|
+
await ctx.database.set('github_subscription', { id: existing[0].id }, {
|
|
73
|
+
events,
|
|
74
|
+
});
|
|
75
|
+
return `已更新 ${repo} 的订阅,当前监听事件: ${events.join(', ')}。`;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Create new subscription
|
|
79
|
+
await ctx.database.create('github_subscription', {
|
|
80
|
+
repo,
|
|
81
|
+
channelId: session.channelId,
|
|
82
|
+
platform: session.platform || 'unknown',
|
|
83
|
+
events,
|
|
84
|
+
});
|
|
85
|
+
return `已订阅 ${repo} 的 ${events.join(', ')} 事件。`;
|
|
86
|
+
}
|
|
31
87
|
}
|
|
32
88
|
catch (e) {
|
|
33
89
|
logger.warn(e);
|
package/package.json
CHANGED