koishi-plugin-githubsth 1.0.1-test1 → 1.0.1-test3

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.
@@ -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,7 @@ 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
8
  }
9
9
  formatPush(payload) {
10
10
  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,7 +5,7 @@ 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
10
  this.registerListeners();
11
11
  }
@@ -22,9 +22,23 @@ class Notifier extends koishi_1.Service {
22
22
  this.ctx.on('github/pull_request_review', (payload) => this.handleEvent('pull_request_review', payload));
23
23
  }
24
24
  async handleEvent(event, payload) {
25
- const repoName = payload.repository?.full_name;
26
- if (!repoName)
25
+ let repoName = payload.repository?.full_name;
26
+ // Try to fallback if repoName is missing
27
+ if (!repoName && payload.issue?.repository_url) {
28
+ const parts = payload.issue.repository_url.split('/');
29
+ if (parts.length >= 2) {
30
+ repoName = `${parts[parts.length - 2]}/${parts[parts.length - 1]}`;
31
+ }
32
+ }
33
+ if (!repoName && payload.pull_request?.base?.repo?.full_name) {
34
+ repoName = payload.pull_request.base.repo.full_name;
35
+ }
36
+ if (!repoName) {
37
+ if (this.config.debug) {
38
+ this.ctx.logger('notifier').warn(`Event ${event} missing repository info. Keys: ${Object.keys(payload).join(', ')}`);
39
+ }
27
40
  return;
41
+ }
28
42
  if (this.config.debug) {
29
43
  this.ctx.logger('notifier').info(`Received event ${event} for ${repoName}`);
30
44
  this.ctx.logger('notifier').debug(JSON.stringify(payload, null, 2));
@@ -56,40 +70,40 @@ class Notifier extends koishi_1.Service {
56
70
  }
57
71
  let message = null;
58
72
  // Ensure formatter is loaded
59
- if (!this.ctx.formatter) {
73
+ if (!this.ctx.githubsthFormatter) {
60
74
  this.ctx.logger('notifier').warn('Formatter service not available');
61
75
  return;
62
76
  }
63
77
  switch (event) {
64
78
  case 'push':
65
- message = this.ctx.formatter.formatPush(payload);
79
+ message = this.ctx.githubsthFormatter.formatPush(payload);
66
80
  break;
67
81
  case 'issues':
68
- message = this.ctx.formatter.formatIssue(payload);
82
+ message = this.ctx.githubsthFormatter.formatIssue(payload);
69
83
  break;
70
84
  case 'pull_request':
71
- message = this.ctx.formatter.formatPullRequest(payload);
85
+ message = this.ctx.githubsthFormatter.formatPullRequest(payload);
72
86
  break;
73
87
  case 'star':
74
- message = this.ctx.formatter.formatStar(payload);
88
+ message = this.ctx.githubsthFormatter.formatStar(payload);
75
89
  break;
76
90
  case 'fork':
77
- message = this.ctx.formatter.formatFork(payload);
91
+ message = this.ctx.githubsthFormatter.formatFork(payload);
78
92
  break;
79
93
  case 'release':
80
- message = this.ctx.formatter.formatRelease(payload);
94
+ message = this.ctx.githubsthFormatter.formatRelease(payload);
81
95
  break;
82
96
  case 'discussion':
83
- message = this.ctx.formatter.formatDiscussion(payload);
97
+ message = this.ctx.githubsthFormatter.formatDiscussion(payload);
84
98
  break;
85
99
  case 'workflow_run':
86
- message = this.ctx.formatter.formatWorkflowRun(payload);
100
+ message = this.ctx.githubsthFormatter.formatWorkflowRun(payload);
87
101
  break;
88
102
  case 'issue_comment':
89
- message = this.ctx.formatter.formatIssueComment(payload);
103
+ message = this.ctx.githubsthFormatter.formatIssueComment(payload);
90
104
  break;
91
105
  case 'pull_request_review':
92
- message = this.ctx.formatter.formatPullRequestReview(payload);
106
+ message = this.ctx.githubsthFormatter.formatPullRequestReview(payload);
93
107
  break;
94
108
  }
95
109
  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-test3",
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
  }