@cnbcool/cnb-api-generate 2.20.1 → 2.21.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.
@@ -32,15 +32,17 @@ const AUTO_INJECTED_DISPLAY_KEYS = new Set(['repo', 'number', 'review-id']);
32
32
 
33
33
  /**
34
34
  * 为不走 registerToolOptions 的快捷命令(upload / CI 自定义命令)注册
35
- * 由环境变量自动注入的 path 参数,使其可被显式覆盖。
36
- * - repo:始终注册,未传时由 autoPath 从 CNB_REPO_SLUG 回填
37
- * - number:仅在命令所属接口真的需要 number 时注册,避免帮助里出现「有选项但静默无效」
35
+ * 由环境变量自动注入的 path 参数,使其可被显式覆盖(未传时由 autoPath 从环境变量回填)。
36
+ * - repo:所有快捷命令都注册
37
+ * - number:对所有快捷命令都注册,但只有接口真的消费 number 时才有意义
38
+ *
39
+ * number 的注册遵循「统一接口形态」:Issue 与 PR 两侧的快捷命令参数保持一致,
40
+ * 便于 NPC 用同一套写法(`--repo x/y --number 99`)在两种场景间迁移。
41
+ * 消费方(upload / CI 分支)只取自己需要的字段,多传不会改变任何请求。
38
42
  */
39
- function registerAutoInjectedPathOptions(cmd: Command, needNumber?: boolean): void {
43
+ function registerAutoInjectedPathOptions(cmd: Command): void {
40
44
  cmd.option('--repo <string>', '仓库名称(可选,默认取 CNB_REPO_SLUG)');
41
- if (needNumber) {
42
- cmd.option('--number <string>', '编号(可选,默认取 CNB_ISSUE_IID / CNB_PULL_REQUEST_IID)');
43
- }
45
+ cmd.option('--number <string>', '编号(可选,默认取 CNB_ISSUE_IID / CNB_PULL_REQUEST_IID)');
44
46
  }
45
47
 
46
48
  /**
@@ -201,19 +203,18 @@ export function registerModuleCommands(program: Command): void {
201
203
  // 按命令类别注册选项:upload / ci 自定义 / 普通 swagger 命令
202
204
  if (shortcut.upload) {
203
205
  shortcutCmd.requiredOption('--file <string>', '本地文件路径。必填。');
204
- // 是否需要 number 由接口本身决定,而非 shortcut.repoOnly:
206
+ // --number 一律注册,但只有 issue 评论上传会消费:
205
207
  // - post-issue-comment-*-asset-upload-url(issue 评论上传):path 为 repo + number
206
208
  // - post-asset-group(创建 issue 时上传):path 只有 repo,number 传了也会被忽略
207
209
  // - pull 侧 upload-files / upload-imgs:按仓库维度上传,同样不需要 number
208
- const needNumber = shortcut.realTool !== 'post-asset-group' && !shortcut.repoOnly;
209
- registerAutoInjectedPathOptions(shortcutCmd, needNumber);
210
+ registerAutoInjectedPathOptions(shortcutCmd);
210
211
  } else if (
211
212
  shortcut.realTool === '__get-ci-logs__' ||
212
213
  shortcut.realTool === '__get-ci-timing__'
213
214
  ) {
214
215
  shortcutCmd.option('--sn <string>', '构建号(可选,默认自动从环境变量或 PR 状态获取)');
215
- // CI 命令按仓库维度查询,允许显式覆盖环境变量中的仓库
216
- shortcutCmd.option('--repo <string>', '仓库名称(可选,默认取 CNB_REPO_SLUG)');
216
+ // CI 命令按 PR 维度查询,同样注册 --number 保持两侧参数形态一致
217
+ registerAutoInjectedPathOptions(shortcutCmd);
217
218
  } else {
218
219
  registerToolOptions(shortcutCmd, moduleName, shortcut.realTool, true);
219
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.20.1",
3
+ "version": "2.21.0",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",