koishi-plugin-githubsth 1.0.1-test9 → 1.0.2-test1

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
@@ -41,7 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.inject = exports.name = void 0;
43
43
  exports.apply = apply;
44
- const commands = __importStar(require("./commands"));
44
+ const commands_1 = require("./commands");
45
45
  const database = __importStar(require("./database"));
46
46
  const zh_CN_1 = __importDefault(require("./locales/zh-CN"));
47
47
  const notifier_1 = require("./services/notifier");
@@ -60,33 +60,12 @@ function apply(ctx, config) {
60
60
  // 数据库
61
61
  ctx.plugin(database);
62
62
  // 注册服务
63
- logger.info('Registering Formatter...');
64
63
  ctx.plugin(formatter_1.Formatter);
65
- logger.info('Registering Notifier...');
66
64
  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
- });
86
65
  // 注册命令
87
66
  // admin and subscribe are already loaded in commands/index.ts, remove duplicate loading here
88
67
  try {
89
- ctx.plugin(commands, config);
68
+ ctx.plugin(commands_1.apply, config);
90
69
  logger.info('Plugin loaded successfully');
91
70
  }
92
71
  catch (e) {
@@ -28,20 +28,12 @@ class Notifier extends koishi_1.Service {
28
28
  this.ctx.on('message-created', (session) => {
29
29
  if (session.platform !== 'github')
30
30
  return;
31
- // Try to find raw payload in session
32
- // adapter-github might put it in session.content (parsed) or some extra field
33
- // We'll try to find the raw JSON.
34
- // Based on common adapter patterns, it might be in session.event._data or similar if it's a raw event wrapped
35
- // But for message-created, session IS the event wrapper.
36
- // Let's inspect the session for debugging first
37
- if (this.config.debug) {
38
- this.ctx.logger('githubsth').info(`[Debug] Message session keys: ${Object.keys(session).join(', ')}`);
39
- }
40
- // If we can't find the payload easily, we might need to rely on the adapter emitting proper events.
41
- // But since we are here, let's try to see if 'payload' or 'extra' exists.
31
+ // Try to find payload
42
32
  const payload = session.payload || session.extra || session.data;
43
33
  if (payload) {
44
- this.ctx.logger('githubsth').info('Found payload in session, attempting to handle');
34
+ if (this.config.debug) {
35
+ this.ctx.logger('githubsth').info('Found payload in session, attempting to handle');
36
+ }
45
37
  // Infer event type
46
38
  let eventType = 'unknown';
47
39
  if (payload.issue && payload.comment)
@@ -71,8 +63,9 @@ class Notifier extends koishi_1.Service {
71
63
  });
72
64
  }
73
65
  async handleEvent(event, payload) {
74
- // FORCE LOG for debugging
75
- this.ctx.logger('githubsth').info(`Received event: ${event}`);
66
+ if (this.config.debug) {
67
+ this.ctx.logger('githubsth').info(`Received event: ${event}`);
68
+ }
76
69
  // Check if payload is nested in an 'event' object (common in some adapter versions)
77
70
  // or if the event data is directly in payload
78
71
  const realPayload = payload.payload || payload;
@@ -88,23 +81,36 @@ class Notifier extends koishi_1.Service {
88
81
  repoName = realPayload.pull_request.base.repo.full_name;
89
82
  }
90
83
  if (!repoName) {
91
- this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
92
84
  if (this.config.debug) {
85
+ this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
93
86
  this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(realPayload).join(', ')}`);
94
87
  }
88
+ else {
89
+ // Log at warning level even in production if repo info is missing, as this is a critical failure
90
+ // But only log keys to avoid leaking sensitive data
91
+ this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}. Keys: ${Object.keys(realPayload).join(', ')}`);
92
+ }
95
93
  return;
96
94
  }
97
- this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
98
95
  if (this.config.debug) {
96
+ this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
99
97
  this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
100
98
  this.ctx.logger('notifier').debug(JSON.stringify(realPayload, null, 2));
101
99
  }
102
100
  // Get rules from database
101
+ // Try to match both exact name and lowercase name to handle case sensitivity
102
+ const repoNames = [repoName];
103
+ if (repoName !== repoName.toLowerCase()) {
104
+ repoNames.push(repoName.toLowerCase());
105
+ }
103
106
  const dbRules = await this.ctx.database.get('github_subscription', {
104
- repo: repoName
107
+ repo: repoNames
105
108
  });
106
109
  // Combine with config rules (if any, for backward compatibility or static rules)
107
- const configRules = (this.config.rules || []).filter((r) => r.repo === repoName || r.repo === '*');
110
+ // Also match config rules case-insensitively if needed
111
+ const configRules = (this.config.rules || []).filter((r) => r.repo === repoName ||
112
+ r.repo === repoName.toLowerCase() ||
113
+ r.repo === '*');
108
114
  const allRules = [
109
115
  ...dbRules.map(r => ({ ...r, platform: r.platform })),
110
116
  ...configRules
@@ -116,14 +122,14 @@ class Notifier extends koishi_1.Service {
116
122
  return true;
117
123
  });
118
124
  if (matchedRules.length === 0) {
119
- this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
120
125
  if (this.config.debug) {
126
+ this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
121
127
  this.ctx.logger('notifier').debug(`No matching rules for ${repoName} (event: ${event})`);
122
128
  }
123
129
  return;
124
130
  }
125
- this.ctx.logger('githubsth').info(`Found ${matchedRules.length} matching rules for ${repoName}`);
126
131
  if (this.config.debug) {
132
+ this.ctx.logger('githubsth').info(`Found ${matchedRules.length} matching rules for ${repoName}`);
127
133
  this.ctx.logger('notifier').debug(`Found ${matchedRules.length} matching rules for ${repoName}`);
128
134
  }
129
135
  let message = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-githubsth",
3
- "version": "1.0.1-test9",
3
+ "version": "1.0.2-test1",
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",