koishi-plugin-githubsth 1.0.0 → 1.0.1-beta

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.
@@ -3,13 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.apply = apply;
4
4
  function apply(ctx) {
5
5
  const logger = ctx.logger('githubsth');
6
+ const repoRegex = /^[\w-]+\/[\w-\.]+$/;
6
7
  ctx.command('githubsth.trust', '管理信任仓库', { authority: 3 })
7
8
  .alias('gh.trust');
8
9
  ctx.command('githubsth.trust.add <repo>', '添加信任仓库')
9
10
  .action(async ({ session }, repo) => {
10
11
  if (!repo)
11
12
  return '请指定仓库名称 (owner/repo)。';
13
+ if (!repoRegex.test(repo))
14
+ return '仓库名称格式不正确 (应为 owner/repo)。';
12
15
  try {
16
+ // Check existence first to avoid UNIQUE constraint error log from driver
17
+ const existing = await ctx.database.get('github_trusted_repo', { repo });
18
+ if (existing.length > 0) {
19
+ return '该仓库已在信任列表中。';
20
+ }
13
21
  await ctx.database.create('github_trusted_repo', {
14
22
  repo,
15
23
  enabled: true,
@@ -19,7 +27,7 @@ function apply(ctx) {
19
27
  return `已添加信任仓库: ${repo}`;
20
28
  }
21
29
  catch (e) {
22
- if (e.code === 'SQLITE_CONSTRAINT') { // Or handle duplicate error generically
30
+ if (e.code === 'SQLITE_CONSTRAINT') {
23
31
  return '该仓库已在信任列表中。';
24
32
  }
25
33
  logger.warn(e);
@@ -30,6 +38,7 @@ function apply(ctx) {
30
38
  .action(async ({ session }, repo) => {
31
39
  if (!repo)
32
40
  return '请指定仓库名称 (owner/repo)。';
41
+ // No regex check here needed strictly, but good for consistency
33
42
  const result = await ctx.database.remove('github_trusted_repo', { repo });
34
43
  if (result.matched === 0)
35
44
  return '未找到该信任仓库。';
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.apply = apply;
4
4
  function apply(ctx) {
5
5
  const logger = ctx.logger('githubsth');
6
+ const repoRegex = /^[\w-]+\/[\w-\.]+$/;
6
7
  ctx.command('githubsth.subscribe <repo> [events:text]', '订阅 GitHub 仓库')
7
8
  .alias('gh.sub')
8
9
  .action(async ({ session }, repo, eventsStr) => {
9
10
  if (!repo)
10
11
  return '请指定仓库名称 (owner/repo)。';
12
+ if (!repoRegex.test(repo))
13
+ return '仓库名称格式不正确 (应为 owner/repo)。';
11
14
  if (!session?.channelId)
12
15
  return '请在群组中使用此命令。';
13
16
  // Check trusted repo
package/lib/config.js CHANGED
@@ -10,6 +10,6 @@ exports.Config = koishi_1.Schema.object({
10
10
  repo: koishi_1.Schema.string().required(),
11
11
  channelId: koishi_1.Schema.string().required(),
12
12
  platform: koishi_1.Schema.string(),
13
- events: koishi_1.Schema.array(koishi_1.Schema.string()).default(['push', 'issues', 'pull_request']),
13
+ events: koishi_1.Schema.array(koishi_1.Schema.string()).default(['push', 'issues', 'pull_request', 'issue_comment', 'pull_request_review']),
14
14
  })).hidden().description('已废弃,请使用数据库管理订阅'),
15
15
  });
package/lib/index.d.ts CHANGED
@@ -3,7 +3,6 @@ import { Config } from './config';
3
3
  export declare const name = "githubsth";
4
4
  export declare const inject: {
5
5
  required: string[];
6
- optional: string[];
7
6
  };
8
7
  export * from './config';
9
8
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -50,8 +50,7 @@ const notifier_1 = require("./services/notifier");
50
50
  const formatter_1 = require("./services/formatter");
51
51
  exports.name = 'githubsth';
52
52
  exports.inject = {
53
- required: ['database'],
54
- optional: ['github']
53
+ required: ['database', 'github'],
55
54
  };
56
55
  __exportStar(require("./config"), exports);
57
56
  function apply(ctx, config) {
@@ -66,4 +65,6 @@ function apply(ctx, config) {
66
65
  ctx.plugin(commands, config);
67
66
  ctx.plugin(admin);
68
67
  ctx.plugin(subscribe);
68
+ // 加载成功日志
69
+ console.log('githubsth plugin loaded');
69
70
  }
@@ -2,6 +2,9 @@ declare const _default: {
2
2
  commands: {
3
3
  githubsth: {
4
4
  description: string;
5
+ };
6
+ 'githubsth.repo': {
7
+ description: string;
5
8
  messages: {
6
9
  repo_info: string;
7
10
  error: string;
@@ -9,9 +12,6 @@ declare const _default: {
9
12
  not_found: string;
10
13
  };
11
14
  };
12
- 'githubsth.repo': {
13
- description: string;
14
- };
15
15
  };
16
16
  };
17
17
  export default _default;
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  commands: {
5
5
  githubsth: {
6
- description: 'GitHub 交互插件',
6
+ description: 'GitHub 交互插件'
7
+ },
8
+ 'githubsth.repo': {
9
+ description: '获取仓库信息',
7
10
  messages: {
8
11
  repo_info: '仓库: {0}/{1}\n描述: {2}\nStars: {3}',
9
12
  error: '获取信息失败: {0}',
10
13
  specify_repo: '请指定仓库名称。',
11
14
  not_found: '未找到仓库或无权限访问。'
12
15
  }
13
- },
14
- 'githubsth.repo': {
15
- description: '获取仓库信息'
16
16
  }
17
17
  }
18
18
  };
@@ -14,4 +14,6 @@ export declare class Formatter extends Service {
14
14
  formatRelease(payload: any): h | null;
15
15
  formatDiscussion(payload: any): h;
16
16
  formatWorkflowRun(payload: any): h | null;
17
+ formatIssueComment(payload: any): h | null;
18
+ formatPullRequestReview(payload: any): h | null;
17
19
  }
@@ -90,5 +90,29 @@ class Formatter extends koishi_1.Service {
90
90
  (0, koishi_1.h)('text', { content: `链接: ${workflow_run.html_url}` })
91
91
  ]);
92
92
  }
93
+ formatIssueComment(payload) {
94
+ const { action, issue, comment, repository, sender } = payload;
95
+ if (action !== 'created')
96
+ return null;
97
+ return (0, koishi_1.h)('message', [
98
+ (0, koishi_1.h)('text', { content: `[GitHub] ${repository.full_name} Issue 收到新评论\n` }),
99
+ (0, koishi_1.h)('text', { content: `标题: #${issue.number} ${issue.title}\n` }),
100
+ (0, koishi_1.h)('text', { content: `评论人: ${sender.login}\n` }),
101
+ (0, koishi_1.h)('text', { content: `内容: ${comment.body.substring(0, 100)}${comment.body.length > 100 ? '...' : ''}\n` }),
102
+ (0, koishi_1.h)('text', { content: `链接: ${comment.html_url}` })
103
+ ]);
104
+ }
105
+ formatPullRequestReview(payload) {
106
+ const { action, pull_request, review, repository, sender } = payload;
107
+ if (action !== 'submitted')
108
+ return null;
109
+ return (0, koishi_1.h)('message', [
110
+ (0, koishi_1.h)('text', { content: `[GitHub] ${repository.full_name} PR 收到 Review\n` }),
111
+ (0, koishi_1.h)('text', { content: `标题: #${pull_request.number} ${pull_request.title}\n` }),
112
+ (0, koishi_1.h)('text', { content: `Reviewer: ${sender.login}\n` }),
113
+ (0, koishi_1.h)('text', { content: `状态: ${review.state}\n` }),
114
+ (0, koishi_1.h)('text', { content: `链接: ${review.html_url}` })
115
+ ]);
116
+ }
93
117
  }
94
118
  exports.Formatter = Formatter;
@@ -18,6 +18,8 @@ class Notifier extends koishi_1.Service {
18
18
  this.ctx.on('github/release', (payload) => this.handleEvent('release', payload));
19
19
  this.ctx.on('github/discussion', (payload) => this.handleEvent('discussion', payload));
20
20
  this.ctx.on('github/workflow_run', (payload) => this.handleEvent('workflow_run', payload));
21
+ this.ctx.on('github/issue_comment', (payload) => this.handleEvent('issue_comment', payload));
22
+ this.ctx.on('github/pull_request_review', (payload) => this.handleEvent('pull_request_review', payload));
21
23
  }
22
24
  async handleEvent(event, payload) {
23
25
  const repoName = payload.repository?.full_name;
@@ -76,6 +78,12 @@ class Notifier extends koishi_1.Service {
76
78
  case 'workflow_run':
77
79
  message = this.ctx.formatter.formatWorkflowRun(payload);
78
80
  break;
81
+ case 'issue_comment':
82
+ message = this.ctx.formatter.formatIssueComment(payload);
83
+ break;
84
+ case 'pull_request_review':
85
+ message = this.ctx.formatter.formatPullRequestReview(payload);
86
+ break;
79
87
  }
80
88
  if (!message)
81
89
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-githubsth",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-beta",
4
4
  "description": "Github Subscriptions Notifications, push notifications for GitHub subscriptions For koishi",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -39,11 +39,10 @@
39
39
  },
40
40
  "service": {
41
41
  "required": [
42
- "database"
43
- ],
44
- "optional": [
42
+ "database",
45
43
  "github"
46
- ]
44
+ ],
45
+ "optional": []
47
46
  }
48
47
  }
49
48
  }