@cnbcool/cnb-api-generate 2.18.18 → 2.18.20
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.
|
@@ -6,6 +6,7 @@ import { restoreOriginalKeys } from '../utils/restore-original-keys';
|
|
|
6
6
|
import { matchArrayObjectField } from '../utils/match-array-object-field';
|
|
7
7
|
import { isNestedObjectSchema } from '../utils/is-nested-object-schema';
|
|
8
8
|
import { isMapField, getMapValueType } from '../utils/is-map-field';
|
|
9
|
+
import { normalizeAssetPath } from '../utils/normalize-asset-path';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 获取 tool 的参数定义(用于自动分发 --key value 到 path/query)
|
|
@@ -16,6 +17,14 @@ export function getToolParamDefs(moduleName: string, toolName: string) {
|
|
|
16
17
|
return toolHelp.help?.parameter || {};
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 取 tool 的接口路径模板(如 `/{repo}/-/imgs/issues/{img_path}`),
|
|
22
|
+
* 供 img_path / file_path 归一化判断「接口路径已自带哪些前缀」。
|
|
23
|
+
*/
|
|
24
|
+
function getToolPath(moduleName: string, toolName: string): string | undefined {
|
|
25
|
+
return helpData.modulesHelp?.[moduleName]?.[toolName]?.path;
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* 将 body 字段值按 schema 类型写入 target。
|
|
21
30
|
* - array 值:原样保留
|
|
@@ -162,6 +171,7 @@ export function formatParams(
|
|
|
162
171
|
params.module as string,
|
|
163
172
|
params.tool as string,
|
|
164
173
|
);
|
|
174
|
+
const toolPath = getToolPath(params.module as string, params.tool as string);
|
|
165
175
|
|
|
166
176
|
if (paramDefs) {
|
|
167
177
|
const pathDef = paramDefs.path || {};
|
|
@@ -278,7 +288,13 @@ export function formatParams(
|
|
|
278
288
|
if (pathDef[key]) {
|
|
279
289
|
// 归入 path
|
|
280
290
|
if (!formatted.path) formatted.path = {};
|
|
281
|
-
|
|
291
|
+
// img_path / file_path 支持直接粘贴 URL 尾段(可带 issues|pulls 前缀),
|
|
292
|
+
// 按接口路径已自带的前缀剥离,避免拼出重复段导致 404;
|
|
293
|
+
// 不带前缀的接口(Assets 分类)需要完整尾段,保持原样。
|
|
294
|
+
formatted.path[key] =
|
|
295
|
+
key === 'img_path' || key === 'file_path'
|
|
296
|
+
? normalizeAssetPath(value as string, toolPath)
|
|
297
|
+
: value;
|
|
282
298
|
// path 与 query 同名时,query 参数通过 q- 前缀传入(见下方 q- 分支);
|
|
283
299
|
// 但若调用方直接用 --<name> 传了值(旧习惯/兼容),且 queryDef 里也有同名项,
|
|
284
300
|
// 则同时回填到 query,保证 URL 查询参数也被带上。
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 归一化图片 / 附件的路径参数(img_path / file_path)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:正文里的下载地址形如
|
|
5
|
+
* .../-/imgs/issues/<数字 ID>/<key>/<文件名>
|
|
6
|
+
* .../-/files/pulls/<数字 ID>/<key>/<文件名>
|
|
7
|
+
*
|
|
8
|
+
* 用户更自然的做法是直接复制整段 URL 尾段(含 `issues|pulls/` 前缀)粘贴。
|
|
9
|
+
* 但接口路径本身已带前缀的接口(如 `/{repo}/-/imgs/issues/{img_path}`)
|
|
10
|
+
* 若再原样拼接,就会拼出 `.../-/imgs/issues/issues/...` 而 404。
|
|
11
|
+
*
|
|
12
|
+
* 因此按「接口路径已自带哪些前缀」剥离:
|
|
13
|
+
* - `imgs|files` 段:只要接口路径含该段就剥(含 Assets 的 `/{repo}/-/imgs/{imgPath}`)
|
|
14
|
+
* - `issues|pulls` 段:仅当接口路径确实含该段才剥
|
|
15
|
+
*
|
|
16
|
+
* 例(toolPath = `/{repo}/-/imgs/issues/{img_path}`):
|
|
17
|
+
* `issues/66/abc/x.png` → `66/abc/x.png`
|
|
18
|
+
* `imgs/issues/66/abc/x.png` → `66/abc/x.png`
|
|
19
|
+
* `66/abc/x.png` → `66/abc/x.png`
|
|
20
|
+
* 例(toolPath = `/{repo}/-/imgs/{imgPath}`):
|
|
21
|
+
* `issues/66/abc/x.png` → 原样(未剥 scope)
|
|
22
|
+
* `imgs/issues/66/abc/x.png` → `issues/66/abc/x.png`(剥掉 kind)
|
|
23
|
+
*/
|
|
24
|
+
export function normalizeAssetPath(value: string, toolPath?: string): string {
|
|
25
|
+
if (typeof value !== 'string') return value;
|
|
26
|
+
|
|
27
|
+
const path = toolPath || '';
|
|
28
|
+
let stripped = value;
|
|
29
|
+
|
|
30
|
+
/** 若 stripped 以 `<prefix>/` 开头则去掉该段,否则原样返回(大小写不敏感)。 */
|
|
31
|
+
const stripPrefix = (prefix: string) =>
|
|
32
|
+
stripped.toLowerCase().startsWith(`${prefix.toLowerCase()}/`)
|
|
33
|
+
? stripped.slice(prefix.length + 1)
|
|
34
|
+
: stripped;
|
|
35
|
+
|
|
36
|
+
// 按「接口路径自带的前缀」逐段剥;顺序固定为 imgs|files → issues|pulls,
|
|
37
|
+
// 与完整 URL 尾段的出现顺序一致,兼容「只带一段」与「两段都带」两种写法。
|
|
38
|
+
const lowerPath = path.toLowerCase();
|
|
39
|
+
|
|
40
|
+
if (lowerPath.includes('/imgs/')) stripped = stripPrefix('imgs');
|
|
41
|
+
else if (lowerPath.includes('/files/')) stripped = stripPrefix('files');
|
|
42
|
+
|
|
43
|
+
// issues|pulls 段必须确实出现在接口路径里才剥,避免把 Assets 接口要的
|
|
44
|
+
// 完整尾段(`issues/...`)误剥。
|
|
45
|
+
if (lowerPath.includes('/imgs/issues') || lowerPath.includes('/files/issues')) {
|
|
46
|
+
stripped = stripPrefix('issues');
|
|
47
|
+
} else if (lowerPath.includes('/imgs/pulls') || lowerPath.includes('/files/pulls')) {
|
|
48
|
+
stripped = stripPrefix('pulls');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 全部剥掉会得到空串(如用户误传 `issues/`),此时保留原值,交给服务端报错更直观。
|
|
52
|
+
if (stripped.length === 0) return value;
|
|
53
|
+
return stripped;
|
|
54
|
+
}
|
package/package.json
CHANGED
package/quick-commands.json
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
{ "shortName": "upload-file", "realTool": "post-issue-comment-file-asset-upload-url", "description": "上传 issue 评论文件", "upload": true, "kind": "file", "hideInSkill": true, "dataTip": "--file 文件路径" },
|
|
13
13
|
{ "shortName": "upload-image", "realTool": "post-issue-comment-image-asset-upload-url","description": "上传 issue 评论图片", "upload": true, "kind": "image", "hideInSkill": true, "dataTip": "--file 图片路径" },
|
|
14
14
|
{ "shortName": "create-upload-file", "realTool": "post-asset-group", "description": "创建 issue 时上传文件", "upload": true, "kind": "file", "hideInSkill": true, "dataTip": "--file 文件路径" },
|
|
15
|
-
{ "shortName": "create-upload-image", "realTool": "post-asset-group", "description": "创建 issue 时上传图片", "upload": true, "kind": "image", "hideInSkill": true, "dataTip": "--file 图片路径" }
|
|
15
|
+
{ "shortName": "create-upload-image", "realTool": "post-asset-group", "description": "创建 issue 时上传图片", "upload": true, "kind": "image", "hideInSkill": true, "dataTip": "--file 图片路径" },
|
|
16
|
+
{ "shortName": "get-imgs", "realTool": "get-issue-imgs", "description": "获取 issue 图片", "repoOnly": true, "dataTip": "--img-path 图片路径" },
|
|
17
|
+
{ "shortName": "get-files", "realTool": "get-issue-files", "description": "获取 issue 附件", "repoOnly": true, "dataTip": "--file-path 附件路径" }
|
|
16
18
|
],
|
|
17
19
|
"pulls": [
|
|
18
20
|
{ "shortName": "get", "realTool": "get-pull", "description": "获取详情" },
|
|
@@ -29,7 +31,9 @@
|
|
|
29
31
|
{ "shortName": "upload-file", "realTool": "upload-files", "description": "上传文件", "repoOnly": true, "upload": true, "kind": "file", "hideInSkill": true, "dataTip": "--file 文件路径" },
|
|
30
32
|
{ "shortName": "upload-image", "realTool": "upload-imgs", "description": "上传图片", "repoOnly": true, "upload": true, "kind": "image", "hideInSkill": true, "dataTip": "--file 图片路径" },
|
|
31
33
|
{ "shortName": "get-ci-logs", "realTool": "__get-ci-logs__", "description": "获取 CI 失败日志", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" },
|
|
32
|
-
{ "shortName": "get-ci-timing", "realTool": "__get-ci-timing__", "description": "分析 CI 耗时瓶颈", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" }
|
|
34
|
+
{ "shortName": "get-ci-timing", "realTool": "__get-ci-timing__", "description": "分析 CI 耗时瓶颈", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" },
|
|
35
|
+
{ "shortName": "get-imgs", "realTool": "get-pr-imgs", "description": "获取 PR 图片", "repoOnly": true, "dataTip": "--img-path 图片路径" },
|
|
36
|
+
{ "shortName": "get-files", "realTool": "get-pr-files", "description": "获取 PR 附件", "repoOnly": true, "dataTip": "--file-path 附件路径" }
|
|
33
37
|
],
|
|
34
38
|
"skills": [
|
|
35
39
|
{ "shortName": "list", "realTool": "__skills-list__", "description": "列出本地 skills", "custom": true, "dataTip": "-p -a codebuddy --json" }
|
package/skills-template/SKILL.md
CHANGED
|
@@ -30,7 +30,7 @@ description: CNB 平台交互命令,支持代码仓库、Issue、PR、CI、制
|
|
|
30
30
|
- 图片 `.../-/imgs/<issues|pulls>/<数字 ID>/<key>/<文件名>`
|
|
31
31
|
- 附件 `.../-/files/<issues|pulls>/<数字 ID>/<key>/<文件名>`
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
`图片路径/附件路径`=`<issues|pulls>/<数字 ID>/<key>/<文件名>`,即 `参数` 取 `<issues|pulls>/` 开头的**完整尾段**。
|
|
34
34
|
|
|
35
35
|
## 常用链接
|
|
36
36
|
|