ai-project-manage-cli 4.0.3 → 4.0.5

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.
Files changed (2) hide show
  1. package/dist/index.js +54 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -121,6 +121,10 @@ var requestConfig = {
121
121
  method: "GET",
122
122
  path: "/requirement-artifacts/list"
123
123
  }),
124
+ get: defineEndpoint({
125
+ method: "GET",
126
+ path: "/requirement-artifacts/get"
127
+ }),
124
128
  create: defineEndpoint({
125
129
  method: "POST",
126
130
  path: "/requirement-artifacts/create"
@@ -443,6 +447,38 @@ async function runUploadArtifact(requirementId, workspaceDir) {
443
447
  import { writeFileSync as writeFileSync2 } from "fs";
444
448
  import { join as join4 } from "path";
445
449
  import { stringify as yamlStringify } from "yaml";
450
+ var PULL_ARTIFACT_FILE_NAMES = ["api.md", "backend.md"];
451
+ function normalizeArtifactPath(fileName) {
452
+ return fileName.trim().replace(/\\/g, "/").replace(/^\/+/, "");
453
+ }
454
+ function artifactFileNameMatches(itemFileName, targetFileName) {
455
+ const norm = normalizeArtifactPath(itemFileName);
456
+ const target = normalizeArtifactPath(targetFileName);
457
+ if (norm === target) return true;
458
+ const base = norm.split("/").filter(Boolean).pop() ?? norm;
459
+ return base === target;
460
+ }
461
+ async function fetchArtifactContentByFileName(api, requirementId, fileName) {
462
+ const pageSize = 500;
463
+ let page = 1;
464
+ const items = [];
465
+ while (true) {
466
+ const batch = await api.requirementArtifact.list({
467
+ requirementId,
468
+ page,
469
+ pageSize
470
+ });
471
+ items.push(...batch.items);
472
+ if (batch.total === 0 || items.length >= batch.total) break;
473
+ page += 1;
474
+ }
475
+ const hit = items.find(
476
+ (item) => artifactFileNameMatches(item.fileName, fileName)
477
+ );
478
+ if (!hit) return null;
479
+ const art = await api.requirementArtifact.get({ artifactId: hit.id });
480
+ return art.content;
481
+ }
446
482
  function valueToXmlContent(value) {
447
483
  if (value === null || value === void 0) return "";
448
484
  if (typeof value === "string") return xmlEscape(value);
@@ -554,6 +590,16 @@ async function runPull(requirementId, workspaceDir) {
554
590
  data.testCases ?? []
555
591
  );
556
592
  writeFileSync2(join4(WORKITEMS_DIR, "testcase.xml"), testCasesXml, "utf8");
593
+ for (const fileName of PULL_ARTIFACT_FILE_NAMES) {
594
+ const content = await fetchArtifactContentByFileName(
595
+ api,
596
+ requirementId,
597
+ fileName
598
+ );
599
+ if (content !== null) {
600
+ writeFileSync2(join4(WORKITEMS_DIR, fileName), content, "utf8");
601
+ }
602
+ }
557
603
  return WORKITEMS_DIR;
558
604
  }
559
605
 
@@ -771,11 +817,17 @@ async function fetchBaselineBranchFromApi(requirementId, cwd) {
771
817
  const cfg = await ensureLoggedConfig();
772
818
  const api = createApmApiClient(cfg);
773
819
  const workdirPath = resolve3(cwd);
774
- const { baselineBranch } = await api.cliRequirements.branchBaseline({
820
+ const res = await api.cliRequirements.branchBaseline({
775
821
  requirementId,
776
822
  workdirPath
777
823
  });
778
- const name = baselineBranch.trim();
824
+ if (!res.repositoryId) {
825
+ throw new Error(
826
+ `[apm] \u672A\u5728\u5E73\u53F0\u627E\u5230\u4E0E\u5F53\u524D\u76EE\u5F55\u5339\u914D\u7684\u5DE5\u4F5C\u76EE\u5F55\u767B\u8BB0\uFF1A${workdirPath}
827
+ \u8BF7\u5148\u5728\u5E73\u53F0\u767B\u8BB0\u8BE5\u8DEF\u5F84\u5BF9\u5E94\u7684\u5DE5\u4F5C\u76EE\u5F55\u4E0E\u4ED3\u5E93\u3002`
828
+ );
829
+ }
830
+ const name = (res.defaultBranch ?? "").trim();
779
831
  if (!name) {
780
832
  throw new Error("[apm] \u5E73\u53F0\u8FD4\u56DE\u7684\u57FA\u7EBF\u5206\u652F\u540D\u4E3A\u7A7A");
781
833
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,