koishi-plugin-githubsth 1.0.1-test1 → 1.0.1-test10

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/index.js CHANGED
@@ -53,21 +53,43 @@ exports.inject = {
53
53
  };
54
54
  __exportStar(require("./config"), exports);
55
55
  function apply(ctx, config) {
56
+ const logger = ctx.logger('githubsth');
57
+ logger.info('Plugin loading...');
56
58
  // 本地化
57
59
  ctx.i18n.define('zh-CN', zh_CN_1.default);
58
60
  // 数据库
59
61
  ctx.plugin(database);
60
62
  // 注册服务
63
+ logger.info('Registering Formatter...');
61
64
  ctx.plugin(formatter_1.Formatter);
65
+ logger.info('Registering Notifier...');
62
66
  ctx.plugin(notifier_1.Notifier, config);
67
+ // Debug listener for raw events
68
+ ctx.on('github/issues', (payload) => {
69
+ logger.info('[DEBUG] Global listener caught github/issues');
70
+ });
71
+ ctx.on('github/opened', (payload) => {
72
+ logger.info('[DEBUG] Global listener caught github/opened');
73
+ });
74
+ // Comprehensive debug listeners
75
+ ctx.on('github/webhook', (payload) => {
76
+ logger.info('[DEBUG] Global listener caught github/webhook');
77
+ });
78
+ // Middleware to log all sessions
79
+ ctx.middleware((session, next) => {
80
+ // Log any session event from github
81
+ if (session.platform === 'github') {
82
+ logger.info(`[DEBUG] Middleware saw session.type: ${session.type}, subtype: ${session.subtype}`);
83
+ }
84
+ return next();
85
+ });
63
86
  // 注册命令
64
87
  // admin and subscribe are already loaded in commands/index.ts, remove duplicate loading here
65
88
  try {
66
89
  ctx.plugin(commands, config);
67
- // 加载成功日志
68
- console.log('githubsth plugin loaded');
90
+ logger.info('Plugin loaded successfully');
69
91
  }
70
92
  catch (e) {
71
- console.error('githubsth plugin failed to load:', e);
93
+ logger.error('Plugin failed to load:', e);
72
94
  }
73
95
  }
@@ -1,7 +1,7 @@
1
1
  import { Context, Service, h } from 'koishi';
2
2
  declare module 'koishi' {
3
3
  interface Context {
4
- formatter: Formatter;
4
+ githubsthFormatter: Formatter;
5
5
  }
6
6
  }
7
7
  export declare class Formatter extends Service {
@@ -4,7 +4,8 @@ exports.Formatter = void 0;
4
4
  const koishi_1 = require("koishi");
5
5
  class Formatter extends koishi_1.Service {
6
6
  constructor(ctx) {
7
- super(ctx, 'formatter');
7
+ super(ctx, 'githubsthFormatter');
8
+ ctx.logger('githubsth').info('Formatter service initialized');
8
9
  }
9
10
  formatPush(payload) {
10
11
  const { repository, pusher, commits, compare } = payload;
@@ -2,7 +2,7 @@ import { Context, Service } from 'koishi';
2
2
  import { Config } from '../config';
3
3
  declare module 'koishi' {
4
4
  interface Context {
5
- notifier: Notifier;
5
+ githubsthNotifier: Notifier;
6
6
  }
7
7
  }
8
8
  export declare class Notifier extends Service {
@@ -5,29 +5,100 @@ const koishi_1 = require("koishi");
5
5
  class Notifier extends koishi_1.Service {
6
6
  // @ts-ignore
7
7
  constructor(ctx, config) {
8
- super(ctx, 'notifier', true);
8
+ super(ctx, 'githubsthNotifier', true);
9
9
  this.config = config;
10
+ this.ctx.logger('githubsth').info('Notifier service initialized');
10
11
  this.registerListeners();
11
12
  }
12
13
  registerListeners() {
13
14
  this.ctx.on('github/push', (payload) => this.handleEvent('push', payload));
14
15
  this.ctx.on('github/issues', (payload) => this.handleEvent('issues', payload));
15
16
  this.ctx.on('github/pull_request', (payload) => this.handleEvent('pull_request', payload));
17
+ this.ctx.on('github/pull-request', (payload) => this.handleEvent('pull_request', payload));
16
18
  this.ctx.on('github/star', (payload) => this.handleEvent('star', payload));
17
19
  this.ctx.on('github/fork', (payload) => this.handleEvent('fork', payload));
18
20
  this.ctx.on('github/release', (payload) => this.handleEvent('release', payload));
19
21
  this.ctx.on('github/discussion', (payload) => this.handleEvent('discussion', payload));
20
22
  this.ctx.on('github/workflow_run', (payload) => this.handleEvent('workflow_run', payload));
23
+ this.ctx.on('github/workflow-run', (payload) => this.handleEvent('workflow_run', payload));
21
24
  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));
25
+ this.ctx.on('github/issue-comment', (payload) => this.handleEvent('issue_comment', payload));
26
+ this.ctx.on('github/pull-request-review', (payload) => this.handleEvent('pull_request_review', payload));
27
+ // Fallback: Listen to message-created for adapters that map webhooks to messages
28
+ this.ctx.on('message-created', (session) => {
29
+ if (session.platform !== 'github')
30
+ return;
31
+ this.ctx.logger('githubsth').info(`[Debug] Message session keys: ${Object.keys(session).join(', ')}`);
32
+ this.ctx.logger('githubsth').info(`[Debug] Message session content: ${session.content}`);
33
+ // Try to find payload
34
+ const possiblePayload = session.payload || session.extra || session.data;
35
+ if (possiblePayload) {
36
+ this.ctx.logger('githubsth').info(`[Debug] Found payload in property: ${!!session.payload ? 'payload' : !!session.extra ? 'extra' : 'data'}`);
37
+ }
38
+ else {
39
+ this.ctx.logger('githubsth').warn('[Debug] No payload found in session');
40
+ }
41
+ // If we can't find the payload easily, we might need to rely on the adapter emitting proper events.
42
+ // But since we are here, let's try to see if 'payload' or 'extra' exists.
43
+ const payload = possiblePayload;
44
+ if (payload) {
45
+ this.ctx.logger('githubsth').info('Found payload in session, attempting to handle');
46
+ // Infer event type
47
+ let eventType = 'unknown';
48
+ if (payload.issue && payload.comment)
49
+ eventType = 'issue_comment';
50
+ else if (payload.issue)
51
+ eventType = 'issues';
52
+ else if (payload.pull_request && payload.review)
53
+ eventType = 'pull_request_review';
54
+ else if (payload.pull_request)
55
+ eventType = 'pull_request';
56
+ else if (payload.commits)
57
+ eventType = 'push';
58
+ else if (payload.starred_at !== undefined || (payload.action === 'started'))
59
+ eventType = 'star'; // star event usually has action 'created' but check payload structure
60
+ else if (payload.forkee)
61
+ eventType = 'fork';
62
+ else if (payload.release)
63
+ eventType = 'release';
64
+ else if (payload.discussion)
65
+ eventType = 'discussion';
66
+ else if (payload.workflow_run)
67
+ eventType = 'workflow_run';
68
+ if (eventType !== 'unknown') {
69
+ this.handleEvent(eventType, payload);
70
+ }
71
+ }
72
+ });
23
73
  }
24
74
  async handleEvent(event, payload) {
25
- const repoName = payload.repository?.full_name;
26
- if (!repoName)
75
+ // FORCE LOG for debugging
76
+ this.ctx.logger('githubsth').info(`Received event: ${event}`);
77
+ // Check if payload is nested in an 'event' object (common in some adapter versions)
78
+ // or if the event data is directly in payload
79
+ const realPayload = payload.payload || payload;
80
+ let repoName = realPayload.repository?.full_name;
81
+ // Try to fallback if repoName is missing
82
+ if (!repoName && realPayload.issue?.repository_url) {
83
+ const parts = realPayload.issue.repository_url.split('/');
84
+ if (parts.length >= 2) {
85
+ repoName = `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
86
+ }
87
+ }
88
+ if (!repoName && realPayload.pull_request?.base?.repo?.full_name) {
89
+ repoName = realPayload.pull_request.base.repo.full_name;
90
+ }
91
+ if (!repoName) {
92
+ this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
93
+ if (this.config.debug) {
94
+ this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(realPayload).join(', ')}`);
95
+ }
27
96
  return;
97
+ }
98
+ this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
28
99
  if (this.config.debug) {
29
100
  this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
30
- this.ctx.logger('notifier').debug(JSON.stringify(payload, null, 2));
101
+ this.ctx.logger('notifier').debug(JSON.stringify(realPayload, null, 2));
31
102
  }
32
103
  // Get rules from database
33
104
  const dbRules = await this.ctx.database.get('github_subscription', {
@@ -46,50 +117,52 @@ class Notifier extends koishi_1.Service {
46
117
  return true;
47
118
  });
48
119
  if (matchedRules.length === 0) {
120
+ this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
49
121
  if (this.config.debug) {
50
122
  this.ctx.logger('notifier').debug(`No matching rules for ${repoName} (event: ${event})`);
51
123
  }
52
124
  return;
53
125
  }
126
+ this.ctx.logger('githubsth').info(`Found ${matchedRules.length} matching rules for ${repoName}`);
54
127
  if (this.config.debug) {
55
128
  this.ctx.logger('notifier').debug(`Found ${matchedRules.length} matching rules for ${repoName}`);
56
129
  }
57
130
  let message = null;
58
131
  // Ensure formatter is loaded
59
- if (!this.ctx.formatter) {
132
+ if (!this.ctx.githubsthFormatter) {
60
133
  this.ctx.logger('notifier').warn('Formatter service not available');
61
134
  return;
62
135
  }
63
136
  switch (event) {
64
137
  case 'push':
65
- message = this.ctx.formatter.formatPush(payload);
138
+ message = this.ctx.githubsthFormatter.formatPush(realPayload);
66
139
  break;
67
140
  case 'issues':
68
- message = this.ctx.formatter.formatIssue(payload);
141
+ message = this.ctx.githubsthFormatter.formatIssue(realPayload);
69
142
  break;
70
143
  case 'pull_request':
71
- message = this.ctx.formatter.formatPullRequest(payload);
144
+ message = this.ctx.githubsthFormatter.formatPullRequest(realPayload);
72
145
  break;
73
146
  case 'star':
74
- message = this.ctx.formatter.formatStar(payload);
147
+ message = this.ctx.githubsthFormatter.formatStar(realPayload);
75
148
  break;
76
149
  case 'fork':
77
- message = this.ctx.formatter.formatFork(payload);
150
+ message = this.ctx.githubsthFormatter.formatFork(realPayload);
78
151
  break;
79
152
  case 'release':
80
- message = this.ctx.formatter.formatRelease(payload);
153
+ message = this.ctx.githubsthFormatter.formatRelease(realPayload);
81
154
  break;
82
155
  case 'discussion':
83
- message = this.ctx.formatter.formatDiscussion(payload);
156
+ message = this.ctx.githubsthFormatter.formatDiscussion(realPayload);
84
157
  break;
85
158
  case 'workflow_run':
86
- message = this.ctx.formatter.formatWorkflowRun(payload);
159
+ message = this.ctx.githubsthFormatter.formatWorkflowRun(realPayload);
87
160
  break;
88
161
  case 'issue_comment':
89
- message = this.ctx.formatter.formatIssueComment(payload);
162
+ message = this.ctx.githubsthFormatter.formatIssueComment(realPayload);
90
163
  break;
91
164
  case 'pull_request_review':
92
- message = this.ctx.formatter.formatPullRequestReview(payload);
165
+ message = this.ctx.githubsthFormatter.formatPullRequestReview(realPayload);
93
166
  break;
94
167
  }
95
168
  if (!message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-githubsth",
3
- "version": "1.0.1-test1",
3
+ "version": "1.0.1-test10",
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,10 +39,11 @@
39
39
  },
40
40
  "service": {
41
41
  "required": [
42
- "database",
43
- "github"
42
+ "database"
44
43
  ],
45
- "optional": []
44
+ "optional": [
45
+ "github"
46
+ ]
46
47
  }
47
48
  }
48
49
  }