@cnbcool/cnb-api-generate 1.0.0
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/README.md +399 -0
- package/bin/cag.js +3 -0
- package/bin/csg.js +3 -0
- package/built/codegen/action/generate-redux-action-ast-node.js +85 -0
- package/built/codegen/action/generate-redux-action-call-api-function-param-ast-node.js +40 -0
- package/built/codegen/action/generate-redux-action-normal-params-ast-node.js +52 -0
- package/built/codegen/action/generate-redux-action-params-binding-element-ast-node.js +40 -0
- package/built/codegen/action/generate-redux-action-params-type-literal-ast-node.js +58 -0
- package/built/codegen/api/generate-api-error-response-ast-node.js +83 -0
- package/built/codegen/api/generate-api-function-ast-node.js +133 -0
- package/built/codegen/api/generate-api-function-request-params-type-ast-node.js +59 -0
- package/built/codegen/api/generate-api-response-return-type-content.js +80 -0
- package/built/codegen/api/generate-api-success-response-ast-node.js +84 -0
- package/built/codegen/api/generate-function-content-ast-node.js +104 -0
- package/built/codegen/api/generate-function-normal-params-ast-node.js +49 -0
- package/built/codegen/api/generate-function-params-ast-node.js +249 -0
- package/built/codegen/api/generate-function-refs-type-params-ast-node.js +102 -0
- package/built/codegen/api/generate-import-ast-node.js +58 -0
- package/built/codegen/api/generate-request-function.js +81 -0
- package/built/codegen/api/generate-request-url-ast-node.js +98 -0
- package/built/codegen/enum/generate-enum-ast-node.js +95 -0
- package/built/codegen/enum/generate-enum-content-ast-node.js +74 -0
- package/built/codegen/interface/generate-import-interface-ast-node.js +47 -0
- package/built/codegen/interface/generate-interface-anchor-ast-node.js +25 -0
- package/built/codegen/interface/generate-interface-ast-node.js +322 -0
- package/built/codegen/interface/generate-interface-desc-ast-node.js +51 -0
- package/built/codegen/interface/generate-interface-entrance.js +110 -0
- package/built/codegen/printer/printer-skill-client-modules.js +58 -0
- package/built/codegen/printer/printer-skills-client-core.js +69 -0
- package/built/codegen/printer/printer-swagger-api-to-file.js +128 -0
- package/built/codegen/printer/printer-swagger-definitions-to-file.js +81 -0
- package/built/codegen/printer/printer-ts-ast-to-js-file.js +72 -0
- package/built/codegen/record/generate-record-anchor-ast-node.js +25 -0
- package/built/codegen/record/generate-record-ast-node.js +134 -0
- package/built/codegen/swagger-definitions-to-ast-node.js +36 -0
- package/built/codegen/types/md-array-type-content-ast-node.js +46 -0
- package/built/constants/actions.js +8 -0
- package/built/constants/definitions.js +20 -0
- package/built/constants/file.js +12 -0
- package/built/constants/index.js +20 -0
- package/built/constants/prettier.js +4 -0
- package/built/constants/request.js +35 -0
- package/built/constants/skills.js +5 -0
- package/built/generate-api.js +36 -0
- package/built/generate-defintions.js +32 -0
- package/built/generate-entrypoint.js +130 -0
- package/built/index.js +19 -0
- package/built/interface/index.js +16 -0
- package/built/skills-tools/generate-config.js +28 -0
- package/built/skills-tools/generate-skill-cli-help.js +156 -0
- package/built/skills-tools/generate-skill-cli-scripts.js +20 -0
- package/built/skills-tools/generate-skill-md.js +25 -0
- package/built/skills.js +36 -0
- package/built/test.js +1 -0
- package/built/utils/camel-to-kebab.js +13 -0
- package/built/utils/comment-line-break.js +6 -0
- package/built/utils/filter-api-param.js +64 -0
- package/built/utils/format-interface-name.js +12 -0
- package/built/utils/format-type-name.js +12 -0
- package/built/utils/gen-operation-id.js +24 -0
- package/built/utils/generate-map-item.js +16 -0
- package/built/utils/get-codegen-target.js +8 -0
- package/built/utils/get-config.js +68 -0
- package/built/utils/get-defintion-name.js +8 -0
- package/built/utils/get-defintion-type.js +13 -0
- package/built/utils/get-generate-license.js +39 -0
- package/built/utils/get-keyword-type-node.js +60 -0
- package/built/utils/get-printer-file-prefix.js +21 -0
- package/built/utils/get-skills-codegen-target.js +15 -0
- package/built/utils/get-swagger-file.js +60 -0
- package/built/utils/inject-param-to-path.js +12 -0
- package/built/utils/is-english-only.js +8 -0
- package/built/utils/is-skills.js +6 -0
- package/built/utils/lower-first-char.js +8 -0
- package/built/utils/path-to-camel-case.js +31 -0
- package/built/utils/progress.js +76 -0
- package/built/utils/to-camel-case.js +8 -0
- package/built/utils/translations-keyworad-to-string.js +55 -0
- package/client/core.ts +114 -0
- package/client/fetch-response-handler.ts +36 -0
- package/client/index.ts +377 -0
- package/client/modules.help.ts +36 -0
- package/client/schemaToJson.ts +26 -0
- package/client/shortcuts.ts +208 -0
- package/client/tools.help.ts +104 -0
- package/client/utils/convert-link.ts +139 -0
- package/client/utils/generate-unique-id.ts +3 -0
- package/package.json +75 -0
- package/skills-template/SKILL.md +100 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import util from 'util';
|
|
2
|
+
import { schemaToJson } from './schemaToJson';
|
|
3
|
+
/**
|
|
4
|
+
* 显示工具帮助文档
|
|
5
|
+
* @param helpData 帮助数据
|
|
6
|
+
* @param moduleName 模块名称
|
|
7
|
+
* @param tool 工具名称
|
|
8
|
+
*/
|
|
9
|
+
export function showToolHelp(
|
|
10
|
+
helpData: any,
|
|
11
|
+
moduleName: string,
|
|
12
|
+
tool: string,
|
|
13
|
+
): void {
|
|
14
|
+
const toolHelpData = helpData.modulesHelp[moduleName][tool];
|
|
15
|
+
if (!toolHelpData) {
|
|
16
|
+
console.error(`工具 ${tool} 不存在`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { summary, description, help } = toolHelpData;
|
|
21
|
+
const { parameter } = help;
|
|
22
|
+
const { path, query, body } = parameter;
|
|
23
|
+
|
|
24
|
+
// path参数说明
|
|
25
|
+
let pathMsg = '';
|
|
26
|
+
const pathParamsExample: Record<string, string> = {};
|
|
27
|
+
if (path) {
|
|
28
|
+
pathMsg = `--path参数详细说明:
|
|
29
|
+
${Object.keys(path)
|
|
30
|
+
.map((key) => {
|
|
31
|
+
if (path[key].required) {
|
|
32
|
+
pathParamsExample[key] = `<${path[key].type}>`;
|
|
33
|
+
}
|
|
34
|
+
return ` - ${key} (${path[key].type}) - ${path[key].description}(${path[key].required ? '必填' : '选填'})`;
|
|
35
|
+
})
|
|
36
|
+
.join('\n')}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// query参数说明
|
|
41
|
+
let queryMsg = '';
|
|
42
|
+
const queryParamsExample: Record<string, string> = {};
|
|
43
|
+
if (query) {
|
|
44
|
+
queryMsg = `--query详细参数:
|
|
45
|
+
${Object.keys(query)
|
|
46
|
+
.map((key) => {
|
|
47
|
+
if (query[key].required) {
|
|
48
|
+
queryParamsExample[key] = `<${query[key].type}>`;
|
|
49
|
+
} else if (query[key].default !== undefined) {
|
|
50
|
+
queryParamsExample[key] = query[key].default;
|
|
51
|
+
}
|
|
52
|
+
return ` - ${key} (${query[key].type}) - ${query[key].description}(${query[key].required ? '必填' : '选填'})${query[key].enum ? `, [枚举: ${query[key].enum.join(', ')}]` : ''}`;
|
|
53
|
+
})
|
|
54
|
+
.join('\n')}
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// data参数说明
|
|
59
|
+
let bodyMsg = '';
|
|
60
|
+
let bodyParamsExample: Record<string, string> = {};
|
|
61
|
+
if (body) {
|
|
62
|
+
const { type, description, required, schema } = body;
|
|
63
|
+
if (schema) {
|
|
64
|
+
bodyParamsExample = schemaToJson(schema, {});
|
|
65
|
+
bodyMsg = `--data参数详细说明:
|
|
66
|
+
${util.inspect(schema, { showHidden: false, depth: null })}`;
|
|
67
|
+
} else {
|
|
68
|
+
bodyMsg = `--data参数详细说明:
|
|
69
|
+
- ${type} - ${description}(${required ? '必填' : '选填'})
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const exampleMsg = [
|
|
75
|
+
`node ./skills/scripts/core ${moduleName} ${tool}`,
|
|
76
|
+
];
|
|
77
|
+
if (Object.keys(pathParamsExample).length > 0) {
|
|
78
|
+
exampleMsg.push(`--path '${JSON.stringify(pathParamsExample)}'`);
|
|
79
|
+
}
|
|
80
|
+
if (Object.keys(queryParamsExample).length > 0) {
|
|
81
|
+
exampleMsg.push(`--query '${JSON.stringify(queryParamsExample)}'`);
|
|
82
|
+
}
|
|
83
|
+
if (Object.keys(bodyParamsExample).length > 0) {
|
|
84
|
+
exampleMsg.push(`--data '${JSON.stringify(bodyParamsExample)}'`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const helpMeg = `
|
|
88
|
+
工具${tool}帮助文档\n
|
|
89
|
+
工具说明:
|
|
90
|
+
1. ${summary}
|
|
91
|
+
2. ${description}
|
|
92
|
+
\n参数说明:
|
|
93
|
+
<module> (必须) 模块名称 (例如: issues),可直接配合 --help 查看该模块帮助
|
|
94
|
+
<tool> (必须) 工具/动作名称 (例如: list-issues)
|
|
95
|
+
--path (可选) 路径参数,JSON字符串
|
|
96
|
+
--query (可选) 查询参数,JSON字符串
|
|
97
|
+
--data (可选) 数据参数,JSON字符串
|
|
98
|
+
--help (可选) 显示此帮助文档
|
|
99
|
+
${pathMsg && `\n${pathMsg}`}${queryMsg && `\n${queryMsg}`}${bodyMsg && `\n${bodyMsg}`}
|
|
100
|
+
\n使用示例:
|
|
101
|
+
${exampleMsg.join(' ')}
|
|
102
|
+
`;
|
|
103
|
+
console.log(helpMeg);
|
|
104
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把文本里的相对路径转换为绝对路径
|
|
3
|
+
* 与 src/helpers/convertLink.ts 逻辑一致
|
|
4
|
+
*
|
|
5
|
+
* @param {String} text 待转换的文本
|
|
6
|
+
* @param {String} repoSlug 仓库路径
|
|
7
|
+
* @param {String} branchOrSha 可选,分支或SHA
|
|
8
|
+
* @returns {String}
|
|
9
|
+
*/
|
|
10
|
+
export default function convertLink(text: string, repoSlug: string | undefined, branchOrSha: string | undefined) {
|
|
11
|
+
// 查询所有代码块的位置
|
|
12
|
+
let codeBlockPositions = [];
|
|
13
|
+
let index = 0;
|
|
14
|
+
while (index !== -1) {
|
|
15
|
+
const nextIndex = text.indexOf('```', index);
|
|
16
|
+
if (nextIndex === -1) break;
|
|
17
|
+
codeBlockPositions.push(nextIndex);
|
|
18
|
+
index = nextIndex + 3; // 跳过已匹配的三个反引号
|
|
19
|
+
}
|
|
20
|
+
if (codeBlockPositions.length % 2 !== 0) {
|
|
21
|
+
codeBlockPositions = codeBlockPositions.slice(0, codeBlockPositions.length - 1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 查询所有行内代码块的位置
|
|
25
|
+
let inlineCodeBlockPositions = [];
|
|
26
|
+
index = 0;
|
|
27
|
+
while (index < text.length) {
|
|
28
|
+
const nextIndex = text.indexOf('`', index);
|
|
29
|
+
if (nextIndex === -1) break;
|
|
30
|
+
// 检查是否是单独的反引号(不是代码块的一部分)
|
|
31
|
+
if (
|
|
32
|
+
(nextIndex === 0 || text.charAt(nextIndex - 1) !== '`') &&
|
|
33
|
+
(nextIndex === text.length - 1 || text.charAt(nextIndex + 1) !== '`')
|
|
34
|
+
) {
|
|
35
|
+
inlineCodeBlockPositions.push(nextIndex);
|
|
36
|
+
}
|
|
37
|
+
index = nextIndex + 1;
|
|
38
|
+
}
|
|
39
|
+
if (inlineCodeBlockPositions.length % 2 !== 0) {
|
|
40
|
+
inlineCodeBlockPositions = inlineCodeBlockPositions.slice(0, inlineCodeBlockPositions.length - 1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 整理起始和结束位置
|
|
44
|
+
const excludedRanges = [...codeBlockPositions, ...inlineCodeBlockPositions].reduce((result: any[], item, index) => {
|
|
45
|
+
if (index % 2 === 0) {
|
|
46
|
+
return result.concat([[item]]);
|
|
47
|
+
} else {
|
|
48
|
+
result[result.length - 1].push(item);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
// Helper function to check if an index is within excluded ranges
|
|
54
|
+
const isInExcludedRange = (index: number) => {
|
|
55
|
+
return excludedRanges.some(([start, end]) => index >= start && index < end);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let match;
|
|
59
|
+
|
|
60
|
+
// Collect all replacements with their positions
|
|
61
|
+
const replacements = [];
|
|
62
|
+
|
|
63
|
+
// Match markdown links and images: [alt](url), [](url),  and 
|
|
64
|
+
const markdownLinkRegex = /!?\[([^\]]*)\]\(([^)]+)\)/g;
|
|
65
|
+
while ((match = markdownLinkRegex.exec(text)) !== null) {
|
|
66
|
+
if (!isInExcludedRange(match.index)) {
|
|
67
|
+
// Calculate URL position: match.index + length of "![" + match[1] + "]("
|
|
68
|
+
const prefixLength = (match[0].startsWith('!') ? 1 : 0) + 1 + match[1].length + 2;
|
|
69
|
+
const urlStart = match.index + prefixLength;
|
|
70
|
+
const urlEnd = urlStart + match[2].length;
|
|
71
|
+
const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
|
|
72
|
+
if (newUrl !== match[2]) {
|
|
73
|
+
replacements.push({ start: urlStart, end: urlEnd, newUrl });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Match HTML tags: <img src="..."> and <a href="...">
|
|
79
|
+
const htmlTagRegex = /\s(src|href)=["']([^"']+)["']/gi;
|
|
80
|
+
while ((match = htmlTagRegex.exec(text)) !== null) {
|
|
81
|
+
if (!isInExcludedRange(match.index)) {
|
|
82
|
+
const urlStart = match.index + match[0].indexOf(match[2]);
|
|
83
|
+
const urlEnd = urlStart + match[2].length;
|
|
84
|
+
const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
|
|
85
|
+
if (newUrl !== match[2]) {
|
|
86
|
+
replacements.push({ start: urlStart, end: urlEnd, newUrl });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Sort replacements by start position in descending order
|
|
92
|
+
replacements.sort((a, b) => b.start - a.start);
|
|
93
|
+
|
|
94
|
+
// Apply replacements from end to start to maintain correct indices
|
|
95
|
+
let result = text;
|
|
96
|
+
for (const { start, end, newUrl } of replacements) {
|
|
97
|
+
result = result.substring(0, start) + newUrl + result.substring(end);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 相对路径转换为绝对路径
|
|
105
|
+
* 与 src/helpers/convertLink.ts 逻辑一致
|
|
106
|
+
*
|
|
107
|
+
* @param {String} link 待转换的链接
|
|
108
|
+
* @param {String} repoSlug 仓库路径
|
|
109
|
+
* @param {String} branchOrSha 分支或SHA,默认为 HEAD
|
|
110
|
+
* @returns {String}
|
|
111
|
+
*/
|
|
112
|
+
function normaliseLink(link: string, repoSlug: string | undefined, branchOrSha = 'HEAD') {
|
|
113
|
+
const { CNB_WEB_ENDPOINT } = process.env;
|
|
114
|
+
const baseURL = `${CNB_WEB_ENDPOINT}/${repoSlug}`;
|
|
115
|
+
|
|
116
|
+
if (link.startsWith('/-/')) {
|
|
117
|
+
return `${baseURL}${link}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
link.indexOf('/-/') === -1 &&
|
|
122
|
+
(
|
|
123
|
+
link.startsWith('../') ||
|
|
124
|
+
link.startsWith('./') ||
|
|
125
|
+
(link.startsWith('/') && !link.startsWith('//'))
|
|
126
|
+
)
|
|
127
|
+
) {
|
|
128
|
+
let chunks = link.split('/');
|
|
129
|
+
// 过滤掉空字符串和 . .. 这些无效路径
|
|
130
|
+
chunks = chunks.filter((chunk) => !!chunk && chunk !== '.' && chunk !== '..');
|
|
131
|
+
if (chunks.length === 0) {
|
|
132
|
+
return link;
|
|
133
|
+
}
|
|
134
|
+
chunks.unshift(branchOrSha);
|
|
135
|
+
return `${baseURL}/-/git/raw/${chunks.join('/')}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return link;
|
|
139
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cnbcool/cnb-api-generate",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./built/index.js",
|
|
5
|
+
"module": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"bin": {
|
|
9
|
+
"cag": "bin/cag.js",
|
|
10
|
+
"csg": "bin/csg.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://cnb.cool/cnb/skills/cnb-api-generate"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "npx nodemon",
|
|
18
|
+
"dev:csg": "npx nodemon --config nodemon-skills.json",
|
|
19
|
+
"build": "rm -rf ./built && tsc --build tsconfig.build.json",
|
|
20
|
+
"lint": "eslint './src/**/*.{ts,tsx}' --quiet",
|
|
21
|
+
"lint:gen": "eslint './generated/**/*.{ts,tsx}' --quiet",
|
|
22
|
+
"ts:gen": "tsc --noEmit -p tsconfig.generated.json",
|
|
23
|
+
"check:gen": "yarn lint:gen && yarn ts:gen",
|
|
24
|
+
"lint:fix": "eslint src --fix",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"test:cover": "jest --coverage",
|
|
27
|
+
"gen:test": "npx swagger-typescript-api generate --path ./template/swagger.json --axios --extract-request-body --extract-response-body --extract-request-params --extract-response-error -o ./test"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@babel/core": "^7.29.0",
|
|
31
|
+
"@babel/generator": "^7.29.1",
|
|
32
|
+
"@babel/parser": "^7.29.0",
|
|
33
|
+
"@babel/preset-env": "^7.29.0",
|
|
34
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
35
|
+
"@babel/traverse": "^7.29.0",
|
|
36
|
+
"@types/cli-progress": "^3.11.6",
|
|
37
|
+
"@types/lodash": "4.17.20",
|
|
38
|
+
"babel-plugin-transform-define": "^2.1.4",
|
|
39
|
+
"cli-progress": "^3.12.0",
|
|
40
|
+
"debug": "4.4.1",
|
|
41
|
+
"glob": "^13.0.1",
|
|
42
|
+
"lodash": "^4.17.23",
|
|
43
|
+
"ora": "5.4.1",
|
|
44
|
+
"prettier": "3.4.2",
|
|
45
|
+
"rimraf": "6.0.1",
|
|
46
|
+
"typescript": "5.9.3"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@reduxjs/toolkit": "^1.9.5",
|
|
50
|
+
"@tencent/eslint-config-tencent": "^1.1.3",
|
|
51
|
+
"@types/debug": "4.1.12",
|
|
52
|
+
"@types/jest": "^29.5.3",
|
|
53
|
+
"@types/node": "24.0.12",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "8.48.1",
|
|
55
|
+
"@typescript-eslint/parser": "8.48.1",
|
|
56
|
+
"axios": "^1.13.6",
|
|
57
|
+
"eslint": "8.57.0",
|
|
58
|
+
"eslint-config-prettier": "9.1.0",
|
|
59
|
+
"eslint-config-turbo": "2.2.3",
|
|
60
|
+
"eslint-plugin-prettier": "5.2.1",
|
|
61
|
+
"jest": "^29.6.1",
|
|
62
|
+
"nodemon": "3.1.10",
|
|
63
|
+
"react-redux": "^8.0.7",
|
|
64
|
+
"ts-jest": "^29.1.1",
|
|
65
|
+
"ts-node": "10.9.2"
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"built",
|
|
69
|
+
"bin",
|
|
70
|
+
"package.json",
|
|
71
|
+
"skills-template",
|
|
72
|
+
"client",
|
|
73
|
+
"README.md"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cnb-skill
|
|
3
|
+
description: 提供与CNB(Cloud Native Build)OpenAPI的完整交互能力,支持项目、组织、代码仓库、Issue、PR、合并请求、流水线,制品库等核心功能的增删改查操作。适用于开发协作、代码管理和CI/CD流程管理场景。关键词:CNB、云原生构建、组织、代码仓库、Issue、PR、合并请求、流水线、制品库,查询、新增、修改、删除、评论、合并、审批。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cnb-skill
|
|
7
|
+
|
|
8
|
+
## 概括
|
|
9
|
+
|
|
10
|
+
本Skill提供完整的CNB的Openapi完整交互能力,用户可以使用此skills对CNB上的资源进行操作。
|
|
11
|
+
|
|
12
|
+
## 适用场景
|
|
13
|
+
|
|
14
|
+
当用户描述对CNB上的资源进行操作时,应该使用此skills进行操作。例如:
|
|
15
|
+
- 查询cnb上某个仓库的Issue列表
|
|
16
|
+
- 对cnb上的某个仓库的Issue或者pr进行评论。
|
|
17
|
+
- ...
|
|
18
|
+
|
|
19
|
+
## 核心原则
|
|
20
|
+
|
|
21
|
+
### 准确性原则
|
|
22
|
+
- **CRITICAL**: 必须先执行 `<$CNB_CLI_CMD$> --help` 获取最新的使用方式
|
|
23
|
+
- **CRITICAL**: 必须通过使用 `<$CNB_CLI_CMD$>`命令行工具,按照帮助信息执行操作
|
|
24
|
+
- **CRITICAL**: 禁止推测或臆断使用方式,严格基于脚本返回的帮助信息进行操作
|
|
25
|
+
- **CRITICAL**: 不要询问用户"是否需要我执行",直接根据帮助信息执行脚本,并返回结果
|
|
26
|
+
|
|
27
|
+
## 脚本使用指南
|
|
28
|
+
|
|
29
|
+
### 第一步:获取帮助信息
|
|
30
|
+
在执行任何任务前,必须先运行以下命令获取最新的使用方式:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
<$CNB_CLI_CMD$> --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
这将显示所有可用的模块及其工具列表。
|
|
37
|
+
|
|
38
|
+
### 第二步:查看具体模块帮助
|
|
39
|
+
使用 `--module` 参数查看特定模块的详细帮助:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
<$CNB_CLI_CMD$> --module <模块名> -help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 第三步:查看工具详细使用
|
|
46
|
+
使用 `--module` 和 `--tool` 参数查看工具的详细参数说明:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
<$CNB_CLI_CMD$> --module <模块名> --tool <工具名> --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 第四步:执行工具
|
|
53
|
+
根据第三步获取的参数说明,执行工具:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
<$CNB_CLI_CMD$> --module <模块名> --tool <工具名> --path '{"参数": "值"}' --query '{"参数": "值"}' --data '{"参数": "值"}'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**参数说明:**
|
|
60
|
+
- `--module`: 必须参数,模块名称
|
|
61
|
+
- `--tool`: 必须参数,工具名称
|
|
62
|
+
- `--path`: 可选参数,路径参数,JSON字符串格式
|
|
63
|
+
- `--query`: 可选参数,查询参数,JSON字符串格式
|
|
64
|
+
- `--data`: 可选参数,数据参数,JSON字符串格式
|
|
65
|
+
- `--help`: 可选参数,显示帮助文档
|
|
66
|
+
|
|
67
|
+
### 第五步:处理结果
|
|
68
|
+
|
|
69
|
+
每一个工具调用都会返回一个标准的JSON结构:
|
|
70
|
+
- status: 一个http状态码
|
|
71
|
+
- trace: 本次调用的traceID
|
|
72
|
+
- header: 本次调用的header
|
|
73
|
+
- data: 本次调用的openapi返回的实体内容
|
|
74
|
+
|
|
75
|
+
#### header说明
|
|
76
|
+
当请求列表时,会在header中包含以下字段说明列表的情况:
|
|
77
|
+
- `x-cnb-page`: 当前页数
|
|
78
|
+
- `x-cnb-page-size`: 每页条数
|
|
79
|
+
- `x-cnb-total`: 总条数
|
|
80
|
+
|
|
81
|
+
从中可以获取到列表的总条数,以及当前页数和每页条数,避免循环请求。
|
|
82
|
+
|
|
83
|
+
#### status说明
|
|
84
|
+
API 返回标准的 JSON 格式响应。请根据 HTTP 状态码判断请求是否成功:
|
|
85
|
+
|
|
86
|
+
- 200: 请求成功
|
|
87
|
+
- 400: 请求参数错误
|
|
88
|
+
- 401: 未授权
|
|
89
|
+
- 403: 禁止访问
|
|
90
|
+
- 404: 资源不存在
|
|
91
|
+
- 500: 服务器内部错误
|
|
92
|
+
|
|
93
|
+
当本地调用返回的 `status` 在 200 ~ 299 之间,只需要返回 `data` 内容给用户。只有当 `status >= 300` 时,才将 `status` 和 `trace` 返回给用户。
|
|
94
|
+
|
|
95
|
+
#### 资源处理
|
|
96
|
+
|
|
97
|
+
当尝试下载图片进行图片分析时,遇到图片下载异常时,请使用以下工具进行图片下载!
|
|
98
|
+
```bash
|
|
99
|
+
node scripts/core/index.js assets get-imgs --help
|
|
100
|
+
```
|