cwm-assistant 0.4.0 → 0.4.2

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.
@@ -2619,7 +2619,7 @@ var Type = type_exports2;
2619
2619
 
2620
2620
  // ../../packages/contracts/src/assistant.ts
2621
2621
  var ASSISTANT_PROTOCOL = 1;
2622
- var ASSISTANT_VERSION = "0.4.0";
2622
+ var ASSISTANT_VERSION = "0.4.2";
2623
2623
  var ASSISTANT_PORT = 46322;
2624
2624
 
2625
2625
  // ../../packages/contracts/src/index.ts
@@ -5751,6 +5751,28 @@ async function latestComparison(cwd, branch, force) {
5751
5751
  comparisonSyncs.set(key, entry);
5752
5752
  return entry.result;
5753
5753
  }
5754
+ async function branchHasChanges(cwd, branch, compareBranch) {
5755
+ if (!fs22.existsSync(cwd)) return true;
5756
+ const baseline = normalizeCommitCompareBranch(compareBranch) || "production";
5757
+ const target = normalizeCommitCompareBranch(branch);
5758
+ if (!target) return true;
5759
+ try {
5760
+ const base = await latestComparison(cwd, baseline, false);
5761
+ if ("unavailable" in base) return true;
5762
+ const candidates = ["refs/remotes/origin/" + target, "refs/heads/" + target];
5763
+ for (const candidate of candidates) {
5764
+ try {
5765
+ const tip = await git2(cwd, ["rev-parse", "--verify", "--end-of-options", candidate]);
5766
+ const ahead = Number(await git2(cwd, ["rev-list", "--count", base.commit + ".." + tip]));
5767
+ return ahead > 0;
5768
+ } catch {
5769
+ }
5770
+ }
5771
+ return true;
5772
+ } catch {
5773
+ return true;
5774
+ }
5775
+ }
5754
5776
  async function readWorkspaceCommits(mount, offset = 0, refresh = false) {
5755
5777
  const compareBranch = normalizeCommitCompareBranch(mount.commit_compare_branch);
5756
5778
  const empty = {
@@ -5859,6 +5881,23 @@ function registerQueryRoutes(app, store) {
5859
5881
  const { mount, folders } = localWorkspace(store, requestGrant(request), id);
5860
5882
  return { ...mount, folders };
5861
5883
  });
5884
+ app.post("/v1/versions/branch-activity", async (request) => {
5885
+ const grant = requestGrant(request);
5886
+ const body = request.body;
5887
+ if (!Array.isArray(body?.branches)) throw new Error("\u5206\u652F\u5217\u8868\u65E0\u6548");
5888
+ const active = [];
5889
+ for (const item of body.branches) {
5890
+ const repositoryId = String(item?.repositoryId || "");
5891
+ const branch = String(item?.branch || "");
5892
+ if (!repositoryId || !branch) continue;
5893
+ const path30 = store.state.repositories[scopeKey(grant.workbenchId, grant.userId, repositoryId)];
5894
+ const changed = await git4(
5895
+ () => branchHasChanges(path30 || "", branch, String(item?.compareBranch || ""))
5896
+ );
5897
+ if (changed) active.push(repositoryId + "\0" + branch);
5898
+ }
5899
+ return { active };
5900
+ });
5862
5901
  app.get("/v1/workspaces/:id/repositories/:index/commits", async (request) => {
5863
5902
  const { id, index } = request.params;
5864
5903
  const query = request.query;
@@ -6108,9 +6147,12 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6108
6147
  fs24.mkdirSync(root, { recursive: true });
6109
6148
  const results = [], folders = [];
6110
6149
  const groups = [...new Set(includedMounts.map((mount) => mount.repository_id))];
6111
- log("\u5BA1\u67E5\u4ED3\u5E93\u603B\u6570\uFF1A" + groups.length);
6150
+ const emptyRepositories = /* @__PURE__ */ new Set();
6112
6151
  excludedRepositories.forEach((repo) => log("\u5DF2\u6392\u9664\uFF1A" + repo.alias + "\uFF08" + repo.reason + "\uFF09"));
6113
- for (const repositoryId of groups) {
6152
+ let kept = 0;
6153
+ const reportTotal = (remaining) => log("\u5BA1\u67E5\u4ED3\u5E93\u603B\u6570\uFF1A" + (kept + remaining));
6154
+ reportTotal(groups.length);
6155
+ for (const [index, repositoryId] of groups.entries()) {
6114
6156
  const entries = includedMounts.filter((entry) => entry.repository_id === repositoryId), repo = entries[0];
6115
6157
  const directory = path26.join(root, repositoryId.replace(/[^a-zA-Z0-9_-]/g, "_"));
6116
6158
  const result2 = {
@@ -6136,9 +6178,8 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6136
6178
  if (!localOrigin && !/^(https:\/\/|ssh:\/\/|[\w.-]+@[\w.-]+:)/.test(remote) || remote.includes("::") || /[\s\x00-\x1f]/.test(remote) || /https?:\/\/[^/]*@/.test(remote))
6137
6179
  throw new Error("\u8FDC\u7AEF\u5730\u5740\u65E0\u6548");
6138
6180
  await git3(root, ["clone", "--no-checkout", "--no-local", "--", remote, directory]);
6139
- folders.push({ name: repo.alias, path: directory });
6140
6181
  result2.remoteRefs = await frozenRefs(git3, directory);
6141
- log("\u4ED3\u5E93\u5FEB\u7167\u5DF2\u83B7\u53D6\uFF1A" + repo.alias);
6182
+ log("\u5DF2\u83B7\u53D6\u8FDC\u7AEF\u5FEB\u7167\uFF1A" + repo.alias);
6142
6183
  const resolveBranch = async (branch) => {
6143
6184
  if (!valid(branch)) throw new Error("\u9700\u6C42\u5206\u652F\u540D\u65E0\u6548\u6216\u7F3A\u5931");
6144
6185
  const clean = branch.replace(/^refs\/remotes\/origin\//, "").replace(/^origin\//, "").replace(/^refs\/heads\//, "");
@@ -6148,13 +6189,46 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6148
6189
  if (!ref) throw new Error(repo.alias + "\uFF1A\u8FDC\u7AEF\u5206\u652F\u4E0D\u5B58\u5728\uFF1A" + clean);
6149
6190
  return ref.sha;
6150
6191
  };
6192
+ const compareName = (repo.compare_branch || "").replace(/^origin\//, "") || production;
6193
+ const baseSha = await resolveBranch(compareName).catch(() => "");
6194
+ const activeEntries = [];
6195
+ for (const entry of entries) {
6196
+ if (!baseSha) {
6197
+ activeEntries.push(entry);
6198
+ continue;
6199
+ }
6200
+ const tip = await resolveBranch(entry.branch).catch(() => "");
6201
+ const ahead = tip ? Number(
6202
+ await git3(directory, ["rev-list", "--count", baseSha + ".." + tip]).catch(() => "1")
6203
+ ) : 1;
6204
+ if (ahead > 0) activeEntries.push(entry);
6205
+ else
6206
+ log(entry.alias + "\uFF1A" + entry.branch + " \u76F8\u5BF9 " + compareName + " \u65E0\u6539\u52A8\uFF0C\u4E0D\u7EB3\u5165\u5BA1\u67E5");
6207
+ }
6208
+ if (!activeEntries.length) {
6209
+ results.splice(results.indexOf(result2), 1);
6210
+ emptyRepositories.add(repositoryId);
6211
+ excludedRepositories.push({
6212
+ repositoryId,
6213
+ alias: repo.alias,
6214
+ reason: "\u5206\u652F\u76F8\u5BF9 " + compareName + " \u65E0\u6539\u52A8"
6215
+ });
6216
+ log("\u5DF2\u6392\u9664\uFF1A" + repo.alias + "\uFF08\u5206\u652F\u76F8\u5BF9 " + compareName + " \u65E0\u6539\u52A8\uFF09");
6217
+ reportTotal(groups.length - index - 1);
6218
+ continue;
6219
+ }
6220
+ entries.length = 0;
6221
+ entries.push(...activeEntries);
6222
+ folders.push({ name: repo.alias, path: directory });
6223
+ kept += 1;
6224
+ log("\u4ED3\u5E93\u5FEB\u7167\u5DF2\u83B7\u53D6\uFF1A" + repo.alias);
6151
6225
  const p = await resolveBranch(production), s = await resolveBranch(staging);
6152
6226
  result2.refs = { production: p, staging: s };
6153
- for (const branch of [...new Set(entries.map((entry) => entry.branch))])
6227
+ for (const branch of [...new Set(activeEntries.map((entry) => entry.branch))])
6154
6228
  result2.branches.push({
6155
6229
  name: branch,
6156
6230
  sha: await resolveBranch(branch),
6157
- requirementIds: entries.filter((entry) => entry.branch === branch).map((entry) => entry.requirement_id)
6231
+ requirementIds: activeEntries.filter((entry) => entry.branch === branch).map((entry) => entry.requirement_id)
6158
6232
  });
6159
6233
  log("\u5F00\u59CB\u5B8C\u6574\u6027\u68C0\u67E5\uFF1A" + repo.alias);
6160
6234
  let mergeConflict = false;
@@ -6188,8 +6262,11 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6188
6262
  log(repo.alias + "\uFF1A\u68C0\u67E5\u5931\u8D25");
6189
6263
  }
6190
6264
  }
6265
+ const coveredMounts = initial.mounts.filter(
6266
+ (mount) => !emptyRepositories.has(mount.repository_id)
6267
+ );
6191
6268
  const uncoveredRequirements = initial.requirements.filter(
6192
- (requirement) => !initial.mounts.some((mount) => mount.requirement_id === requirement.id)
6269
+ (requirement) => !coveredMounts.some((mount) => mount.requirement_id === requirement.id)
6193
6270
  );
6194
6271
  const stale = false;
6195
6272
  const result = stale ? "STALE" : results.some((repo) => ["ERROR", "CONFLICT"].includes(repo.status)) ? "BLOCKED" : uncoveredRequirements.length || results.some((repo) => repo.status === "WARN") ? "WARN" : "PASS";
@@ -6205,6 +6282,7 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6205
6282
  2
6206
6283
  )
6207
6284
  );
6285
+ if (!results.length) throw new Error("\u6240\u6709\u5173\u8054\u5206\u652F\u76F8\u5BF9\u5BF9\u6BD4\u5206\u652F\u5747\u65E0\u6539\u52A8\uFF0C\u65E0\u53EF\u5BA1\u67E5\u7684\u4ED3\u5E93");
6208
6286
  const snapshot = {
6209
6287
  type: "release-integrity",
6210
6288
  formatVersion: 4,
@@ -6872,4 +6950,4 @@ async function cli(args, entry) {
6872
6950
  export {
6873
6951
  cli
6874
6952
  };
6875
- //# sourceMappingURL=cli-7UNIFMZL.js.map
6953
+ //# sourceMappingURL=cli-FQPKDTQT.js.map