@hangox/pm-cli 1.2.2 → 1.2.3

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/index.js CHANGED
@@ -530,8 +530,40 @@ function outputError(error, pretty = false) {
530
530
  const finalResult = addKeyMappingToResult(result);
531
531
  console.log(JSON.stringify(finalResult, null, pretty ? 2 : 0));
532
532
  }
533
+ function extractNestedErrorMsg(errorObj) {
534
+ if (!errorObj || typeof errorObj !== "object") return null;
535
+ const obj = errorObj;
536
+ const issues = obj.data?.errors?.issue;
537
+ if (Array.isArray(issues) && issues.length > 0) {
538
+ return issues.map((e) => `${e.name} ${e.msg}`).join(", ");
539
+ }
540
+ if (typeof obj.res_msg === "string") return obj.res_msg;
541
+ return null;
542
+ }
533
543
  function extractErrorMessage(result, defaultMsg = "\u64CD\u4F5C\u5931\u8D25") {
534
- return result.post_error_msg || result.api_error_msg || result.message || result.msg || defaultMsg;
544
+ if (result.post_error_msg && typeof result.post_error_msg === "string") return result.post_error_msg;
545
+ if (result.api_error_msg) {
546
+ if (typeof result.api_error_msg === "string") return result.api_error_msg;
547
+ const nested = extractNestedErrorMsg(result.api_error_msg);
548
+ if (nested) return nested;
549
+ }
550
+ return result.message || result.msg || defaultMsg;
551
+ }
552
+ function parseRequiredFieldErrors(errorMsg) {
553
+ const pattern = /(?:^|[,,;;\s])([^,,;;]+?)\s*(?:不能为空字符|不能留空)/g;
554
+ const fields = [];
555
+ let match;
556
+ while ((match = pattern.exec(errorMsg)) !== null) {
557
+ fields.push(match[1].trim());
558
+ }
559
+ return fields;
560
+ }
561
+ function enrichErrorWithFieldHint(errorMsg) {
562
+ const fields = parseRequiredFieldErrors(errorMsg);
563
+ if (fields.length === 0) return errorMsg;
564
+ const hints = fields.map((f) => `"${f}"`).join(", ");
565
+ return `${errorMsg}
566
+ [\u63D0\u793A] \u5FC5\u586B\u5B57\u6BB5 ${hints} \u672A\u586B\u5199\u3002\u8BF7\u7528 --cf "\u5B57\u6BB5ID=\u503C" \u6307\u5B9A\uFF0C\u6267\u884C pm-cli issue field-options \u67E5\u770B\u53EF\u7528\u503C`;
535
567
  }
536
568
 
537
569
  // src/commands/test.ts
@@ -1675,13 +1707,16 @@ var IssueService = class {
1675
1707
  const errorMsg = createResult.post_error_msg || createResult.api_error_msg || createResult.message || "\u521B\u5EFA\u5931\u8D25";
1676
1708
  logger_default.error(`\u274C \u521B\u5EFA\u5B50\u4EFB\u52A1\u5931\u8D25: ${taskName}`, errorMsg);
1677
1709
  result.totalFailed++;
1710
+ const fieldHint = this.parseRequiredFieldHint(errorMsg);
1678
1711
  result.failed.push({
1679
1712
  subject: taskName,
1680
1713
  parentId: targetParentId,
1681
- error: errorMsg
1714
+ error: errorMsg,
1715
+ ...fieldHint ? { requiredFieldHint: fieldHint } : {}
1682
1716
  });
1683
1717
  const progress = result.totalCreated + result.totalFailed;
1684
- console.error(`[${progress}/${result.totalTasks}] \u274C \u521B\u5EFA\u5931\u8D25: ${taskName} - ${errorMsg}`);
1718
+ const hintSuffix = fieldHint ? ` (${fieldHint})` : "";
1719
+ console.error(`[${progress}/${result.totalTasks}] \u274C \u521B\u5EFA\u5931\u8D25: ${taskName} - ${errorMsg}${hintSuffix}`);
1685
1720
  }
1686
1721
  } catch (error) {
1687
1722
  const errorMsg = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
@@ -1699,6 +1734,16 @@ var IssueService = class {
1699
1734
  }
1700
1735
  }
1701
1736
  }
1737
+ /**
1738
+ * 解析必填字段错误,生成提示信息
1739
+ * 复用 output.ts 的 parseRequiredFieldErrors 保持正则一致
1740
+ */
1741
+ parseRequiredFieldHint(errorMsg) {
1742
+ const fields = parseRequiredFieldErrors(errorMsg);
1743
+ if (fields.length === 0) return null;
1744
+ const hints = fields.map((f) => `"${f}"`).join(", ");
1745
+ return `\u5FC5\u586B\u5B57\u6BB5 ${hints} \u672A\u586B\u5199\u3002\u8BF7\u7528 --cf "\u5B57\u6BB5ID=\u503C" \u6307\u5B9A\uFF0C\u6267\u884C pm-cli issue field-options \u67E5\u770B\u53EF\u7528\u503C`;
1746
+ }
1702
1747
  };
1703
1748
  var issueService = new IssueService();
1704
1749
 
@@ -2184,7 +2229,8 @@ function createIssueCommand() {
2184
2229
  if (result.success && result.data) {
2185
2230
  outputSuccess(result.data, options.pretty);
2186
2231
  } else {
2187
- outputError(extractErrorMessage(result, "\u521B\u5EFA\u95EE\u9898\u5931\u8D25"), options.pretty);
2232
+ const errMsg = extractErrorMessage(result, "\u521B\u5EFA\u95EE\u9898\u5931\u8D25");
2233
+ outputError(enrichErrorWithFieldHint(errMsg), options.pretty);
2188
2234
  process.exit(1);
2189
2235
  }
2190
2236
  });
@@ -2303,7 +2349,8 @@ function createIssueCommand() {
2303
2349
  if (result.success && result.data) {
2304
2350
  outputSuccess(result.data, options.pretty);
2305
2351
  } else {
2306
- outputError(extractErrorMessage(result, "\u66F4\u65B0\u95EE\u9898\u5931\u8D25"), options.pretty);
2352
+ const errMsg = extractErrorMessage(result, "\u66F4\u65B0\u95EE\u9898\u5931\u8D25");
2353
+ outputError(enrichErrorWithFieldHint(errMsg), options.pretty);
2307
2354
  process.exit(1);
2308
2355
  }
2309
2356
  });