koishi-plugin-github-webhook-pusher 0.0.1

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.
@@ -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[];
@@ -0,0 +1,37 @@
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
+ * 解析 Release 事件
13
+ * 需求 4.2: 提取版本号、发布者和下载链接
14
+ */
15
+ export declare function parseReleaseEvent(payload: any): ParsedEvent | null;
16
+ /**
17
+ * 解析 Push 事件
18
+ * 需求 4.3, 4.6: 提取分支名、提交列表(最多5条)和推送者信息
19
+ */
20
+ export declare function parsePushEvent(payload: any): ParsedEvent | null;
21
+ /**
22
+ * 解析 Pull Request 事件
23
+ * 需求 4.4: 提取 PR 标题、编号、操作者和链接
24
+ */
25
+ export declare function parsePullRequestEvent(payload: any): ParsedEvent | null;
26
+ /**
27
+ * 解析 Star 事件
28
+ * 需求 4.5: 提取操作者和当前 star 数量
29
+ */
30
+ export declare function parseStarEvent(payload: any): ParsedEvent | null;
31
+ /**
32
+ * 统一的事件解析入口函数
33
+ * @param eventName X-GitHub-Event 头的值
34
+ * @param payload 解析后的 JSON 负载
35
+ * @returns 解析后的事件数据,不支持的事件返回 null
36
+ */
37
+ export declare function parseEvent(eventName: string, payload: any): ParsedEvent | null;
@@ -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,6 @@
1
+ /**
2
+ * 数据访问层导出
3
+ */
4
+ export * from './trust';
5
+ export * from './subscription';
6
+ export * from './delivery';
@@ -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' | 'release' | 'push' | 'pull_request' | 'star';
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;
@@ -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 ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "koishi-plugin-github-webhook-pusher",
3
+ "description": "GitHub Webhook 事件推送插件",
4
+ "version": "0.0.1",
5
+ "contributors": [
6
+ "ClozyA <aoxuan233@gmail.com>"
7
+ ],
8
+ "homepage": "https://github.com/ClozyA/github-webhook-pusher",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/ClozyA/github-webhook-pusher.git"
12
+ },
13
+ "main": "lib/index.js",
14
+ "typings": "lib/index.d.ts",
15
+ "files": [
16
+ "lib",
17
+ "dist"
18
+ ],
19
+ "license": "MIT",
20
+ "scripts": {
21
+ "test": "vitest --run",
22
+ "test:watch": "vitest"
23
+ },
24
+ "keywords": [
25
+ "chatbot",
26
+ "koishi",
27
+ "plugin",
28
+ "github",
29
+ "webhook"
30
+ ],
31
+ "devDependencies": {
32
+ "@types/node": "^22.10.5",
33
+ "fast-check": "^3.22.0",
34
+ "koishi": "^4.18.7",
35
+ "typescript": "^5.7.3",
36
+ "vitest": "^2.1.8"
37
+ },
38
+ "peerDependencies": {
39
+ "koishi": "^4.18.7"
40
+ },
41
+ "koishi": {
42
+ "description": {
43
+ "zh": "接收 GitHub Webhook 事件并推送到群聊,支持 Issues、Release、Push、PR、Star 等事件",
44
+ "en": "Receive GitHub Webhook events and push to chat groups, supporting Issues, Release, Push, PR, Star events"
45
+ },
46
+ "service": {
47
+ "required": [
48
+ "server",
49
+ "database"
50
+ ],
51
+ "optional": [],
52
+ "implements": []
53
+ }
54
+ }
55
+ }
package/readme.md ADDED
@@ -0,0 +1,210 @@
1
+ # koishi-plugin-github-webhook-pusher
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-github-webhook-pusher?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-github-webhook-pusher)
4
+
5
+ Koishi 机器人框架的 GitHub Webhook 推送插件,支持将 GitHub 仓库事件(Issues、Release、Push、PR、Star)推送到 QQ 群聊或私聊。
6
+
7
+ ## 功能特性
8
+
9
+ - 🔐 **安全验证** - 支持 HMAC SHA256 签名验证,确保 Webhook 请求来源可信
10
+ - 📋 **信任仓库管理** - 管理员可控制哪些仓库的事件可以被处理
11
+ - 🔔 **灵活订阅** - 用户可自由订阅感兴趣的仓库和事件类型
12
+ - 📨 **多事件支持** - 支持 Issues、Release、Push、Pull Request、Star 等事件
13
+ - 🚀 **并发推送** - 支持并发推送到多个订阅目标,可配置并发数
14
+ - 💾 **数据持久化** - 订阅和信任仓库数据持久化存储
15
+
16
+ ## 安装
17
+
18
+ ### 通过 Koishi 插件市场安装
19
+
20
+ 在 Koishi 控制台的插件市场中搜索 `github-webhook-pusher` 并安装。
21
+
22
+ ### 通过 npm 安装
23
+
24
+ ```bash
25
+ npm install koishi-plugin-github-webhook-pusher
26
+ ```
27
+
28
+ ## 配置说明
29
+
30
+ | 配置项 | 类型 | 默认值 | 说明 |
31
+ |--------|------|--------|------|
32
+ | `path` | string | `/github/webhook` | Webhook 接收路径 |
33
+ | `secret` | string | (必填) | GitHub Webhook Secret,用于签名验证 |
34
+ | `baseUrl` | string | - | 显示用基础 URL |
35
+ | `defaultEvents` | string[] | `['issues', 'release', 'push']` | 新订阅的默认事件类型 |
36
+ | `debug` | boolean | `false` | 启用调试模式,输出详细日志 |
37
+ | `allowUntrusted` | boolean | `false` | 是否允许处理非信任仓库的事件 |
38
+ | `concurrency` | number | `5` | 消息推送并发数 |
39
+
40
+ ### 配置示例
41
+
42
+ ```yaml
43
+ plugins:
44
+ github-webhook-pusher:
45
+ path: /github/webhook
46
+ secret: your-webhook-secret-here
47
+ defaultEvents:
48
+ - issues
49
+ - release
50
+ - push
51
+ debug: false
52
+ allowUntrusted: false
53
+ concurrency: 5
54
+ ```
55
+
56
+ ## GitHub Webhook 设置指南
57
+
58
+ ### 1. 获取 Webhook URL
59
+
60
+ 你的 Webhook URL 格式为:
61
+ ```
62
+ https://your-koishi-server.com/github/webhook
63
+ ```
64
+
65
+ 其中 `/github/webhook` 是默认路径,可通过 `path` 配置项修改。
66
+
67
+ ### 2. 在 GitHub 仓库中配置 Webhook
68
+
69
+ 1. 进入你的 GitHub 仓库
70
+ 2. 点击 **Settings** → **Webhooks** → **Add webhook**
71
+ 3. 填写以下信息:
72
+ - **Payload URL**: 你的 Webhook URL
73
+ - **Content type**: `application/json`
74
+ - **Secret**: 与插件配置中的 `secret` 保持一致
75
+ - **Which events would you like to trigger this webhook?**: 选择需要的事件
76
+ - Issues
77
+ - Releases
78
+ - Pushes
79
+ - Pull requests
80
+ - Stars (Watch)
81
+ 4. 点击 **Add webhook** 保存
82
+
83
+ ### 3. 验证配置
84
+
85
+ 配置完成后,GitHub 会发送一个 ping 事件。你可以在 Webhook 设置页面查看投递记录,确认是否收到 200 响应。
86
+
87
+
88
+ ## 命令使用说明
89
+
90
+ ### 信任仓库管理(管理员)
91
+
92
+ 信任仓库是可以被订阅的仓库白名单,只有管理员可以管理。
93
+
94
+ | 命令 | 说明 | 示例 |
95
+ |------|------|------|
96
+ | `gh.trust.add <repo>` | 添加信任仓库 | `gh.trust.add koishijs/koishi` |
97
+ | `gh.trust.remove <repo>` | 移除信任仓库 | `gh.trust.remove koishijs/koishi` |
98
+ | `gh.trust.list` | 列出所有信任仓库 | `gh.trust.list` |
99
+ | `gh.trust.enable <repo>` | 启用信任仓库 | `gh.trust.enable koishijs/koishi` |
100
+ | `gh.trust.disable <repo>` | 禁用信任仓库 | `gh.trust.disable koishijs/koishi` |
101
+
102
+ ### 订阅管理
103
+
104
+ 用户可以订阅信任列表中的仓库,接收事件通知。
105
+
106
+ | 命令 | 说明 | 示例 |
107
+ |------|------|------|
108
+ | `gh.sub <repo>` | 订阅仓库 | `gh.sub koishijs/koishi` |
109
+ | `gh.unsub <repo>` | 取消订阅 | `gh.unsub koishijs/koishi` |
110
+ | `gh.list` | 列出当前会话的所有订阅 | `gh.list` |
111
+ | `gh.events <repo>` | 查看订阅的事件类型 | `gh.events koishijs/koishi` |
112
+ | `gh.events <repo> +/-event` | 修改订阅的事件类型 | `gh.events koishijs/koishi +issues -star` |
113
+
114
+ ### 工具命令
115
+
116
+ | 命令 | 说明 | 示例 |
117
+ |------|------|------|
118
+ | `gh.ping` | 查看插件状态 | `gh.ping` |
119
+ | `gh.test <repo> <event>` | 生成测试消息(管理员) | `gh.test koishijs/koishi push` |
120
+
121
+ ## 支持的事件类型
122
+
123
+ | 事件类型 | 显示名称 | Emoji | 说明 |
124
+ |----------|----------|-------|------|
125
+ | `issues` | Issue | 📌 | Issue 的创建、关闭、重新打开、编辑 |
126
+ | `release` | Release | 🚀 | 版本发布 |
127
+ | `push` | Commit | ⬆️ | 代码推送(最多显示 5 条提交) |
128
+ | `pull_request` | PR | 🔀 | Pull Request 的创建、关闭、合并 |
129
+ | `star` | Star | ⭐ | Star 操作 |
130
+
131
+ ## 消息格式示例
132
+
133
+ ### Issues 事件
134
+ ```
135
+ 📌 [owner/repo] Issue
136
+ user opened #123: Issue 标题
137
+ https://github.com/owner/repo/issues/123
138
+ ```
139
+
140
+ ### Push 事件
141
+ ```
142
+ ⬆️ [owner/repo] Commit
143
+ user 推送了 3 个提交到 main
144
+
145
+ • abc1234 - 提交消息1
146
+ • def5678 - 提交消息2
147
+ • ghi9012 - 提交消息3
148
+
149
+ https://github.com/owner/repo/compare/...
150
+ ```
151
+
152
+ ### Release 事件
153
+ ```
154
+ 🚀 [owner/repo] Release
155
+ user 发布了 v1.0.0
156
+ https://github.com/owner/repo/releases/tag/v1.0.0
157
+ ```
158
+
159
+ ## 常见问题解答
160
+
161
+ ### Q: Webhook 返回 401 错误?
162
+
163
+ **A:** 签名验证失败。请检查:
164
+ 1. GitHub Webhook 设置中的 Secret 与插件配置的 `secret` 是否一致
165
+ 2. Content type 是否设置为 `application/json`
166
+
167
+ ### Q: 收不到 Webhook 事件?
168
+
169
+ **A:** 请检查:
170
+ 1. Koishi 服务器是否可以从公网访问
171
+ 2. Webhook URL 是否正确(包括端口号)
172
+ 3. 防火墙是否允许 GitHub 的 IP 访问
173
+ 4. 在 GitHub Webhook 设置页面查看投递记录,确认请求是否发送成功
174
+
175
+ ### Q: 订阅仓库时提示"不在信任列表中"?
176
+
177
+ **A:** 需要管理员先使用 `gh.trust.add owner/repo` 将仓库添加到信任列表。
178
+
179
+ ### Q: 如何修改订阅的事件类型?
180
+
181
+ **A:** 使用 `gh.events` 命令:
182
+ - 添加事件:`gh.events owner/repo +issues +release`
183
+ - 移除事件:`gh.events owner/repo -star -push`
184
+ - 混合操作:`gh.events owner/repo +issues -star`
185
+
186
+ ### Q: 如何查看当前订阅了哪些仓库?
187
+
188
+ **A:** 使用 `gh.list` 命令查看当前会话的所有订阅。
189
+
190
+ ### Q: 消息推送失败会影响其他订阅者吗?
191
+
192
+ **A:** 不会。插件使用错误隔离机制,单个目标的推送失败不会影响其他目标。
193
+
194
+ ### Q: 如何测试消息格式?
195
+
196
+ **A:** 管理员可以使用 `gh.test owner/repo event` 命令生成测试消息,例如:
197
+ ```
198
+ gh.test koishijs/koishi issues
199
+ gh.test koishijs/koishi push
200
+ ```
201
+
202
+ ## 依赖
203
+
204
+ - Koishi 4.x
205
+ - 需要 `server` 服务(提供 HTTP 路由)
206
+ - 需要 `database` 服务(数据持久化)
207
+
208
+ ## 许可证
209
+
210
+ MIT License