koishi-plugin-githubsth 1.0.1-test6 → 1.0.1-test8
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 +12 -0
- package/lib/services/notifier.js +21 -18
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -71,6 +71,18 @@ function apply(ctx, config) {
|
|
|
71
71
|
ctx.on('github/opened', (payload) => {
|
|
72
72
|
logger.info('[DEBUG] Global listener caught github/opened');
|
|
73
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
|
+
});
|
|
74
86
|
// 注册命令
|
|
75
87
|
// admin and subscribe are already loaded in commands/index.ts, remove duplicate loading here
|
|
76
88
|
try {
|
package/lib/services/notifier.js
CHANGED
|
@@ -29,28 +29,31 @@ class Notifier extends koishi_1.Service {
|
|
|
29
29
|
async handleEvent(event, payload) {
|
|
30
30
|
// FORCE LOG for debugging
|
|
31
31
|
this.ctx.logger('githubsth').info(`Received event: ${event}`);
|
|
32
|
-
|
|
32
|
+
// Check if payload is nested in an 'event' object (common in some adapter versions)
|
|
33
|
+
// or if the event data is directly in payload
|
|
34
|
+
const realPayload = payload.payload || payload;
|
|
35
|
+
let repoName = realPayload.repository?.full_name;
|
|
33
36
|
// Try to fallback if repoName is missing
|
|
34
|
-
if (!repoName &&
|
|
35
|
-
const parts =
|
|
37
|
+
if (!repoName && realPayload.issue?.repository_url) {
|
|
38
|
+
const parts = realPayload.issue.repository_url.split('/');
|
|
36
39
|
if (parts.length >= 2) {
|
|
37
40
|
repoName = `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
if (!repoName &&
|
|
41
|
-
repoName =
|
|
43
|
+
if (!repoName && realPayload.pull_request?.base?.repo?.full_name) {
|
|
44
|
+
repoName = realPayload.pull_request.base.repo.full_name;
|
|
42
45
|
}
|
|
43
46
|
if (!repoName) {
|
|
44
47
|
this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
|
|
45
48
|
if (this.config.debug) {
|
|
46
|
-
this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(
|
|
49
|
+
this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(realPayload).join(', ')}`);
|
|
47
50
|
}
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
50
53
|
this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
|
|
51
54
|
if (this.config.debug) {
|
|
52
55
|
this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
|
|
53
|
-
this.ctx.logger('notifier').debug(JSON.stringify(
|
|
56
|
+
this.ctx.logger('notifier').debug(JSON.stringify(realPayload, null, 2));
|
|
54
57
|
}
|
|
55
58
|
// Get rules from database
|
|
56
59
|
const dbRules = await this.ctx.database.get('github_subscription', {
|
|
@@ -69,7 +72,7 @@ class Notifier extends koishi_1.Service {
|
|
|
69
72
|
return true;
|
|
70
73
|
});
|
|
71
74
|
if (matchedRules.length === 0) {
|
|
72
|
-
this.ctx.logger('githubsth').info(`No matching rules for ${repoName}`);
|
|
75
|
+
this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
|
|
73
76
|
if (this.config.debug) {
|
|
74
77
|
this.ctx.logger('notifier').debug(`No matching rules for ${repoName} (event: ${event})`);
|
|
75
78
|
}
|
|
@@ -87,34 +90,34 @@ class Notifier extends koishi_1.Service {
|
|
|
87
90
|
}
|
|
88
91
|
switch (event) {
|
|
89
92
|
case 'push':
|
|
90
|
-
message = this.ctx.githubsthFormatter.formatPush(
|
|
93
|
+
message = this.ctx.githubsthFormatter.formatPush(realPayload);
|
|
91
94
|
break;
|
|
92
95
|
case 'issues':
|
|
93
|
-
message = this.ctx.githubsthFormatter.formatIssue(
|
|
96
|
+
message = this.ctx.githubsthFormatter.formatIssue(realPayload);
|
|
94
97
|
break;
|
|
95
98
|
case 'pull_request':
|
|
96
|
-
message = this.ctx.githubsthFormatter.formatPullRequest(
|
|
99
|
+
message = this.ctx.githubsthFormatter.formatPullRequest(realPayload);
|
|
97
100
|
break;
|
|
98
101
|
case 'star':
|
|
99
|
-
message = this.ctx.githubsthFormatter.formatStar(
|
|
102
|
+
message = this.ctx.githubsthFormatter.formatStar(realPayload);
|
|
100
103
|
break;
|
|
101
104
|
case 'fork':
|
|
102
|
-
message = this.ctx.githubsthFormatter.formatFork(
|
|
105
|
+
message = this.ctx.githubsthFormatter.formatFork(realPayload);
|
|
103
106
|
break;
|
|
104
107
|
case 'release':
|
|
105
|
-
message = this.ctx.githubsthFormatter.formatRelease(
|
|
108
|
+
message = this.ctx.githubsthFormatter.formatRelease(realPayload);
|
|
106
109
|
break;
|
|
107
110
|
case 'discussion':
|
|
108
|
-
message = this.ctx.githubsthFormatter.formatDiscussion(
|
|
111
|
+
message = this.ctx.githubsthFormatter.formatDiscussion(realPayload);
|
|
109
112
|
break;
|
|
110
113
|
case 'workflow_run':
|
|
111
|
-
message = this.ctx.githubsthFormatter.formatWorkflowRun(
|
|
114
|
+
message = this.ctx.githubsthFormatter.formatWorkflowRun(realPayload);
|
|
112
115
|
break;
|
|
113
116
|
case 'issue_comment':
|
|
114
|
-
message = this.ctx.githubsthFormatter.formatIssueComment(
|
|
117
|
+
message = this.ctx.githubsthFormatter.formatIssueComment(realPayload);
|
|
115
118
|
break;
|
|
116
119
|
case 'pull_request_review':
|
|
117
|
-
message = this.ctx.githubsthFormatter.formatPullRequestReview(
|
|
120
|
+
message = this.ctx.githubsthFormatter.formatPullRequestReview(realPayload);
|
|
118
121
|
break;
|
|
119
122
|
}
|
|
120
123
|
if (!message) {
|
package/package.json
CHANGED