@zhin.js/adapter-github 0.1.19 → 0.1.21

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/src/types.ts ADDED
@@ -0,0 +1,167 @@
1
+ // ── Bot 配置 ─────────────────────────────────────────────────────────
2
+ // GitHub App 认证: app_id + private_key → JWT → Installation Token
3
+ // OAuth 用户授权: client_id + client_secret → 用户绑定 GitHub 账号
4
+
5
+ export interface GitHubBotConfig {
6
+ context: 'github';
7
+ /** Bot 标识名称 */
8
+ name: string;
9
+ /** GitHub App ID */
10
+ app_id: number;
11
+ /** GitHub App 私钥 PEM 内容或文件路径 */
12
+ private_key: string;
13
+ /** Installation ID (不填则自动获取第一个) */
14
+ installation_id?: number;
15
+ /** Webhook 签名密钥 */
16
+ webhook_secret?: string;
17
+ /** GitHub App OAuth: Client ID (在 App 设置页获取) */
18
+ client_id?: string;
19
+ /** GitHub App OAuth: Client Secret */
20
+ client_secret?: string;
21
+ /** 服务公开访问地址,用于 OAuth 回调和绑定链接(如 https://bot.example.com) */
22
+ public_url?: string;
23
+ }
24
+
25
+ // ── OAuth 用户绑定 ───────────────────────────────────────────────────
26
+
27
+ export interface GitHubOAuthUser {
28
+ id: number;
29
+ /** 聊天平台名称 (icqq / kook / discord ...) */
30
+ platform: string;
31
+ /** 聊天平台用户 ID */
32
+ platform_uid: string;
33
+ /** GitHub 用户名 */
34
+ github_login: string;
35
+ /** GitHub 用户 ID */
36
+ github_id: number;
37
+ /** OAuth access_token */
38
+ access_token: string;
39
+ /** 授权范围 */
40
+ scope: string;
41
+ created_at: Date;
42
+ updated_at: Date;
43
+ }
44
+
45
+ // ── Channel ID ───────────────────────────────────────────────────────
46
+ // 格式: {owner}/{repo}/issues/{number} 或 {owner}/{repo}/pull/{number}
47
+
48
+ export interface ParsedChannel {
49
+ repo: string;
50
+ type: 'issue' | 'pr';
51
+ number: number;
52
+ }
53
+
54
+ export function parseChannelId(channelId: string): ParsedChannel | null {
55
+ const issueMatch = channelId.match(/^(.+?\/.+?)\/issues\/(\d+)$/);
56
+ if (issueMatch) return { repo: issueMatch[1], type: 'issue', number: parseInt(issueMatch[2]) };
57
+ const prMatch = channelId.match(/^(.+?\/.+?)\/pull\/(\d+)$/);
58
+ if (prMatch) return { repo: prMatch[1], type: 'pr', number: parseInt(prMatch[2]) };
59
+ return null;
60
+ }
61
+
62
+ export function buildChannelId(repo: string, type: 'issue' | 'pr', number: number): string {
63
+ return type === 'issue' ? `${repo}/issues/${number}` : `${repo}/pull/${number}`;
64
+ }
65
+
66
+ // ── Webhook Payloads ─────────────────────────────────────────────────
67
+
68
+ export interface GitHubUser {
69
+ login: string;
70
+ id: number;
71
+ html_url: string;
72
+ }
73
+
74
+ export interface GitHubComment {
75
+ id: number;
76
+ body: string;
77
+ user: GitHubUser;
78
+ created_at: string;
79
+ updated_at: string;
80
+ html_url: string;
81
+ }
82
+
83
+ export interface GitHubRepo {
84
+ full_name: string;
85
+ html_url: string;
86
+ description?: string;
87
+ }
88
+
89
+ export interface GitHubIssue {
90
+ number: number;
91
+ title: string;
92
+ html_url: string;
93
+ state: string;
94
+ user: GitHubUser;
95
+ }
96
+
97
+ export interface GitHubPR {
98
+ number: number;
99
+ title: string;
100
+ html_url: string;
101
+ state: string;
102
+ user: GitHubUser;
103
+ head: { ref: string };
104
+ base: { ref: string };
105
+ }
106
+
107
+ export interface IssueCommentPayload {
108
+ action: 'created' | 'edited' | 'deleted';
109
+ comment: GitHubComment;
110
+ issue: GitHubIssue;
111
+ repository: GitHubRepo;
112
+ sender: GitHubUser;
113
+ }
114
+
115
+ export interface PRReviewCommentPayload {
116
+ action: 'created' | 'edited' | 'deleted';
117
+ comment: GitHubComment & { diff_hunk?: string; path?: string };
118
+ pull_request: GitHubPR;
119
+ repository: GitHubRepo;
120
+ sender: GitHubUser;
121
+ }
122
+
123
+ export interface PRReviewPayload {
124
+ action: 'submitted' | 'edited' | 'dismissed';
125
+ review: {
126
+ id: number;
127
+ body: string | null;
128
+ state: 'approved' | 'changes_requested' | 'commented' | 'dismissed';
129
+ user: GitHubUser;
130
+ html_url: string;
131
+ submitted_at: string;
132
+ };
133
+ pull_request: GitHubPR;
134
+ repository: GitHubRepo;
135
+ sender: GitHubUser;
136
+ }
137
+
138
+ export interface GenericWebhookPayload {
139
+ action?: string;
140
+ repository: GitHubRepo;
141
+ sender: GitHubUser;
142
+ ref?: string;
143
+ commits?: Array<{ id: string; message: string; author: { name: string; username?: string }; url: string }>;
144
+ issue?: GitHubIssue;
145
+ pull_request?: GitHubPR;
146
+ forkee?: { full_name: string; html_url: string; owner: { login: string } };
147
+ }
148
+
149
+ // ── Subscription ─────────────────────────────────────────────────────
150
+
151
+ export type EventType = 'push' | 'issue' | 'star' | 'fork' | 'unstar' | 'pull_request';
152
+
153
+ export interface Subscription {
154
+ id: number;
155
+ repo: string;
156
+ events: EventType[];
157
+ target_id: string;
158
+ target_type: 'private' | 'group' | 'channel';
159
+ adapter: string;
160
+ bot: string;
161
+ }
162
+
163
+ // ── Tool Action Types ────────────────────────────────────────────────
164
+
165
+ export type PrAction = 'list' | 'view' | 'diff' | 'merge' | 'create' | 'review' | 'close';
166
+ export type IssueAction = 'list' | 'view' | 'create' | 'close' | 'comment';
167
+ export type RepoAction = 'info' | 'branches' | 'releases' | 'runs' | 'stars';