@kevisual/cnb 0.0.13 → 0.0.14
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/dist/keep.js +2850 -4
- package/dist/opencode.js +3216 -290
- package/dist/routes.d.ts +11 -2
- package/dist/routes.js +3215 -289
- package/package.json +7 -6
- package/src/cnb-core.ts +8 -0
- package/src/git/index.ts +676 -0
- package/src/repo/index.ts +2 -2
- package/src/user/index.ts +4 -4
package/src/git/index.ts
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Git 提交信息
|
|
5
|
+
*/
|
|
6
|
+
export type Commit = {
|
|
7
|
+
sha: string;
|
|
8
|
+
short_sha: string;
|
|
9
|
+
title: string;
|
|
10
|
+
message: string;
|
|
11
|
+
author: {
|
|
12
|
+
name: string;
|
|
13
|
+
email: string;
|
|
14
|
+
username: string;
|
|
15
|
+
avatar_url: string;
|
|
16
|
+
};
|
|
17
|
+
committer: {
|
|
18
|
+
name: string;
|
|
19
|
+
email: string;
|
|
20
|
+
username: string;
|
|
21
|
+
avatar_url: string;
|
|
22
|
+
};
|
|
23
|
+
parents: Array<{ sha: string }>;
|
|
24
|
+
created_at: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Git 分支信息
|
|
29
|
+
*/
|
|
30
|
+
export type Branch = {
|
|
31
|
+
name: string;
|
|
32
|
+
commit: {
|
|
33
|
+
sha: string;
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Git 分支详细信息
|
|
40
|
+
*/
|
|
41
|
+
export type BranchDetail = Branch & {
|
|
42
|
+
protected: boolean;
|
|
43
|
+
default: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Git 标签信息
|
|
48
|
+
*/
|
|
49
|
+
export type Tag = {
|
|
50
|
+
name: string;
|
|
51
|
+
commit: {
|
|
52
|
+
sha: string;
|
|
53
|
+
url: string;
|
|
54
|
+
};
|
|
55
|
+
message: string;
|
|
56
|
+
annotation: Record<string, any>;
|
|
57
|
+
created_at: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Git 文件内容信息
|
|
62
|
+
*/
|
|
63
|
+
export type Content = {
|
|
64
|
+
name: string;
|
|
65
|
+
path: string;
|
|
66
|
+
sha: string;
|
|
67
|
+
size: number;
|
|
68
|
+
url: string;
|
|
69
|
+
html_url: string;
|
|
70
|
+
git_url: string;
|
|
71
|
+
download_url: string;
|
|
72
|
+
type: string;
|
|
73
|
+
content?: string;
|
|
74
|
+
encoding?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Git Blob 对象
|
|
79
|
+
*/
|
|
80
|
+
export type Blob = {
|
|
81
|
+
sha: string;
|
|
82
|
+
size: number;
|
|
83
|
+
url: string;
|
|
84
|
+
content?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Git 比较结果
|
|
89
|
+
*/
|
|
90
|
+
export type CompareResponse = {
|
|
91
|
+
status: string;
|
|
92
|
+
ahead_by: number;
|
|
93
|
+
behind_by: number;
|
|
94
|
+
total_commits: number;
|
|
95
|
+
commits: Commit[];
|
|
96
|
+
files: Array<{
|
|
97
|
+
sha: string;
|
|
98
|
+
filename: string;
|
|
99
|
+
status: string;
|
|
100
|
+
additions: number;
|
|
101
|
+
deletions: number;
|
|
102
|
+
changes: number;
|
|
103
|
+
patch?: string;
|
|
104
|
+
}>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Git 提交状态
|
|
109
|
+
*/
|
|
110
|
+
export type CommitStatus = {
|
|
111
|
+
id: string;
|
|
112
|
+
state: string;
|
|
113
|
+
description: string;
|
|
114
|
+
target_url: string;
|
|
115
|
+
context: string;
|
|
116
|
+
created_at: string;
|
|
117
|
+
updated_at: string;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Git 提交附件
|
|
122
|
+
*/
|
|
123
|
+
export type CommitAsset = {
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
path: string;
|
|
127
|
+
sha1: string;
|
|
128
|
+
size: number;
|
|
129
|
+
created_at: string;
|
|
130
|
+
uploader: {
|
|
131
|
+
username: string;
|
|
132
|
+
nickname: string;
|
|
133
|
+
avatar_url: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Git 提交附件上传 URL
|
|
139
|
+
*/
|
|
140
|
+
export type CommitAssetUploadURL = {
|
|
141
|
+
upload_url: string;
|
|
142
|
+
verify_url: string;
|
|
143
|
+
upload_token: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Git 标签注释
|
|
148
|
+
*/
|
|
149
|
+
export type TagAnnotation = {
|
|
150
|
+
key: string;
|
|
151
|
+
value: string;
|
|
152
|
+
creator: string;
|
|
153
|
+
created_at: string;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Git 头引用
|
|
158
|
+
*/
|
|
159
|
+
export type HeadRef = {
|
|
160
|
+
default_branch: string;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Git 操作类
|
|
165
|
+
* 提供 Git 相关的 API 操作,包括提交、分支、标签、文件等
|
|
166
|
+
*/
|
|
167
|
+
export class Git extends CNBCore {
|
|
168
|
+
constructor(options: CNBCoreOptions) {
|
|
169
|
+
super({ token: options.token, cookie: options.cookie });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 查询提交列表
|
|
174
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
175
|
+
* @param params 查询参数
|
|
176
|
+
* @returns 提交列表
|
|
177
|
+
*/
|
|
178
|
+
async listCommits(repo: string, params?: ListCommitsParams): Promise<Result<Commit[]>> {
|
|
179
|
+
const url = `/${repo}/-/git/commits`;
|
|
180
|
+
return this.get({ url, params });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 查询指定提交
|
|
185
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
186
|
+
* @param ref 提交的哈希值或分支名称
|
|
187
|
+
* @returns 提交信息
|
|
188
|
+
*/
|
|
189
|
+
async getCommit(repo: string, ref: string): Promise<Result<Commit>> {
|
|
190
|
+
const url = `/${repo}/-/git/commits/${ref}`;
|
|
191
|
+
return this.get({ url });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 查询指定提交的提交状态
|
|
196
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
197
|
+
* @param commitish Git 引用标识符,分支名称、提交哈希值或标签名称
|
|
198
|
+
* @returns 提交状态列表
|
|
199
|
+
*/
|
|
200
|
+
async getCommitStatuses(repo: string, commitish: string): Promise<Result<CommitStatus[]>> {
|
|
201
|
+
const url = `/${repo}/-/git/commit-statuses/${commitish}`;
|
|
202
|
+
return this.get({ url });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 查询分支列表
|
|
207
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
208
|
+
* @param params 分页参数
|
|
209
|
+
* @returns 分支列表
|
|
210
|
+
*/
|
|
211
|
+
async listBranches(repo: string, params?: PaginationParams): Promise<Result<Branch[]>> {
|
|
212
|
+
const url = `/${repo}/-/git/branches`;
|
|
213
|
+
return this.get({ url, params });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 创建新分支
|
|
218
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
219
|
+
* @param data 创建分支的数据
|
|
220
|
+
* @returns 创建结果
|
|
221
|
+
*/
|
|
222
|
+
async createBranch(repo: string, data: CreateBranchData): Promise<Result<void>> {
|
|
223
|
+
const url = `/${repo}/-/git/branches`;
|
|
224
|
+
return this.post({ url, data });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 查询指定分支
|
|
229
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
230
|
+
* @param branch 分支名称
|
|
231
|
+
* @returns 分支详细信息
|
|
232
|
+
*/
|
|
233
|
+
async getBranch(repo: string, branch: string): Promise<Result<BranchDetail>> {
|
|
234
|
+
const url = `/${repo}/-/git/branches/${branch}`;
|
|
235
|
+
return this.get({ url });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 删除指定分支
|
|
240
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
241
|
+
* @param branch 分支名称
|
|
242
|
+
* @returns 删除结果
|
|
243
|
+
*/
|
|
244
|
+
async deleteBranch(repo: string, branch: string): Promise<Result<void>> {
|
|
245
|
+
const url = `/${repo}/-/git/branches/${branch}`;
|
|
246
|
+
return this.delete({ url });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 查询标签列表
|
|
251
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
252
|
+
* @param params 分页参数
|
|
253
|
+
* @returns 标签列表
|
|
254
|
+
*/
|
|
255
|
+
async listTags(repo: string, params?: PaginationParams): Promise<Result<Tag[]>> {
|
|
256
|
+
const url = `/${repo}/-/git/tags`;
|
|
257
|
+
return this.get({ url, params });
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 创建标签
|
|
262
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
263
|
+
* @param data 创建标签的数据
|
|
264
|
+
* @returns 创建的标签信息
|
|
265
|
+
*/
|
|
266
|
+
async createTag(repo: string, data: CreateTagData): Promise<Result<Tag>> {
|
|
267
|
+
const url = `/${repo}/-/git/tags`;
|
|
268
|
+
return this.post({ url, data });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 查询指定标签
|
|
273
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
274
|
+
* @param tag 标签名称
|
|
275
|
+
* @returns 标签信息
|
|
276
|
+
*/
|
|
277
|
+
async getTag(repo: string, tag: string): Promise<Result<Tag>> {
|
|
278
|
+
const url = `/${repo}/-/git/tags/${tag}`;
|
|
279
|
+
return this.get({ url });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 删除指定标签
|
|
284
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
285
|
+
* @param tag 标签名称
|
|
286
|
+
* @returns 删除结果
|
|
287
|
+
*/
|
|
288
|
+
async deleteTag(repo: string, tag: string): Promise<Result<void>> {
|
|
289
|
+
const url = `/${repo}/-/git/tags/${tag}`;
|
|
290
|
+
return this.delete({ url });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 创建 Blob 对象
|
|
295
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
296
|
+
* @param data 创建 Blob 的数据
|
|
297
|
+
* @returns 创建的 Blob 信息
|
|
298
|
+
*/
|
|
299
|
+
async createBlob(repo: string, data: CreateBlobData): Promise<Result<Blob>> {
|
|
300
|
+
const url = `/${repo}/-/git/blobs`;
|
|
301
|
+
return this.post({ url, data });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* 查询仓库文件内容(根目录)
|
|
306
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
307
|
+
* @param params 查询参数
|
|
308
|
+
* @returns 文件或目录内容
|
|
309
|
+
*/
|
|
310
|
+
async getContent(repo: string, params?: GetContentParams): Promise<Result<Content>> {
|
|
311
|
+
const url = `/${repo}/-/git/contents`;
|
|
312
|
+
return this.get({ url, params });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* 查询指定路径的文件内容
|
|
317
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
318
|
+
* @param filePath 文件路径
|
|
319
|
+
* @param params 查询参数
|
|
320
|
+
* @returns 文件内容
|
|
321
|
+
*/
|
|
322
|
+
async getContentWithPath(repo: string, filePath: string, params?: GetContentWithPathParams): Promise<Result<Content>> {
|
|
323
|
+
const url = `/${repo}/-/git/contents/${filePath}`;
|
|
324
|
+
return this.get({ url, params });
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 获取原始文件内容
|
|
329
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
330
|
+
* @param refWithPath Git 引用(分支、标签、提交哈希)和文件路径
|
|
331
|
+
* @param params 查询参数
|
|
332
|
+
* @returns 原始文件内容
|
|
333
|
+
*/
|
|
334
|
+
async getRaw(repo: string, refWithPath: string, params?: GetRawParams): Promise<string> {
|
|
335
|
+
const url = `/${repo}/-/git/raw/${refWithPath}`;
|
|
336
|
+
const response = await this.get({ url, params, useOrigin: true });
|
|
337
|
+
return response;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 下载仓库内容归档
|
|
342
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
343
|
+
* @param refWithPath Git 引用(分支名、标签名、提交哈希或分支名/文件路径)
|
|
344
|
+
* @param useOrigin 是否返回原始响应
|
|
345
|
+
* @returns 归档文件
|
|
346
|
+
*/
|
|
347
|
+
async getArchive(repo: string, refWithPath: string, useOrigin?: boolean): Promise<any> {
|
|
348
|
+
const url = `/${repo}/-/git/archive/${refWithPath}`;
|
|
349
|
+
return this.get({ url, useOrigin });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* 打包下载提交变更文件
|
|
354
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
355
|
+
* @param sha1 提交的哈希值
|
|
356
|
+
* @returns 变更文件归档
|
|
357
|
+
*/
|
|
358
|
+
async getArchiveCommitChangedFiles(repo: string, sha1: string): Promise<any> {
|
|
359
|
+
const url = `/${repo}/-/git/archive-commit-changed-files/${sha1}`;
|
|
360
|
+
return this.get({ url, useOrigin: true });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 打包下载两次引用之间的变更文件
|
|
365
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
366
|
+
* @param baseHead 用于 Git 比较操作的基准和头部分支或提交的 SHA 值,格式:base...head
|
|
367
|
+
* @returns 变更文件归档
|
|
368
|
+
*/
|
|
369
|
+
async getArchiveCompareChangedFiles(repo: string, baseHead: string): Promise<any> {
|
|
370
|
+
const url = `/${repo}/-/git/archive-compare-changed-files/${baseHead}`;
|
|
371
|
+
return this.get({ url, useOrigin: true });
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* 查询指定提交的元数据
|
|
376
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
377
|
+
* @param sha 提交的哈希值
|
|
378
|
+
* @returns 提交元数据列表
|
|
379
|
+
*/
|
|
380
|
+
async getCommitAnnotations(repo: string, sha: string): Promise<Result<TagAnnotation[]>> {
|
|
381
|
+
const url = `/${repo}/-/git/commit-annotations/${sha}`;
|
|
382
|
+
return this.get({ url });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 设定指定提交的元数据
|
|
387
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
388
|
+
* @param sha 提交的哈希值
|
|
389
|
+
* @param data 提交的元数据
|
|
390
|
+
* @returns 设置结果
|
|
391
|
+
*/
|
|
392
|
+
async putCommitAnnotations(repo: string, sha: string, data: PutCommitAnnotationsData): Promise<Result<void>> {
|
|
393
|
+
const url = `/${repo}/-/git/commit-annotations/${sha}`;
|
|
394
|
+
return this.put({ url, data });
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 删除指定提交的元数据
|
|
399
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
400
|
+
* @param sha 提交的哈希值
|
|
401
|
+
* @param key 提交的元数据键名
|
|
402
|
+
* @returns 删除结果
|
|
403
|
+
*/
|
|
404
|
+
async deleteCommitAnnotation(repo: string, sha: string, key: string): Promise<Result<void>> {
|
|
405
|
+
const url = `/${repo}/-/git/commit-annotations/${sha}/${key}`;
|
|
406
|
+
return this.delete({ url });
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 批量查询提交的元数据
|
|
411
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
412
|
+
* @param data 包含多个提交哈希的请求数据
|
|
413
|
+
* @returns 提交元数据列表
|
|
414
|
+
*/
|
|
415
|
+
async getCommitAnnotationsInBatch(repo: string, data: GetCommitAnnotationsInBatchData): Promise<Result<TagAnnotation[]>> {
|
|
416
|
+
const url = `/${repo}/-/git/commit-annotations-in-batch`;
|
|
417
|
+
return this.post({ url, data });
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 查询指定提交的附件列表
|
|
422
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
423
|
+
* @param sha1 提交的哈希值
|
|
424
|
+
* @returns 附件列表
|
|
425
|
+
*/
|
|
426
|
+
async getCommitAssetsBySha(repo: string, sha1: string): Promise<Result<CommitAsset[]>> {
|
|
427
|
+
const url = `/${repo}/-/git/commit-assets/${sha1}`;
|
|
428
|
+
return this.get({ url });
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* 新增提交附件(获取上传 URL)
|
|
433
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
434
|
+
* @param sha1 提交的哈希值
|
|
435
|
+
* @param data 创建附件上传 URL 的数据
|
|
436
|
+
* @returns 上传 URL 信息
|
|
437
|
+
*/
|
|
438
|
+
async postCommitAssetUploadURL(repo: string, sha1: string, data: PostCommitAssetUploadURLData): Promise<Result<CommitAssetUploadURL>> {
|
|
439
|
+
const url = `/${repo}/-/git/commit-assets/${sha1}/asset-upload-url`;
|
|
440
|
+
return this.post({ url, data });
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 确认提交附件上传完成
|
|
445
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
446
|
+
* @param sha1 提交的哈希值
|
|
447
|
+
* @param uploadToken 上传令牌
|
|
448
|
+
* @param assetPath 附件路径
|
|
449
|
+
* @param params 确认参数
|
|
450
|
+
* @returns 确认结果
|
|
451
|
+
*/
|
|
452
|
+
async postCommitAssetUploadConfirmation(repo: string, sha1: string, uploadToken: string, assetPath: string, params?: PostCommitAssetUploadConfirmationParams): Promise<Result<void>> {
|
|
453
|
+
const url = `/${repo}/-/git/commit-assets/${sha1}/asset-upload-confirmation/${uploadToken}/${assetPath}`;
|
|
454
|
+
return this.post({ url, params });
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* 删除指定提交的附件
|
|
459
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
460
|
+
* @param sha1 提交的哈希值
|
|
461
|
+
* @param assetId 附件唯一标识符
|
|
462
|
+
* @returns 删除结果
|
|
463
|
+
*/
|
|
464
|
+
async deleteCommitAsset(repo: string, sha1: string, assetId: string): Promise<Result<void>> {
|
|
465
|
+
const url = `/${repo}/-/git/commit-assets/${sha1}/${assetId}`;
|
|
466
|
+
return this.delete({ url });
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* 获取提交附件下载链接
|
|
471
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
472
|
+
* @param commitId 提交的哈希值
|
|
473
|
+
* @param filename 文件名称
|
|
474
|
+
* @param params 查询参数
|
|
475
|
+
* @returns 302 重定向到下载地址
|
|
476
|
+
*/
|
|
477
|
+
async getCommitAssets(repo: string, commitId: string, filename: string, params?: GetCommitAssetsParams): Promise<any> {
|
|
478
|
+
const url = `/${repo}/-/commit-assets/download/${commitId}/${filename}`;
|
|
479
|
+
return this.get({ url, params, useOrigin: true });
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* 比较两个提交、分支或标签之间的差异
|
|
484
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
485
|
+
* @param baseHead 用于 Git 比较操作的基准和头部分支或提交的 SHA 值,格式:base...head
|
|
486
|
+
* @returns 比较结果
|
|
487
|
+
*/
|
|
488
|
+
async getCompareCommits(repo: string, baseHead: string): Promise<Result<CompareResponse>> {
|
|
489
|
+
const url = `/${repo}/-/git/compare/${baseHead}`;
|
|
490
|
+
return this.get({ url });
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 获取仓库默认分支
|
|
495
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
496
|
+
* @returns 默认分支信息
|
|
497
|
+
*/
|
|
498
|
+
async getHead(repo: string): Promise<Result<HeadRef>> {
|
|
499
|
+
const url = `/${repo}/-/git/head`;
|
|
500
|
+
return this.get({ url });
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* 查询指定标签的元数据
|
|
505
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
506
|
+
* @param tag 标签名称
|
|
507
|
+
* @returns 标签元数据列表
|
|
508
|
+
*/
|
|
509
|
+
async getTagAnnotations(repo: string, tag: string): Promise<Result<TagAnnotation[]>> {
|
|
510
|
+
const url = `/${repo}/-/git/tag-annotations/${tag}`;
|
|
511
|
+
return this.get({ url });
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* 设定指定标签的元数据
|
|
516
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
517
|
+
* @param tag 标签名称
|
|
518
|
+
* @param data 标签元数据
|
|
519
|
+
* @returns 设置结果
|
|
520
|
+
*/
|
|
521
|
+
async putTagAnnotations(repo: string, tag: string, data: PutTagAnnotationsData): Promise<Result<void>> {
|
|
522
|
+
const url = `/${repo}/-/git/tag-annotations/${tag}`;
|
|
523
|
+
return this.put({ url, data });
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* 删除指定标签的元数据
|
|
528
|
+
* @param repo 仓库名称,格式:组织名称/仓库名称
|
|
529
|
+
* @param tagWithKey 标签名称和键名组合
|
|
530
|
+
* @returns 删除结果
|
|
531
|
+
*/
|
|
532
|
+
async deleteTagAnnotation(repo: string, tagWithKey: string): Promise<Result<void>> {
|
|
533
|
+
const url = `/${repo}/-/git/tag-annotations/${tagWithKey}`;
|
|
534
|
+
return this.delete({ url });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* 分页参数
|
|
540
|
+
*/
|
|
541
|
+
type PaginationParams = {
|
|
542
|
+
/** 分页页码,默认: 1 */
|
|
543
|
+
page?: number;
|
|
544
|
+
/** 分页页大小,默认: 30 */
|
|
545
|
+
page_size?: number;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* 查询提交列表参数
|
|
550
|
+
*/
|
|
551
|
+
type ListCommitsParams = PaginationParams & {
|
|
552
|
+
/** 提交标识符,分支名称或提交哈希值 */
|
|
553
|
+
sha?: string;
|
|
554
|
+
/** 作者匹配模式,支持 Git 原生正则表达式 */
|
|
555
|
+
author?: string;
|
|
556
|
+
/** 提交者匹配模式,支持 Git 原生正则表达式 */
|
|
557
|
+
committer?: string;
|
|
558
|
+
/** 提交时间起始范围,示例:2025-01-01T00:00:00Z */
|
|
559
|
+
since?: string;
|
|
560
|
+
/** 提交时间结束范围,示例:2025-12-31T23:59:59Z */
|
|
561
|
+
until?: string;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* 创建分支参数
|
|
566
|
+
*/
|
|
567
|
+
type CreateBranchData = {
|
|
568
|
+
/** 分支名称 */
|
|
569
|
+
branch_name: string;
|
|
570
|
+
/** 起始点,默认使用仓库默认分支 */
|
|
571
|
+
start_point?: string;
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* 创建标签参数
|
|
576
|
+
*/
|
|
577
|
+
type CreateTagData = {
|
|
578
|
+
/** 标签名称 */
|
|
579
|
+
tag_name: string;
|
|
580
|
+
/** 目标提交或分支,默认使用当前分支 */
|
|
581
|
+
target?: string;
|
|
582
|
+
/** 标签消息 */
|
|
583
|
+
message?: string;
|
|
584
|
+
/** 标签注释 */
|
|
585
|
+
annotation?: Record<string, any>;
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* 创建 Blob 参数
|
|
590
|
+
*/
|
|
591
|
+
type CreateBlobData = {
|
|
592
|
+
/** 文件内容 */
|
|
593
|
+
content: string;
|
|
594
|
+
/** 编码格式,默认: utf-8 */
|
|
595
|
+
encoding?: string;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* 查询内容参数
|
|
600
|
+
*/
|
|
601
|
+
type GetContentParams = {
|
|
602
|
+
/** Git 引用,分支名、标签名或提交哈希 */
|
|
603
|
+
ref?: string;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* 查询指定路径内容参数
|
|
608
|
+
*/
|
|
609
|
+
type GetContentWithPathParams = {
|
|
610
|
+
/** Git 引用,分支名、标签名或提交哈希 */
|
|
611
|
+
ref?: string;
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* 获取原始文件参数
|
|
616
|
+
*/
|
|
617
|
+
type GetRawParams = {
|
|
618
|
+
/** 最大 Blob 大小限制(字节) */
|
|
619
|
+
max_in_byte?: number;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* 设置提交注释参数
|
|
624
|
+
*/
|
|
625
|
+
type PutCommitAnnotationsData = {
|
|
626
|
+
/** 注释键值对 */
|
|
627
|
+
annotations: Record<string, string>;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* 批量查询提交注释参数
|
|
632
|
+
*/
|
|
633
|
+
type GetCommitAnnotationsInBatchData = {
|
|
634
|
+
/** 提交哈希值列表 */
|
|
635
|
+
shas: string[];
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* 创建提交附件上传 URL 参数
|
|
640
|
+
*/
|
|
641
|
+
type PostCommitAssetUploadURLData = {
|
|
642
|
+
/** 附件名称 */
|
|
643
|
+
name: string;
|
|
644
|
+
/** 附件路径 */
|
|
645
|
+
path: string;
|
|
646
|
+
/** 内容长度 */
|
|
647
|
+
content_length: number;
|
|
648
|
+
/** 内容类型 */
|
|
649
|
+
content_type: string;
|
|
650
|
+
/** 内容摘要 */
|
|
651
|
+
digest: string;
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* 确认附件上传参数
|
|
656
|
+
*/
|
|
657
|
+
type PostCommitAssetUploadConfirmationParams = {
|
|
658
|
+
/** 附件保持的天数,0 表示永久,最大 180 天 */
|
|
659
|
+
ttl?: number;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* 获取提交附件参数
|
|
664
|
+
*/
|
|
665
|
+
type GetCommitAssetsParams = {
|
|
666
|
+
/** 是否可分享,true 表示下载地址有效期 12 小时,最多下载 10 次 */
|
|
667
|
+
share?: boolean;
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* 设置标签注释参数
|
|
672
|
+
*/
|
|
673
|
+
type PutTagAnnotationsData = {
|
|
674
|
+
/** 注释键值对 */
|
|
675
|
+
annotations: Record<string, string>;
|
|
676
|
+
};
|
package/src/repo/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class Repo extends CNBCore {
|
|
|
23
23
|
return this.post({ url, data: postData });
|
|
24
24
|
}
|
|
25
25
|
deleteRepo(name: string): Promise<any> {
|
|
26
|
-
const url =
|
|
26
|
+
const url = `${this.hackURL}/${name}`;
|
|
27
27
|
return this.delete({ url, useCookie: true });
|
|
28
28
|
}
|
|
29
29
|
async createCommit(repo: string, data: CreateCommitData): Promise<any> {
|
|
@@ -38,7 +38,7 @@ export class Repo extends CNBCore {
|
|
|
38
38
|
if (!data.parent_commit_sha && preCommitSha) {
|
|
39
39
|
data.parent_commit_sha = preCommitSha;
|
|
40
40
|
}
|
|
41
|
-
const url =
|
|
41
|
+
const url = `${this.hackURL}/${repo}/-/git/commits`;
|
|
42
42
|
const postData: CreateCommitData = {
|
|
43
43
|
...data,
|
|
44
44
|
base_branch: data.base_branch || 'refs/heads/main',
|