@cnbcool/cnb-api-generate 2.20.1 → 2.21.1

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.
@@ -114,7 +114,8 @@ export async function executeAction(
114
114
  const result = await diagnoseBuild({
115
115
  repo: (params.repo as string) || '',
116
116
  sn: (opts.sn as string) || undefined,
117
- prNumber: process.env.CNB_PULL_REQUEST_IID || undefined,
117
+ // --number 显式传入时优先,未传时由 autoPath 用 CNB_PULL_REQUEST_IID 兜底
118
+ prNumber: (params.number as string) || undefined,
118
119
  });
119
120
  console.log(result);
120
121
  return;
@@ -124,7 +125,8 @@ export async function executeAction(
124
125
  const result = await analyzeBuildTiming({
125
126
  repo: (params.repo as string) || '',
126
127
  sn: (opts.sn as string) || undefined,
127
- prNumber: process.env.CNB_PULL_REQUEST_IID || undefined,
128
+ // --number 显式传入时优先,未传时由 autoPath 用 CNB_PULL_REQUEST_IID 兜底
129
+ prNumber: (params.number as string) || undefined,
128
130
  });
129
131
  console.log(result);
130
132
  return;
@@ -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,17 @@ 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 / PR 两侧参数形态,但只有 issue 评论上传会消费:
205
207
  // - post-issue-comment-*-asset-upload-url(issue 评论上传):path 为 repo + number
206
- // - post-asset-group(创建 issue 时上传):path 只有 repo,number 传了也会被忽略
207
- // - pull 侧 upload-files / upload-imgs:按仓库维度上传,同样不需要 number
208
- const needNumber = shortcut.realTool !== 'post-asset-group' && !shortcut.repoOnly;
209
- registerAutoInjectedPathOptions(shortcutCmd, needNumber);
208
+ // - post-asset-group / pull 侧 upload-*:path 只有 repo,number 传了也被忽略
209
+ registerAutoInjectedPathOptions(shortcutCmd);
210
210
  } else if (
211
211
  shortcut.realTool === '__get-ci-logs__' ||
212
212
  shortcut.realTool === '__get-ci-timing__'
213
213
  ) {
214
214
  shortcutCmd.option('--sn <string>', '构建号(可选,默认自动从环境变量或 PR 状态获取)');
215
- // CI 命令按仓库维度查询,允许显式覆盖环境变量中的仓库
216
- shortcutCmd.option('--repo <string>', '仓库名称(可选,默认取 CNB_REPO_SLUG)');
215
+ // CI 命令按 PR 维度查询,--number 会作为 prNumber 参与查询(见 execute-action)
216
+ registerAutoInjectedPathOptions(shortcutCmd);
217
217
  } else {
218
218
  registerToolOptions(shortcutCmd, moduleName, shortcut.realTool, true);
219
219
  }
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.1",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",