koishi-plugin-githubsth 1.0.1-test7 → 1.0.1-test9
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/services/notifier.js +66 -19
- package/package.json +1 -1
package/lib/services/notifier.js
CHANGED
|
@@ -23,34 +23,81 @@ 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 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.
|
|
42
|
+
const payload = session.payload || session.extra || session.data;
|
|
43
|
+
if (payload) {
|
|
44
|
+
this.ctx.logger('githubsth').info('Found payload in session, attempting to handle');
|
|
45
|
+
// Infer event type
|
|
46
|
+
let eventType = 'unknown';
|
|
47
|
+
if (payload.issue && payload.comment)
|
|
48
|
+
eventType = 'issue_comment';
|
|
49
|
+
else if (payload.issue)
|
|
50
|
+
eventType = 'issues';
|
|
51
|
+
else if (payload.pull_request && payload.review)
|
|
52
|
+
eventType = 'pull_request_review';
|
|
53
|
+
else if (payload.pull_request)
|
|
54
|
+
eventType = 'pull_request';
|
|
55
|
+
else if (payload.commits)
|
|
56
|
+
eventType = 'push';
|
|
57
|
+
else if (payload.starred_at !== undefined || (payload.action === 'started'))
|
|
58
|
+
eventType = 'star'; // star event usually has action 'created' but check payload structure
|
|
59
|
+
else if (payload.forkee)
|
|
60
|
+
eventType = 'fork';
|
|
61
|
+
else if (payload.release)
|
|
62
|
+
eventType = 'release';
|
|
63
|
+
else if (payload.discussion)
|
|
64
|
+
eventType = 'discussion';
|
|
65
|
+
else if (payload.workflow_run)
|
|
66
|
+
eventType = 'workflow_run';
|
|
67
|
+
if (eventType !== 'unknown') {
|
|
68
|
+
this.handleEvent(eventType, payload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
28
72
|
}
|
|
29
73
|
async handleEvent(event, payload) {
|
|
30
74
|
// FORCE LOG for debugging
|
|
31
75
|
this.ctx.logger('githubsth').info(`Received event: ${event}`);
|
|
32
|
-
|
|
76
|
+
// Check if payload is nested in an 'event' object (common in some adapter versions)
|
|
77
|
+
// or if the event data is directly in payload
|
|
78
|
+
const realPayload = payload.payload || payload;
|
|
79
|
+
let repoName = realPayload.repository?.full_name;
|
|
33
80
|
// Try to fallback if repoName is missing
|
|
34
|
-
if (!repoName &&
|
|
35
|
-
const parts =
|
|
81
|
+
if (!repoName && realPayload.issue?.repository_url) {
|
|
82
|
+
const parts = realPayload.issue.repository_url.split('/');
|
|
36
83
|
if (parts.length >= 2) {
|
|
37
84
|
repoName = `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
|
|
38
85
|
}
|
|
39
86
|
}
|
|
40
|
-
if (!repoName &&
|
|
41
|
-
repoName =
|
|
87
|
+
if (!repoName && realPayload.pull_request?.base?.repo?.full_name) {
|
|
88
|
+
repoName = realPayload.pull_request.base.repo.full_name;
|
|
42
89
|
}
|
|
43
90
|
if (!repoName) {
|
|
44
91
|
this.ctx.logger('githubsth').warn(`Missing repo info for event: ${event}`);
|
|
45
92
|
if (this.config.debug) {
|
|
46
|
-
this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(
|
|
93
|
+
this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(realPayload).join(', ')}`);
|
|
47
94
|
}
|
|
48
95
|
return;
|
|
49
96
|
}
|
|
50
97
|
this.ctx.logger('githubsth').info(`Processing event ${event} for ${repoName}`);
|
|
51
98
|
if (this.config.debug) {
|
|
52
99
|
this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
|
|
53
|
-
this.ctx.logger('notifier').debug(JSON.stringify(
|
|
100
|
+
this.ctx.logger('notifier').debug(JSON.stringify(realPayload, null, 2));
|
|
54
101
|
}
|
|
55
102
|
// Get rules from database
|
|
56
103
|
const dbRules = await this.ctx.database.get('github_subscription', {
|
|
@@ -69,7 +116,7 @@ class Notifier extends koishi_1.Service {
|
|
|
69
116
|
return true;
|
|
70
117
|
});
|
|
71
118
|
if (matchedRules.length === 0) {
|
|
72
|
-
this.ctx.logger('githubsth').info(`No matching rules for ${repoName}`);
|
|
119
|
+
this.ctx.logger('githubsth').info(`No matching rules for ${repoName} (event: ${event})`);
|
|
73
120
|
if (this.config.debug) {
|
|
74
121
|
this.ctx.logger('notifier').debug(`No matching rules for ${repoName} (event: ${event})`);
|
|
75
122
|
}
|
|
@@ -87,34 +134,34 @@ class Notifier extends koishi_1.Service {
|
|
|
87
134
|
}
|
|
88
135
|
switch (event) {
|
|
89
136
|
case 'push':
|
|
90
|
-
message = this.ctx.githubsthFormatter.formatPush(
|
|
137
|
+
message = this.ctx.githubsthFormatter.formatPush(realPayload);
|
|
91
138
|
break;
|
|
92
139
|
case 'issues':
|
|
93
|
-
message = this.ctx.githubsthFormatter.formatIssue(
|
|
140
|
+
message = this.ctx.githubsthFormatter.formatIssue(realPayload);
|
|
94
141
|
break;
|
|
95
142
|
case 'pull_request':
|
|
96
|
-
message = this.ctx.githubsthFormatter.formatPullRequest(
|
|
143
|
+
message = this.ctx.githubsthFormatter.formatPullRequest(realPayload);
|
|
97
144
|
break;
|
|
98
145
|
case 'star':
|
|
99
|
-
message = this.ctx.githubsthFormatter.formatStar(
|
|
146
|
+
message = this.ctx.githubsthFormatter.formatStar(realPayload);
|
|
100
147
|
break;
|
|
101
148
|
case 'fork':
|
|
102
|
-
message = this.ctx.githubsthFormatter.formatFork(
|
|
149
|
+
message = this.ctx.githubsthFormatter.formatFork(realPayload);
|
|
103
150
|
break;
|
|
104
151
|
case 'release':
|
|
105
|
-
message = this.ctx.githubsthFormatter.formatRelease(
|
|
152
|
+
message = this.ctx.githubsthFormatter.formatRelease(realPayload);
|
|
106
153
|
break;
|
|
107
154
|
case 'discussion':
|
|
108
|
-
message = this.ctx.githubsthFormatter.formatDiscussion(
|
|
155
|
+
message = this.ctx.githubsthFormatter.formatDiscussion(realPayload);
|
|
109
156
|
break;
|
|
110
157
|
case 'workflow_run':
|
|
111
|
-
message = this.ctx.githubsthFormatter.formatWorkflowRun(
|
|
158
|
+
message = this.ctx.githubsthFormatter.formatWorkflowRun(realPayload);
|
|
112
159
|
break;
|
|
113
160
|
case 'issue_comment':
|
|
114
|
-
message = this.ctx.githubsthFormatter.formatIssueComment(
|
|
161
|
+
message = this.ctx.githubsthFormatter.formatIssueComment(realPayload);
|
|
115
162
|
break;
|
|
116
163
|
case 'pull_request_review':
|
|
117
|
-
message = this.ctx.githubsthFormatter.formatPullRequestReview(
|
|
164
|
+
message = this.ctx.githubsthFormatter.formatPullRequestReview(realPayload);
|
|
118
165
|
break;
|
|
119
166
|
}
|
|
120
167
|
if (!message) {
|
package/package.json
CHANGED