koishi-plugin-github-webhook-pusher 0.0.6 → 0.0.7
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/commands/index.d.ts +6 -0
- package/lib/commands/subscription.d.ts +12 -0
- package/lib/commands/trust.d.ts +10 -0
- package/lib/commands/utils.d.ts +12 -0
- package/lib/config.d.ts +20 -0
- package/lib/database.d.ts +35 -0
- package/lib/index.d.ts +18 -0
- package/lib/message.d.ts +12 -0
- package/lib/parser.d.ts +65 -0
- package/lib/pusher.d.ts +55 -0
- package/lib/repository/delivery.d.ts +38 -0
- package/lib/repository/index.d.ts +6 -0
- package/lib/repository/subscription.d.ts +99 -0
- package/lib/repository/trust.d.ts +73 -0
- package/lib/signature.d.ts +15 -0
- package/lib/types.d.ts +49 -0
- package/lib/webhook.d.ts +21 -0
- package/package.json +5 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 订阅管理命令
|
|
3
|
+
* 需求: 3.1-3.7
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { Config } from '../config';
|
|
7
|
+
/**
|
|
8
|
+
* 注册订阅管理命令
|
|
9
|
+
* @param ctx Koishi 上下文
|
|
10
|
+
* @param config 插件配置
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerSubscriptionCommands(ctx: Context, config: Config): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具命令
|
|
3
|
+
* 需求: 8.1, 8.2
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { Config } from '../config';
|
|
7
|
+
/**
|
|
8
|
+
* 注册工具命令
|
|
9
|
+
* @param ctx Koishi 上下文
|
|
10
|
+
* @param config 插件配置
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerUtilCommands(ctx: Context, config: Config): void;
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from 'koishi';
|
|
2
|
+
import { EventType } from './types';
|
|
3
|
+
export { EventType };
|
|
4
|
+
export interface Config {
|
|
5
|
+
/** Webhook 接收路径 */
|
|
6
|
+
path: string;
|
|
7
|
+
/** GitHub Webhook Secret */
|
|
8
|
+
secret: string;
|
|
9
|
+
/** 显示用基础 URL */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** 默认订阅事件 */
|
|
12
|
+
defaultEvents: EventType[];
|
|
13
|
+
/** 调试模式 */
|
|
14
|
+
debug: boolean;
|
|
15
|
+
/** 允许非信任仓库 */
|
|
16
|
+
allowUntrusted: boolean;
|
|
17
|
+
/** 推送并发数 */
|
|
18
|
+
concurrency: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const Config: Schema<Config>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { EventType } from './types';
|
|
3
|
+
declare module 'koishi' {
|
|
4
|
+
interface Tables {
|
|
5
|
+
github_trusted_repos: TrustedRepo;
|
|
6
|
+
github_subscriptions: Subscription;
|
|
7
|
+
github_deliveries: Delivery;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export interface TrustedRepo {
|
|
11
|
+
id: number;
|
|
12
|
+
repo: string;
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
}
|
|
17
|
+
export interface Subscription {
|
|
18
|
+
id: number;
|
|
19
|
+
platform: string;
|
|
20
|
+
channelId: string;
|
|
21
|
+
guildId: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
repo: string;
|
|
24
|
+
events: EventType[];
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
createdAt: Date;
|
|
27
|
+
updatedAt: Date;
|
|
28
|
+
}
|
|
29
|
+
export interface Delivery {
|
|
30
|
+
deliveryId: string;
|
|
31
|
+
repo: string;
|
|
32
|
+
event: string;
|
|
33
|
+
receivedAt: Date;
|
|
34
|
+
}
|
|
35
|
+
export declare function extendDatabase(ctx: Context): void;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Koishi GitHub Webhook 推送插件入口
|
|
3
|
+
* 需求: 1.1, 7.1-7.7
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { Config } from './config';
|
|
7
|
+
/** 插件名称 */
|
|
8
|
+
export declare const name = "github-webhook-pusher";
|
|
9
|
+
/** 声明服务依赖 - 需要 server 服务提供 router 和 database 服务 */
|
|
10
|
+
export declare const inject: string[];
|
|
11
|
+
/** 导出配置 Schema */
|
|
12
|
+
export { Config };
|
|
13
|
+
/**
|
|
14
|
+
* 插件入口函数
|
|
15
|
+
* @param ctx Koishi 上下文
|
|
16
|
+
* @param config 插件配置
|
|
17
|
+
*/
|
|
18
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/message.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息构建器
|
|
3
|
+
* 需求: 5.3, 5.4, 5.5
|
|
4
|
+
*/
|
|
5
|
+
import { Element } from 'koishi';
|
|
6
|
+
import { ParsedEvent } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* 构建推送消息
|
|
9
|
+
* @param event 解析后的事件
|
|
10
|
+
* @returns Koishi Element 消息数组
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildMessage(event: ParsedEvent): Element[];
|
package/lib/parser.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Webhook 事件解析器
|
|
3
|
+
* 需求: 4.1-4.7
|
|
4
|
+
*/
|
|
5
|
+
import { ParsedEvent } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 解析 Issues 事件
|
|
8
|
+
* 需求 4.1: 提取 issue 标题、编号、操作者和链接
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseIssuesEvent(payload: any): ParsedEvent | null;
|
|
11
|
+
/**
|
|
12
|
+
* 解析 Issue Comment 事件
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseIssueCommentEvent(payload: any): ParsedEvent | null;
|
|
15
|
+
/**
|
|
16
|
+
* 解析 Release 事件
|
|
17
|
+
* 需求 4.2: 提取版本号、发布者和下载链接
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseReleaseEvent(payload: any): ParsedEvent | null;
|
|
20
|
+
/**
|
|
21
|
+
* 解析 Push 事件
|
|
22
|
+
* 需求 4.3, 4.6: 提取分支名、提交列表(最多5条)和推送者信息
|
|
23
|
+
*/
|
|
24
|
+
export declare function parsePushEvent(payload: any): ParsedEvent | null;
|
|
25
|
+
/**
|
|
26
|
+
* 解析 Pull Request 事件
|
|
27
|
+
* 需求 4.4: 提取 PR 标题、编号、操作者和链接
|
|
28
|
+
*/
|
|
29
|
+
export declare function parsePullRequestEvent(payload: any): ParsedEvent | null;
|
|
30
|
+
/**
|
|
31
|
+
* 解析 Pull Request Review 事件
|
|
32
|
+
*/
|
|
33
|
+
export declare function parsePullRequestReviewEvent(payload: any): ParsedEvent | null;
|
|
34
|
+
/**
|
|
35
|
+
* 解析 Pull Request Review Comment 事件
|
|
36
|
+
*/
|
|
37
|
+
export declare function parsePullRequestReviewCommentEvent(payload: any): ParsedEvent | null;
|
|
38
|
+
/**
|
|
39
|
+
* 解析 Star 事件
|
|
40
|
+
* 需求 4.5: 提取操作者和当前 star 数量
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseStarEvent(payload: any): ParsedEvent | null;
|
|
43
|
+
/**
|
|
44
|
+
* 解析 Fork 事件
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseForkEvent(payload: any): ParsedEvent | null;
|
|
47
|
+
/**
|
|
48
|
+
* 解析 Create 事件
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseCreateEvent(payload: any): ParsedEvent | null;
|
|
51
|
+
/**
|
|
52
|
+
* 解析 Delete 事件
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseDeleteEvent(payload: any): ParsedEvent | null;
|
|
55
|
+
/**
|
|
56
|
+
* 解析 Workflow Run 事件
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseWorkflowRunEvent(payload: any): ParsedEvent | null;
|
|
59
|
+
/**
|
|
60
|
+
* 统一的事件解析入口函数
|
|
61
|
+
* @param eventName X-GitHub-Event 头的值
|
|
62
|
+
* @param payload 解析后的 JSON 负载
|
|
63
|
+
* @returns 解析后的事件数据,不支持的事件返回 null
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseEvent(eventName: string, payload: any): ParsedEvent | null;
|
package/lib/pusher.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息推送器
|
|
3
|
+
* 需求: 5.1, 5.2, 5.6, 5.7
|
|
4
|
+
*/
|
|
5
|
+
import { Context, Element } from 'koishi';
|
|
6
|
+
import { EventType, ParsedEvent } from './types';
|
|
7
|
+
import { PushTarget } from './repository/subscription';
|
|
8
|
+
/** 推送结果 */
|
|
9
|
+
export interface PushResult {
|
|
10
|
+
target: PushTarget;
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: Error;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 查询订阅目标
|
|
16
|
+
* 需求 5.1: 查询所有订阅该仓库的目标会话
|
|
17
|
+
* 需求 5.2: 根据订阅的事件类型过滤目标
|
|
18
|
+
* @param ctx Koishi 上下文
|
|
19
|
+
* @param repo 仓库名 (owner/repo)
|
|
20
|
+
* @param eventType 事件类型
|
|
21
|
+
* @returns 推送目标列表
|
|
22
|
+
*/
|
|
23
|
+
export declare function queryTargets(ctx: Context, repo: string, eventType: EventType): Promise<PushTarget[]>;
|
|
24
|
+
/**
|
|
25
|
+
* 并发推送消息到多个目标
|
|
26
|
+
* 需求 5.6: 使用 Promise.allSettled 并发推送并限制并发数
|
|
27
|
+
* 需求 5.7: 推送失败记录错误日志但不影响其他目标的推送
|
|
28
|
+
* @param ctx Koishi 上下文
|
|
29
|
+
* @param targets 推送目标列表
|
|
30
|
+
* @param message 消息内容
|
|
31
|
+
* @param concurrency 并发数限制
|
|
32
|
+
* @returns 推送结果列表
|
|
33
|
+
*/
|
|
34
|
+
export declare function pushWithConcurrency(ctx: Context, targets: PushTarget[], message: Element[], concurrency: number): Promise<PushResult[]>;
|
|
35
|
+
/**
|
|
36
|
+
* 推送消息到所有订阅目标
|
|
37
|
+
* @param ctx Koishi 上下文
|
|
38
|
+
* @param event 解析后的事件
|
|
39
|
+
* @param concurrency 并发数限制
|
|
40
|
+
* @returns 推送结果列表
|
|
41
|
+
*/
|
|
42
|
+
export declare function pushMessage(ctx: Context, event: ParsedEvent, concurrency?: number): Promise<PushResult[]>;
|
|
43
|
+
/**
|
|
44
|
+
* 推送事件(完整流程)
|
|
45
|
+
* 整合事件解析、消息构建和推送
|
|
46
|
+
* @param ctx Koishi 上下文
|
|
47
|
+
* @param event 解析后的事件
|
|
48
|
+
* @param concurrency 并发数限制
|
|
49
|
+
* @returns 推送结果
|
|
50
|
+
*/
|
|
51
|
+
export declare function pushEvent(ctx: Context, event: ParsedEvent, concurrency?: number): Promise<{
|
|
52
|
+
pushed: number;
|
|
53
|
+
failed: number;
|
|
54
|
+
results: PushResult[];
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 投递记录数据访问层
|
|
3
|
+
* 需求: 1.6
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { Delivery } from '../database';
|
|
7
|
+
/**
|
|
8
|
+
* 记录投递
|
|
9
|
+
* 需求 1.6: 记录 Delivery ID 用于去重
|
|
10
|
+
* @param ctx Koishi 上下文
|
|
11
|
+
* @param deliveryId GitHub Delivery ID
|
|
12
|
+
* @param repo 仓库名 (owner/repo)
|
|
13
|
+
* @param event 事件类型
|
|
14
|
+
* @returns 创建的投递记录
|
|
15
|
+
*/
|
|
16
|
+
export declare function recordDelivery(ctx: Context, deliveryId: string, repo: string, event: string): Promise<Delivery>;
|
|
17
|
+
/**
|
|
18
|
+
* 检查是否已投递
|
|
19
|
+
* 需求 1.6: 检查 Delivery ID 是否已处理过,用于去重
|
|
20
|
+
* @param ctx Koishi 上下文
|
|
21
|
+
* @param deliveryId GitHub Delivery ID
|
|
22
|
+
* @returns 是否已投递
|
|
23
|
+
*/
|
|
24
|
+
export declare function isDelivered(ctx: Context, deliveryId: string): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取投递记录
|
|
27
|
+
* @param ctx Koishi 上下文
|
|
28
|
+
* @param deliveryId GitHub Delivery ID
|
|
29
|
+
* @returns 投递记录,不存在返回 null
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDelivery(ctx: Context, deliveryId: string): Promise<Delivery | null>;
|
|
32
|
+
/**
|
|
33
|
+
* 清理旧的投递记录
|
|
34
|
+
* @param ctx Koishi 上下文
|
|
35
|
+
* @param beforeDate 清理此日期之前的记录
|
|
36
|
+
* @returns 清理的记录数
|
|
37
|
+
*/
|
|
38
|
+
export declare function cleanupDeliveries(ctx: Context, beforeDate: Date): Promise<number>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 订阅数据访问层
|
|
3
|
+
* 需求: 3.1-3.7, 5.1, 5.2
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { Subscription } from '../database';
|
|
7
|
+
import { EventType } from '../types';
|
|
8
|
+
/** 推送目标信息 */
|
|
9
|
+
export interface PushTarget {
|
|
10
|
+
platform: string;
|
|
11
|
+
channelId: string;
|
|
12
|
+
guildId?: string;
|
|
13
|
+
userId?: string;
|
|
14
|
+
}
|
|
15
|
+
/** 会话标识 */
|
|
16
|
+
export interface SessionIdentifier {
|
|
17
|
+
platform: string;
|
|
18
|
+
channelId: string;
|
|
19
|
+
guildId?: string;
|
|
20
|
+
userId?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 创建订阅
|
|
24
|
+
* 需求 3.1: 为当前会话创建订阅记录
|
|
25
|
+
* @param ctx Koishi 上下文
|
|
26
|
+
* @param session 会话标识
|
|
27
|
+
* @param repo 仓库名 (owner/repo)
|
|
28
|
+
* @param defaultEvents 默认事件列表
|
|
29
|
+
* @returns 创建的订阅记录
|
|
30
|
+
*/
|
|
31
|
+
export declare function createSubscription(ctx: Context, session: SessionIdentifier, repo: string, defaultEvents: EventType[]): Promise<Subscription>;
|
|
32
|
+
/**
|
|
33
|
+
* 移除订阅
|
|
34
|
+
* 需求 3.3: 移除当前会话对该仓库的订阅
|
|
35
|
+
* @param ctx Koishi 上下文
|
|
36
|
+
* @param session 会话标识
|
|
37
|
+
* @param repo 仓库名 (owner/repo)
|
|
38
|
+
* @returns 是否成功移除
|
|
39
|
+
*/
|
|
40
|
+
export declare function removeSubscription(ctx: Context, session: SessionIdentifier, repo: string): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* 列出会话的所有订阅
|
|
43
|
+
* 需求 3.4: 显示当前会话的所有订阅及其事件设置
|
|
44
|
+
* @param ctx Koishi 上下文
|
|
45
|
+
* @param session 会话标识
|
|
46
|
+
* @returns 订阅列表
|
|
47
|
+
*/
|
|
48
|
+
export declare function listSubscriptions(ctx: Context, session: SessionIdentifier): Promise<Subscription[]>;
|
|
49
|
+
/**
|
|
50
|
+
* 获取单个订阅
|
|
51
|
+
* 需求 3.5: 显示该仓库订阅的事件类型列表
|
|
52
|
+
* @param ctx Koishi 上下文
|
|
53
|
+
* @param session 会话标识
|
|
54
|
+
* @param repo 仓库名 (owner/repo)
|
|
55
|
+
* @returns 订阅记录,不存在返回 null
|
|
56
|
+
*/
|
|
57
|
+
export declare function getSubscription(ctx: Context, session: SessionIdentifier, repo: string): Promise<Subscription | null>;
|
|
58
|
+
/**
|
|
59
|
+
* 更新订阅的事件类型
|
|
60
|
+
* 需求 3.6: 根据 +/- 前缀启用或禁用对应事件类型
|
|
61
|
+
* @param ctx Koishi 上下文
|
|
62
|
+
* @param session 会话标识
|
|
63
|
+
* @param repo 仓库名 (owner/repo)
|
|
64
|
+
* @param events 新的事件列表
|
|
65
|
+
* @returns 是否成功更新
|
|
66
|
+
*/
|
|
67
|
+
export declare function updateEvents(ctx: Context, session: SessionIdentifier, repo: string, events: EventType[]): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* 查询订阅目标
|
|
70
|
+
* 需求 5.1, 5.2: 查询所有订阅该仓库的目标会话,并根据事件类型过滤
|
|
71
|
+
* @param ctx Koishi 上下文
|
|
72
|
+
* @param repo 仓库名 (owner/repo)
|
|
73
|
+
* @param eventType 事件类型
|
|
74
|
+
* @returns 推送目标列表
|
|
75
|
+
*/
|
|
76
|
+
export declare function queryTargets(ctx: Context, repo: string, eventType: EventType): Promise<PushTarget[]>;
|
|
77
|
+
/**
|
|
78
|
+
* 获取仓库的所有订阅
|
|
79
|
+
* @param ctx Koishi 上下文
|
|
80
|
+
* @param repo 仓库名 (owner/repo)
|
|
81
|
+
* @returns 订阅列表
|
|
82
|
+
*/
|
|
83
|
+
export declare function getRepoSubscriptions(ctx: Context, repo: string): Promise<Subscription[]>;
|
|
84
|
+
/**
|
|
85
|
+
* 启用订阅
|
|
86
|
+
* @param ctx Koishi 上下文
|
|
87
|
+
* @param session 会话标识
|
|
88
|
+
* @param repo 仓库名 (owner/repo)
|
|
89
|
+
* @returns 是否成功启用
|
|
90
|
+
*/
|
|
91
|
+
export declare function enableSubscription(ctx: Context, session: SessionIdentifier, repo: string): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* 禁用订阅
|
|
94
|
+
* @param ctx Koishi 上下文
|
|
95
|
+
* @param session 会话标识
|
|
96
|
+
* @param repo 仓库名 (owner/repo)
|
|
97
|
+
* @returns 是否成功禁用
|
|
98
|
+
*/
|
|
99
|
+
export declare function disableSubscription(ctx: Context, session: SessionIdentifier, repo: string): Promise<boolean>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 信任仓库数据访问层
|
|
3
|
+
* 需求: 2.1-2.7
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import { TrustedRepo } from '../database';
|
|
7
|
+
/**
|
|
8
|
+
* 验证仓库名格式是否符合 owner/repo 格式
|
|
9
|
+
* @param repo 仓库名
|
|
10
|
+
* @returns 是否有效
|
|
11
|
+
*/
|
|
12
|
+
export declare function isValidRepoFormat(repo: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 添加信任仓库
|
|
15
|
+
* 需求 2.1: 将仓库添加到信任列表并持久化到数据库
|
|
16
|
+
* @param ctx Koishi 上下文
|
|
17
|
+
* @param repo 仓库名 (owner/repo)
|
|
18
|
+
* @returns 添加的仓库记录,如果格式错误返回 null
|
|
19
|
+
*/
|
|
20
|
+
export declare function addTrustedRepo(ctx: Context, repo: string): Promise<TrustedRepo | null>;
|
|
21
|
+
/**
|
|
22
|
+
* 移除信任仓库
|
|
23
|
+
* 需求 2.2: 从信任列表中移除该仓库
|
|
24
|
+
* @param ctx Koishi 上下文
|
|
25
|
+
* @param repo 仓库名 (owner/repo)
|
|
26
|
+
* @returns 是否成功移除
|
|
27
|
+
*/
|
|
28
|
+
export declare function removeTrustedRepo(ctx: Context, repo: string): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* 列出所有信任仓库
|
|
31
|
+
* 需求 2.3: 显示所有信任仓库及其启用状态
|
|
32
|
+
* @param ctx Koishi 上下文
|
|
33
|
+
* @returns 信任仓库列表
|
|
34
|
+
*/
|
|
35
|
+
export declare function listTrustedRepos(ctx: Context): Promise<TrustedRepo[]>;
|
|
36
|
+
/**
|
|
37
|
+
* 检查仓库是否在信任列表中且已启用
|
|
38
|
+
* 需求 2.6: 验证仓库是否可以处理事件
|
|
39
|
+
* @param ctx Koishi 上下文
|
|
40
|
+
* @param repo 仓库名 (owner/repo)
|
|
41
|
+
* @returns 是否信任且启用
|
|
42
|
+
*/
|
|
43
|
+
export declare function isTrusted(ctx: Context, repo: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* 检查仓库是否在信任列表中(不考虑启用状态)
|
|
46
|
+
* @param ctx Koishi 上下文
|
|
47
|
+
* @param repo 仓库名 (owner/repo)
|
|
48
|
+
* @returns 是否在信任列表中
|
|
49
|
+
*/
|
|
50
|
+
export declare function isInTrustList(ctx: Context, repo: string): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* 启用信任仓库
|
|
53
|
+
* 需求 2.4: 启用该仓库的事件处理
|
|
54
|
+
* @param ctx Koishi 上下文
|
|
55
|
+
* @param repo 仓库名 (owner/repo)
|
|
56
|
+
* @returns 是否成功启用
|
|
57
|
+
*/
|
|
58
|
+
export declare function enableRepo(ctx: Context, repo: string): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* 禁用信任仓库
|
|
61
|
+
* 需求 2.5: 禁用该仓库的事件处理
|
|
62
|
+
* @param ctx Koishi 上下文
|
|
63
|
+
* @param repo 仓库名 (owner/repo)
|
|
64
|
+
* @returns 是否成功禁用
|
|
65
|
+
*/
|
|
66
|
+
export declare function disableRepo(ctx: Context, repo: string): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* 获取单个信任仓库信息
|
|
69
|
+
* @param ctx Koishi 上下文
|
|
70
|
+
* @param repo 仓库名 (owner/repo)
|
|
71
|
+
* @returns 仓库信息,不存在返回 null
|
|
72
|
+
*/
|
|
73
|
+
export declare function getTrustedRepo(ctx: Context, repo: string): Promise<TrustedRepo | null>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建 GitHub Webhook 签名
|
|
3
|
+
* @param payload 原始请求体
|
|
4
|
+
* @param secret Webhook Secret
|
|
5
|
+
* @returns 签名字符串,格式为 sha256=<hex_digest>
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSignature(payload: string, secret: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* 验证 GitHub Webhook 签名
|
|
10
|
+
* @param payload 原始请求体
|
|
11
|
+
* @param signature X-Hub-Signature-256 头的值
|
|
12
|
+
* @param secret 配置的 Webhook Secret
|
|
13
|
+
* @returns 签名是否有效
|
|
14
|
+
*/
|
|
15
|
+
export declare function verifySignature(payload: string, signature: string, secret: string): boolean;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件类型和接口定义
|
|
3
|
+
* 需求: 4.1-4.7
|
|
4
|
+
*/
|
|
5
|
+
/** 支持的事件类型 */
|
|
6
|
+
export type EventType = 'issues' | 'issue_comment' | 'pull_request' | 'pull_request_review' | 'pull_request_review_comment' | 'release' | 'push' | 'star' | 'fork' | 'create' | 'delete' | 'workflow_run';
|
|
7
|
+
/** 提交信息 */
|
|
8
|
+
export interface CommitInfo {
|
|
9
|
+
sha: string;
|
|
10
|
+
message: string;
|
|
11
|
+
author: string;
|
|
12
|
+
url: string;
|
|
13
|
+
}
|
|
14
|
+
/** 解析后的事件数据 */
|
|
15
|
+
export interface ParsedEvent {
|
|
16
|
+
type: EventType;
|
|
17
|
+
displayType: string;
|
|
18
|
+
repo: string;
|
|
19
|
+
actor: string;
|
|
20
|
+
action?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
number?: number;
|
|
23
|
+
url: string;
|
|
24
|
+
body?: string;
|
|
25
|
+
commits?: CommitInfo[];
|
|
26
|
+
totalCommits?: number;
|
|
27
|
+
ref?: string;
|
|
28
|
+
tagName?: string;
|
|
29
|
+
starCount?: number;
|
|
30
|
+
}
|
|
31
|
+
/** 事件类型显示信息 */
|
|
32
|
+
export interface EventDisplayInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
emoji: string;
|
|
35
|
+
}
|
|
36
|
+
/** 事件类型到显示名称和 emoji 的映射 */
|
|
37
|
+
export declare const EVENT_DISPLAY_MAP: Record<EventType, EventDisplayInfo>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取事件类型的显示名称
|
|
40
|
+
* @param type 事件类型
|
|
41
|
+
* @returns 显示名称
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDisplayType(type: EventType): string;
|
|
44
|
+
/**
|
|
45
|
+
* 获取事件类型的 emoji
|
|
46
|
+
* @param type 事件类型
|
|
47
|
+
* @returns emoji 字符
|
|
48
|
+
*/
|
|
49
|
+
export declare function getEventEmoji(type: EventType): string;
|
package/lib/webhook.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook 处理器
|
|
3
|
+
* 需求: 1.1-1.6, 2.6, 9.1-9.6
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from 'koishi';
|
|
6
|
+
import type { Context as KoaContext } from 'koa';
|
|
7
|
+
import { Config } from './config';
|
|
8
|
+
declare module 'koishi' {
|
|
9
|
+
interface Context {
|
|
10
|
+
server: {
|
|
11
|
+
post(path: string, handler: (ctx: KoaContext) => Promise<void>): void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 注册 Webhook 处理器
|
|
17
|
+
* 需求 1.1: 在配置的路径上监听 HTTP POST 请求
|
|
18
|
+
* @param ctx Koishi 上下文
|
|
19
|
+
* @param config 插件配置
|
|
20
|
+
*/
|
|
21
|
+
export declare function registerWebhook(ctx: Context, config: Config): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-github-webhook-pusher",
|
|
3
3
|
"description": "GitHub Webhook 事件推送插件",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"ClozyA <aoxuan233@gmail.com>"
|
|
7
7
|
],
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "vitest --run",
|
|
22
|
-
"test:watch": "vitest"
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"build": "tsc -p tsconfig.json",
|
|
24
|
+
"build:ci": "tsc -p tsconfig.github.json",
|
|
25
|
+
"prepublishOnly": "npm run build:ci"
|
|
23
26
|
},
|
|
24
27
|
"keywords": [
|
|
25
28
|
"chatbot",
|