koishi-plugin-githubsth 1.0.1-test8 → 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 +2 -23
- package/lib/services/notifier.js +59 -9
- package/package.json +1 -1
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
|
|
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(
|
|
68
|
+
ctx.plugin(commands_1.apply, config);
|
|
90
69
|
logger.info('Plugin loaded successfully');
|
|
91
70
|
}
|
|
92
71
|
catch (e) {
|
package/lib/services/notifier.js
CHANGED
|
@@ -23,12 +23,49 @@ class Notifier extends koishi_1.Service {
|
|
|
23
23
|
this.ctx.on('github/workflow-run', (payload) => this.handleEvent('workflow_run', payload));
|
|
24
24
|
this.ctx.on('github/issue_comment', (payload) => this.handleEvent('issue_comment', payload));
|
|
25
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
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
|
+
// Try to find payload
|
|
32
|
+
const payload = session.payload || session.extra || session.data;
|
|
33
|
+
if (payload) {
|
|
34
|
+
if (this.config.debug) {
|
|
35
|
+
this.ctx.logger('githubsth').info('Found payload in session, attempting to handle');
|
|
36
|
+
}
|
|
37
|
+
// Infer event type
|
|
38
|
+
let eventType = 'unknown';
|
|
39
|
+
if (payload.issue && payload.comment)
|
|
40
|
+
eventType = 'issue_comment';
|
|
41
|
+
else if (payload.issue)
|
|
42
|
+
eventType = 'issues';
|
|
43
|
+
else if (payload.pull_request && payload.review)
|
|
44
|
+
eventType = 'pull_request_review';
|
|
45
|
+
else if (payload.pull_request)
|
|
46
|
+
eventType = 'pull_request';
|
|
47
|
+
else if (payload.commits)
|
|
48
|
+
eventType = 'push';
|
|
49
|
+
else if (payload.starred_at !== undefined || (payload.action === 'started'))
|
|
50
|
+
eventType = 'star'; // star event usually has action 'created' but check payload structure
|
|
51
|
+
else if (payload.forkee)
|
|
52
|
+
eventType = 'fork';
|
|
53
|
+
else if (payload.release)
|
|
54
|
+
eventType = 'release';
|
|
55
|
+
else if (payload.discussion)
|
|
56
|
+
eventType = 'discussion';
|
|
57
|
+
else if (payload.workflow_run)
|
|
58
|
+
eventType = 'workflow_run';
|
|
59
|
+
if (eventType !== 'unknown') {
|
|
60
|
+
this.handleEvent(eventType, payload);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
28
64
|
}
|
|
29
65
|
async handleEvent(event, payload) {
|
|
30
|
-
|
|
31
|
-
|
|
66
|
+
if (this.config.debug) {
|
|
67
|
+
this.ctx.logger('githubsth').info(`Received event: ${event}`);
|
|
68
|
+
}
|
|
32
69
|
// Check if payload is nested in an 'event' object (common in some adapter versions)
|
|
33
70
|
// or if the event data is directly in payload
|
|
34
71
|
const realPayload = payload.payload || payload;
|
|
@@ -44,23 +81,36 @@ class Notifier extends koishi_1.Service {
|
|
|
44
81
|
repoName = realPayload.pull_request.base.repo.full_name;
|
|
45
82
|
}
|
|
46
83
|
if (!repoName) {
|
|
47
|
-
this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
|
|
48
84
|
if (this.config.debug) {
|
|
85
|
+
this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
|
|
49
86
|
this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(realPayload).join(', ')}`);
|
|
50
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
|
+
}
|
|
51
93
|
return;
|
|
52
94
|
}
|
|
53
|
-
this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
|
|
54
95
|
if (this.config.debug) {
|
|
96
|
+
this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
|
|
55
97
|
this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
|
|
56
98
|
this.ctx.logger('notifier').debug(JSON.stringify(realPayload, null, 2));
|
|
57
99
|
}
|
|
58
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
|
+
}
|
|
59
106
|
const dbRules = await this.ctx.database.get('github_subscription', {
|
|
60
|
-
repo:
|
|
107
|
+
repo: repoNames
|
|
61
108
|
});
|
|
62
109
|
// Combine with config rules (if any, for backward compatibility or static rules)
|
|
63
|
-
|
|
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 === '*');
|
|
64
114
|
const allRules = [
|
|
65
115
|
...dbRules.map(r => ({ ...r, platform: r.platform })),
|
|
66
116
|
...configRules
|
|
@@ -72,14 +122,14 @@ class Notifier extends koishi_1.Service {
|
|
|
72
122
|
return true;
|
|
73
123
|
});
|
|
74
124
|
if (matchedRules.length === 0) {
|
|
75
|
-
this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
|
|
76
125
|
if (this.config.debug) {
|
|
126
|
+
this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
|
|
77
127
|
this.ctx.logger('notifier').debug(`No matching rules for ${repoName} (event: ${event})`);
|
|
78
128
|
}
|
|
79
129
|
return;
|
|
80
130
|
}
|
|
81
|
-
this.ctx.logger('githubsth').info(`Found ${matchedRules.length} matching rules for ${repoName}`);
|
|
82
131
|
if (this.config.debug) {
|
|
132
|
+
this.ctx.logger('githubsth').info(`Found ${matchedRules.length} matching rules for ${repoName}`);
|
|
83
133
|
this.ctx.logger('notifier').debug(`Found ${matchedRules.length} matching rules for ${repoName}`);
|
|
84
134
|
}
|
|
85
135
|
let message = null;
|
package/package.json
CHANGED