plugin-git-manager 1.2.27 → 1.3.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.
Files changed (138) hide show
  1. package/README.md +151 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/941.1793e67472872992.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  13. package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +396 -297
  17. package/dist/locale/vi-VN.json +384 -292
  18. package/dist/locale/zh-CN.json +150 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review-cutover.js +137 -0
  27. package/dist/server/actions/review.js +150 -51
  28. package/dist/server/actions/role-permissions.js +1 -0
  29. package/dist/server/ai-tools.js +8 -9
  30. package/dist/server/collections/gitCodeReviews.js +10 -0
  31. package/dist/server/collections/gitReviewCutover.js +44 -0
  32. package/dist/server/collections/gitReviewFlows.js +3 -0
  33. package/dist/server/collections/gitReviewInbox.js +51 -0
  34. package/dist/server/collections/gitReviewProjects.js +43 -0
  35. package/dist/server/collections/gitReviewRequests.js +56 -0
  36. package/dist/server/index.js +8 -2
  37. package/dist/server/plugin.js +57 -20
  38. package/dist/server/poller.js +95 -74
  39. package/dist/server/repository-access.js +23 -5
  40. package/dist/server/request-method-policy.js +76 -0
  41. package/dist/server/review-control-access.js +79 -0
  42. package/dist/server/services/legacy-post-service.js +412 -0
  43. package/dist/server/services/registry-content-service.js +4 -3
  44. package/dist/server/services/review-service.js +1451 -0
  45. package/dist/server/services/review-source.js +325 -0
  46. package/dist/server/utils/get-repo-account.js +3 -2
  47. package/dist/server/utils/url-security.js +24 -0
  48. package/package.json +61 -43
  49. package/server.d.ts +2 -2
  50. package/server.js +1 -1
  51. package/src/client/__tests__/CommitHistory.test.tsx +79 -0
  52. package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
  53. package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
  54. package/src/client/__tests__/workflowRoutes.test.ts +65 -0
  55. package/src/client/ai-context.tsx +114 -114
  56. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  57. package/src/client/components/CommitHistory.tsx +429 -374
  58. package/src/client/components/FileExplorer.tsx +386 -386
  59. package/src/client/components/GitAccounts.tsx +179 -179
  60. package/src/client/components/GitManagerSettings.tsx +160 -160
  61. package/src/client/components/GitOperations.tsx +220 -220
  62. package/src/client/components/LLMModelSelect.tsx +63 -63
  63. package/src/client/components/LLMServiceSelect.tsx +58 -58
  64. package/src/client/components/MarkdownView.tsx +80 -80
  65. package/src/client/components/MergeRequests.tsx +790 -790
  66. package/src/client/components/PollingStatus.tsx +225 -225
  67. package/src/client/components/RepositoryConfig.tsx +335 -335
  68. package/src/client/components/RepositoryPermissions.tsx +123 -123
  69. package/src/client/components/ReviewFlows.tsx +352 -303
  70. package/src/client/components/ReviewHistory.tsx +796 -566
  71. package/src/client/components/RunReviewButton.tsx +57 -173
  72. package/src/client/context/GitManagerContext.tsx +92 -92
  73. package/src/client/index.tsx +91 -82
  74. package/src/client/locale.ts +9 -9
  75. package/src/client/promptTemplates.ts +31 -31
  76. package/src/client/workflowRoutes.ts +42 -0
  77. package/src/client-v2/ai-context.tsx +99 -0
  78. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  79. package/src/client-v2/index.tsx +1 -1
  80. package/src/client-v2/locale.ts +8 -8
  81. package/src/client-v2/plugin.tsx +67 -39
  82. package/src/index.ts +2 -2
  83. package/src/locale/en-US.json +396 -297
  84. package/src/locale/vi-VN.json +384 -292
  85. package/src/locale/zh-CN.json +150 -51
  86. package/src/server/__tests__/git-actions.test.ts +24 -24
  87. package/src/server/__tests__/git-security.test.ts +170 -0
  88. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  89. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  90. package/src/server/__tests__/poller.test.ts +37 -37
  91. package/src/server/__tests__/repository-access.test.ts +760 -752
  92. package/src/server/__tests__/review-service.integration.test.ts +1263 -0
  93. package/src/server/__tests__/review.test.ts +76 -137
  94. package/src/server/__tests__/role-permissions.test.ts +147 -147
  95. package/src/server/__tests__/smoke.test.ts +139 -17
  96. package/src/server/__tests__/subtree.test.ts +85 -85
  97. package/src/server/actions/git-actions.ts +540 -480
  98. package/src/server/actions/gitlab-api.ts +422 -411
  99. package/src/server/actions/poller.ts +39 -27
  100. package/src/server/actions/review-cutover.ts +121 -0
  101. package/src/server/actions/review.ts +1498 -1369
  102. package/src/server/actions/role-permissions.ts +331 -321
  103. package/src/server/actions/subtree.ts +508 -508
  104. package/src/server/ai-tools.ts +334 -319
  105. package/src/server/collections/gitAccounts.ts +56 -56
  106. package/src/server/collections/gitCodeReviews.ts +218 -199
  107. package/src/server/collections/gitRepositories.ts +87 -87
  108. package/src/server/collections/gitReviewCutover.ts +23 -0
  109. package/src/server/collections/gitReviewFlows.ts +120 -108
  110. package/src/server/collections/gitReviewInbox.ts +30 -0
  111. package/src/server/collections/gitReviewProjects.ts +22 -0
  112. package/src/server/collections/gitReviewRequests.ts +35 -0
  113. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  114. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  115. package/src/server/index.ts +14 -2
  116. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  117. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  118. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  119. package/src/server/plugin.ts +409 -361
  120. package/src/server/poller.ts +365 -352
  121. package/src/server/repository-access.ts +803 -773
  122. package/src/server/request-method-policy.ts +56 -0
  123. package/src/server/review-control-access.ts +71 -0
  124. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  125. package/src/server/services/__tests__/review-source.test.ts +226 -0
  126. package/src/server/services/legacy-post-service.ts +550 -0
  127. package/src/server/services/registry-content-service.ts +495 -484
  128. package/src/server/services/review-service.ts +1899 -0
  129. package/src/server/services/review-source.ts +359 -0
  130. package/src/server/utils/__tests__/redact.test.ts +56 -56
  131. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  132. package/src/server/utils/get-repo-account.ts +51 -41
  133. package/src/server/utils/gitlab-url.ts +38 -38
  134. package/src/server/utils/redact.ts +87 -87
  135. package/src/server/utils/url-security.ts +128 -95
  136. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  137. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  138. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -0,0 +1,79 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var review_control_access_exports = {};
28
+ __export(review_control_access_exports, {
29
+ enforceReviewControlAccess: () => enforceReviewControlAccess
30
+ });
31
+ module.exports = __toCommonJS(review_control_access_exports);
32
+ const CONTROL_COLLECTIONS = /* @__PURE__ */ new Set(["gitReviewProjects", "gitReviewInbox", "gitReviewRequests", "gitReviewCutover"]);
33
+ const REVIEW_COLLECTION = /* @__PURE__ */ new Set(["gitCodeReviews"]);
34
+ const ROUTE_KEYS = /* @__PURE__ */ new Set([
35
+ "resourceName",
36
+ "targetCollection",
37
+ "associatedName",
38
+ "__collection",
39
+ "appends",
40
+ "include",
41
+ "fields"
42
+ ]);
43
+ function containsCollection(value, collections = CONTROL_COLLECTIONS) {
44
+ if (typeof value === "string") return value.split(/[.[\],:/()=\s]+/).some((part) => collections.has(part));
45
+ if (Array.isArray(value)) return value.some((item) => containsCollection(item, collections));
46
+ if (value && typeof value === "object")
47
+ return Object.entries(value).some(
48
+ ([key, nested]) => containsCollection(key, collections) || containsCollection(nested, collections)
49
+ );
50
+ return false;
51
+ }
52
+ function containsRouteOverride(value, collections = CONTROL_COLLECTIONS) {
53
+ if (Array.isArray(value)) return value.some((item) => containsRouteOverride(item, collections));
54
+ if (!value || typeof value !== "object") return false;
55
+ return Object.entries(value).some(([key, nested]) => {
56
+ const keyParts = key.split(/[.[\],:/()=\s]+/);
57
+ return keyParts.some((part) => ROUTE_KEYS.has(part)) && containsCollection(nested, collections) || containsRouteOverride(nested, collections);
58
+ });
59
+ }
60
+ async function enforceReviewControlAccess(ctx, next) {
61
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
62
+ let currentTarget;
63
+ try {
64
+ const current = (_a = ctx.getCurrentRepository) == null ? void 0 : _a.call(ctx);
65
+ currentTarget = ((_b = current == null ? void 0 : current.targetCollection) == null ? void 0 : _b.name) || ((_c = current == null ? void 0 : current.collection) == null ? void 0 : _c.name);
66
+ } catch {
67
+ }
68
+ if (containsCollection((_d = ctx.action) == null ? void 0 : _d.resourceName) || containsCollection(currentTarget) || [(_e = ctx.action) == null ? void 0 : _e.params, (_f = ctx.request) == null ? void 0 : _f.body, ctx.query, (_g = ctx.request) == null ? void 0 : _g.query].some((input) => containsRouteOverride(input)))
69
+ ctx.throw(403, "Permission denied");
70
+ if (((_h = ctx.action) == null ? void 0 : _h.actionName) && !["list", "get"].includes(ctx.action.actionName) && (containsCollection(ctx.action.resourceName, REVIEW_COLLECTION) || containsCollection(currentTarget, REVIEW_COLLECTION) || [ctx.action.params, (_i = ctx.request) == null ? void 0 : _i.body, ctx.query, (_j = ctx.request) == null ? void 0 : _j.query].some(
71
+ (input) => containsRouteOverride(input, REVIEW_COLLECTION)
72
+ )))
73
+ ctx.throw(403, "Permission denied");
74
+ await next();
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ enforceReviewControlAccess
79
+ });
@@ -0,0 +1,412 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var legacy_post_service_exports = {};
28
+ __export(legacy_post_service_exports, {
29
+ LegacyPostService: () => LegacyPostService
30
+ });
31
+ module.exports = __toCommonJS(legacy_post_service_exports);
32
+ var import_crypto = require("crypto");
33
+ var import_sequelize = require("sequelize");
34
+ var import_review = require("../actions/review");
35
+ var import_repository_access = require("../repository-access");
36
+ var import_review_source = require("./review-source");
37
+ function value(record, name) {
38
+ return record.get(name);
39
+ }
40
+ function conflict(message) {
41
+ const error = new Error(message);
42
+ error.status = 409;
43
+ throw error;
44
+ }
45
+ function hash(markdown) {
46
+ return (0, import_crypto.createHash)("sha256").update(markdown).digest("hex");
47
+ }
48
+ function sourceOf(record) {
49
+ const source = value(record, "legacyPostSource");
50
+ if (source == null) return null;
51
+ if (!source || typeof source !== "object" || Array.isArray(source)) conflict("Legacy review source is invalid");
52
+ const candidate = source;
53
+ if (candidate.targetType !== "mr" || typeof candidate.projectKey !== "string" || !candidate.projectKey || !candidate.mrIid || typeof candidate.headSha !== "string" || typeof candidate.baseSha !== "string" || String(candidate.repositoryId) !== String(value(record, "repositoryId")) || String(candidate.mrIid) !== String(value(record, "mrIid")) || candidate.headSha !== value(record, "headSha"))
54
+ conflict("Legacy review source is invalid");
55
+ const projectKey = value(record, "legacyPostProjectKey");
56
+ if (projectKey && projectKey !== candidate.projectKey) conflict("Legacy review source is invalid");
57
+ return candidate;
58
+ }
59
+ function baseAcknowledged(record) {
60
+ return value(record, "legacyBaseProvenance") === "unverified_legacy" && !!value(record, "legacyBaseAcknowledgedBy") && !!value(record, "legacyBaseAcknowledgedAt");
61
+ }
62
+ class LegacyPostService {
63
+ constructor(app) {
64
+ this.app = app;
65
+ }
66
+ async load(reviewId, actor, roles) {
67
+ var _a;
68
+ const db = this.app.db;
69
+ const review = await db.getRepository("gitCodeReviews").findOne({ filterByTk: reviewId });
70
+ if (!review) conflict("Review not found");
71
+ if (((_a = value(review, "metadata")) == null ? void 0 : _a.workflowManaged) || await db.getRepository("gitReviewInbox").findOne({ filter: { reviewId } })) {
72
+ conflict("Use the workflow approval task for this review");
73
+ }
74
+ if (value(review, "status") !== "completed" || value(review, "targetType") !== "mr") {
75
+ conflict("Only completed legacy merge request reviews can be published");
76
+ }
77
+ const repositoryId = value(review, "repositoryId");
78
+ const currentRoles = await (0, import_review.resolveBackgroundReviewRoles)(db, actor);
79
+ if (!roles.length || roles.some((role) => !currentRoles.includes(role)) || !await (0, import_repository_access.hasRepositoryAccess)({ acl: this.app.acl, roles, repositoryId, action: "reviewApprovePost" })) {
80
+ const error = new Error("Permission denied");
81
+ error.status = 403;
82
+ throw error;
83
+ }
84
+ const repo = await db.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
85
+ if (!repo) conflict("Repository not found");
86
+ return { review, repo, repositoryId };
87
+ }
88
+ async lookupSource(review, repo) {
89
+ const snapshot = sourceOf(review);
90
+ if (snapshot) return snapshot;
91
+ const mrIid = Number(value(review, "mrIid"));
92
+ if (!Number.isSafeInteger(mrIid) || mrIid < 1) conflict("Invalid merge request");
93
+ return {
94
+ projectKey: value(review, "legacyPostProjectKey") || await (0, import_review_source.resolveReviewProjectKey)(this.app.db, repo),
95
+ repositoryId: Number(value(review, "repositoryId")),
96
+ targetType: "mr",
97
+ mrIid,
98
+ branch: null,
99
+ folderPath: null,
100
+ headSha: value(review, "headSha") || "",
101
+ baseSha: null
102
+ };
103
+ }
104
+ async status(reviewId, actor, roles) {
105
+ const db = this.app.db;
106
+ const { review, repo } = await this.load(reviewId, actor, roles);
107
+ const postStatus = value(review, "postStatus");
108
+ if (!["posting", "post_unknown", "post_failed", "posted"].includes(postStatus)) {
109
+ conflict("Legacy review is not awaiting publication recovery");
110
+ }
111
+ const markdown = value(review, "reviewMarkdown");
112
+ if (!markdown) conflict("No review content to post");
113
+ const fingerprint = hash(markdown);
114
+ const stored = value(review, "legacyPostFingerprint");
115
+ if (stored && stored !== fingerprint) conflict("Approved review content changed");
116
+ const source = await this.lookupSource(review, repo);
117
+ const project = await db.getRepository("gitReviewProjects").findOne({ filter: { projectKey: source.projectKey } });
118
+ const attemptId = value(review, "legacyPostClaim") ?? null;
119
+ const result = {
120
+ status: postStatus === "posted" ? "posted" : "unknown",
121
+ attemptId,
122
+ canRetry: postStatus !== "posted",
123
+ baseUnverified: true,
124
+ baseAcknowledged: baseAcknowledged(review),
125
+ holdActive: !!project && String(value(project, "legacyPostReviewId")) === String(reviewId)
126
+ };
127
+ if (postStatus === "posted") {
128
+ const noteId = value(review, "postedNoteId");
129
+ if (noteId != null) result.postedNoteId = String(noteId);
130
+ return result;
131
+ }
132
+ const marker = `<!-- git-review:legacy:${String(reviewId)}:${fingerprint} -->`;
133
+ const found = await (0, import_review_source.findLegacyPublishedReview)(db, repo, source, markdown, marker);
134
+ if (!found) return result;
135
+ result.status = "observed";
136
+ result.canRetry = found.kind === "marked" && attemptId != null;
137
+ result.postedNoteId = found.noteId;
138
+ if (found.kind !== "marked" || attemptId) return result;
139
+ await db.sequelize.transaction(async (transaction) => {
140
+ const current = await db.getCollection("gitCodeReviews").model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
141
+ if (!current || value(current, "legacyPostClaim") || value(current, "reviewMarkdown") !== markdown || !["posting", "post_unknown", "post_failed"].includes(value(current, "postStatus")))
142
+ return;
143
+ const oldFingerprint = value(current, "legacyPostFingerprint");
144
+ if (oldFingerprint && oldFingerprint !== fingerprint) return;
145
+ await current.update(
146
+ { postStatus: "posted", postedNoteId: found.noteId, legacyPostFingerprint: fingerprint, error: null },
147
+ { transaction }
148
+ );
149
+ await db.getCollection("gitReviewProjects").model.update(
150
+ { legacyPostReviewId: null },
151
+ { where: { projectKey: source.projectKey, legacyPostReviewId: reviewId }, transaction }
152
+ );
153
+ result.status = "posted";
154
+ result.holdActive = false;
155
+ });
156
+ return result;
157
+ }
158
+ async approve(reviewId, actor, roles, editedMarkdown, baseConfirmation) {
159
+ return this.post(reviewId, actor, roles, { kind: "approve", editedMarkdown, baseConfirmation });
160
+ }
161
+ async retry(reviewId, actor, roles, expectedAttempt, baseConfirmation) {
162
+ return this.post(reviewId, actor, roles, { kind: "retry", expectedAttempt, baseConfirmation });
163
+ }
164
+ async post(reviewId, actor, roles, input) {
165
+ const db = this.app.db;
166
+ const owner = this.app.pm.get("plugin-git-manager") || this.app.pm.get("git-manager");
167
+ if (!(owner == null ? void 0 : owner.reviewService) || (await owner.reviewService.cutoverStatus()).state !== "ready") {
168
+ conflict("Review cutover has not been confirmed");
169
+ }
170
+ const { review, repo, repositoryId } = await this.load(reviewId, actor, roles);
171
+ const previousStatus = value(review, "postStatus");
172
+ if (input.kind === "approve" && previousStatus !== "pending_approval") conflict("Review is not awaiting approval");
173
+ if (input.kind === "retry" && !["posting", "post_unknown", "post_failed"].includes(previousStatus)) {
174
+ conflict("Legacy review is not awaiting publication recovery");
175
+ }
176
+ const oldAttempt = value(review, "legacyPostClaim") ?? null;
177
+ if (input.kind === "retry" && oldAttempt !== input.expectedAttempt) conflict("Review publication claim changed");
178
+ if (input.kind === "approve" && oldAttempt) conflict("A publication attempt may still be running");
179
+ const existingMarkdown = value(review, "reviewMarkdown");
180
+ const markdown = input.kind === "approve" && input.editedMarkdown != null ? input.editedMarkdown : existingMarkdown;
181
+ if (typeof markdown !== "string" || !markdown.trim() || Buffer.byteLength(markdown) > 2e5)
182
+ conflict("No review content to post");
183
+ const fingerprint = hash(markdown);
184
+ const previousFingerprint = value(review, "legacyPostFingerprint");
185
+ if (previousFingerprint && previousFingerprint !== fingerprint) conflict("Approved review content changed");
186
+ const marker = `<!-- git-review:legacy:${String(reviewId)}:${fingerprint} -->`;
187
+ let source = sourceOf(review);
188
+ const lookup = source || await this.lookupSource(review, repo);
189
+ const priorMatch = input.kind === "retry" ? await (0, import_review_source.findLegacyPublishedReview)(db, repo, lookup, markdown, marker) : null;
190
+ if ((priorMatch == null ? void 0 : priorMatch.kind) === "unmarked") {
191
+ const project = await db.getRepository("gitReviewProjects").findOne({ filter: { projectKey: lookup.projectKey } });
192
+ return {
193
+ status: "observed",
194
+ attemptId: oldAttempt,
195
+ canRetry: false,
196
+ baseUnverified: true,
197
+ baseAcknowledged: baseAcknowledged(review),
198
+ holdActive: !!project && String(value(project, "legacyPostReviewId")) === String(reviewId),
199
+ postedNoteId: priorMatch.noteId
200
+ };
201
+ }
202
+ let acknowledgedNow = false;
203
+ if (source && !baseAcknowledged(review) && !priorMatch) {
204
+ if (input.baseConfirmation !== "LEGACY_BASE_UNVERIFIED")
205
+ conflict("Legacy review base requires explicit confirmation");
206
+ acknowledgedNow = true;
207
+ }
208
+ if (!source && !priorMatch) {
209
+ if (input.baseConfirmation !== "LEGACY_BASE_UNVERIFIED")
210
+ conflict("Legacy review base requires explicit confirmation");
211
+ const headSha = value(review, "headSha");
212
+ if (!headSha) conflict("Reviewed commit is unavailable");
213
+ source = await (0, import_review_source.resolveReviewSource)(db, repo, {
214
+ targetType: "mr",
215
+ mrIid: Number(value(review, "mrIid")),
216
+ headSha
217
+ });
218
+ acknowledgedNow = true;
219
+ }
220
+ const selectedSource = source || lookup;
221
+ await owner.reviewService.ensureReviewProject(selectedSource.projectKey);
222
+ const token = (0, import_crypto.randomUUID)();
223
+ await db.sequelize.transaction(async (transaction) => {
224
+ const current = await db.getCollection("gitCodeReviews").model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
225
+ if (!current || value(current, "status") !== "completed" || value(current, "postStatus") !== previousStatus || (value(current, "legacyPostClaim") ?? null) !== oldAttempt || value(current, "reviewMarkdown") !== existingMarkdown || value(current, "legacyPostFingerprint") && value(current, "legacyPostFingerprint") !== fingerprint || value(current, "legacyPostProjectKey") && value(current, "legacyPostProjectKey") !== selectedSource.projectKey) {
226
+ conflict("Review publication claim changed");
227
+ }
228
+ if (await db.getRepository("gitReviewInbox").findOne({ filter: { reviewId }, transaction }))
229
+ conflict("Use the workflow approval task for this review");
230
+ const project = await db.getCollection("gitReviewProjects").model.findOne({
231
+ where: { projectKey: selectedSource.projectKey },
232
+ transaction,
233
+ lock: transaction.LOCK.UPDATE
234
+ });
235
+ if (!project || value(project, "activeInboxId") != null)
236
+ conflict("Another review is active for this project");
237
+ const legacyOwner = value(project, "legacyPostReviewId");
238
+ if (legacyOwner != null && String(legacyOwner) !== String(reviewId))
239
+ conflict("Another review is active for this project");
240
+ if (legacyOwner == null) {
241
+ const [reserved] = await db.getCollection("gitReviewProjects").model.update(
242
+ { legacyPostReviewId: reviewId },
243
+ {
244
+ where: { projectKey: selectedSource.projectKey, activeInboxId: null, legacyPostReviewId: null },
245
+ transaction
246
+ }
247
+ );
248
+ if (reserved !== 1) conflict("Another review is active for this project");
249
+ }
250
+ const values = {
251
+ reviewMarkdown: markdown,
252
+ legacyPostFingerprint: fingerprint,
253
+ legacyPostClaim: token,
254
+ legacyPostProjectKey: selectedSource.projectKey,
255
+ postStatus: "posting",
256
+ ...input.kind === "approve" ? { approvedBy: String(actor), approvedAt: /* @__PURE__ */ new Date() } : {},
257
+ ...source ? { legacyPostSource: source } : {},
258
+ ...acknowledgedNow ? {
259
+ legacyBaseProvenance: "unverified_legacy",
260
+ legacyBaseAcknowledgedBy: String(actor),
261
+ legacyBaseAcknowledgedAt: /* @__PURE__ */ new Date()
262
+ } : {}
263
+ };
264
+ const [claimed] = await db.getCollection("gitCodeReviews").model.update(values, {
265
+ where: { id: reviewId, status: "completed", postStatus: previousStatus, legacyPostClaim: oldAttempt },
266
+ transaction
267
+ });
268
+ if (claimed !== 1) conflict("Review publication claim changed");
269
+ });
270
+ try {
271
+ const found = await (0, import_review_source.findLegacyPublishedReview)(db, repo, selectedSource, markdown, marker);
272
+ if ((found == null ? void 0 : found.kind) === "unmarked") {
273
+ const nextAttempt = await this.finish(reviewId, selectedSource.projectKey, token, fingerprint, null);
274
+ return {
275
+ status: "observed",
276
+ attemptId: nextAttempt,
277
+ canRetry: false,
278
+ baseUnverified: true,
279
+ baseAcknowledged: acknowledgedNow || baseAcknowledged(review),
280
+ holdActive: false,
281
+ postedNoteId: found.noteId
282
+ };
283
+ }
284
+ const noteId = (found == null ? void 0 : found.noteId) || await (0, import_review_source.publishPinnedReview)(db, repo, selectedSource, markdown, marker, async (start) => {
285
+ const freshRepo = await db.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
286
+ if (!freshRepo) conflict("Repository not found");
287
+ const currentRoles = await (0, import_review.resolveBackgroundReviewRoles)(db, actor);
288
+ if (roles.some((role) => !currentRoles.includes(role)) || !await (0, import_repository_access.hasRepositoryAccess)({ acl: this.app.acl, roles, repositoryId, action: "reviewApprovePost" }))
289
+ conflict("Permission denied");
290
+ await (0, import_review_source.assertCurrentMrHead)(db, freshRepo, selectedSource);
291
+ const options = db.sequelize.getDialect() === "sqlite" ? { type: import_sequelize.Transaction.TYPES.IMMEDIATE } : {};
292
+ return db.sequelize.transaction(options, async (transaction) => {
293
+ const current = await db.getCollection("gitCodeReviews").model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
294
+ const project = await db.getCollection("gitReviewProjects").model.findOne({
295
+ where: { projectKey: selectedSource.projectKey },
296
+ transaction,
297
+ lock: transaction.LOCK.UPDATE
298
+ });
299
+ const currentSource = current && sourceOf(current);
300
+ if (!current || value(current, "status") !== "completed" || value(current, "postStatus") !== "posting" || value(current, "legacyPostClaim") !== token || value(current, "legacyPostProjectKey") !== selectedSource.projectKey || value(current, "legacyPostFingerprint") !== fingerprint || hash(value(current, "reviewMarkdown") || "") !== fingerprint || !currentSource || String(currentSource.repositoryId) !== String(selectedSource.repositoryId) || String(currentSource.mrIid) !== String(selectedSource.mrIid) || currentSource.headSha !== selectedSource.headSha || currentSource.baseSha !== selectedSource.baseSha || !baseAcknowledged(current) || !project || String(value(project, "legacyPostReviewId")) !== String(reviewId) || value(project, "activeInboxId") != null)
301
+ conflict("Review publication claim changed");
302
+ const response = start();
303
+ response.catch(() => void 0);
304
+ return { response };
305
+ });
306
+ });
307
+ await this.finish(reviewId, selectedSource.projectKey, token, fingerprint, noteId);
308
+ await owner.reviewService.reconcile().catch((error) => {
309
+ var _a, _b;
310
+ return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "Git review dispatch will be retried", error);
311
+ });
312
+ return {
313
+ status: "posted",
314
+ attemptId: null,
315
+ canRetry: false,
316
+ baseUnverified: true,
317
+ baseAcknowledged: acknowledgedNow || baseAcknowledged(review),
318
+ holdActive: false,
319
+ postedNoteId: noteId
320
+ };
321
+ } catch (error) {
322
+ await db.getCollection("gitCodeReviews").model.update(
323
+ {
324
+ postStatus: "post_unknown",
325
+ error: error instanceof Error ? error.message : "Publication outcome is unknown"
326
+ },
327
+ { where: { id: reviewId, legacyPostClaim: token, postStatus: "posting" } }
328
+ );
329
+ throw error;
330
+ }
331
+ }
332
+ async finish(reviewId, projectKey, token, fingerprint, noteId) {
333
+ const db = this.app.db;
334
+ const nextAttempt = noteId ? null : (0, import_crypto.randomUUID)();
335
+ await db.sequelize.transaction(async (transaction) => {
336
+ const review = await db.getCollection("gitCodeReviews").model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
337
+ const project = await db.getCollection("gitReviewProjects").model.findOne({ where: { projectKey }, transaction, lock: transaction.LOCK.UPDATE });
338
+ if (!review || value(review, "legacyPostClaim") !== token || value(review, "legacyPostFingerprint") !== fingerprint || hash(value(review, "reviewMarkdown") || "") !== fingerprint || !project || String(value(project, "legacyPostReviewId")) !== String(reviewId) || value(project, "activeInboxId") != null)
339
+ conflict("Review publication claim changed");
340
+ const [changed] = await db.getCollection("gitCodeReviews").model.update(
341
+ {
342
+ postStatus: noteId ? "posted" : "post_unknown",
343
+ postedNoteId: noteId,
344
+ legacyPostClaim: nextAttempt,
345
+ error: null
346
+ },
347
+ { where: { id: reviewId, legacyPostClaim: token, legacyPostFingerprint: fingerprint }, transaction }
348
+ );
349
+ if (changed !== 1) conflict("Review publication claim changed");
350
+ const [released] = await db.getCollection("gitReviewProjects").model.update(
351
+ { legacyPostReviewId: null },
352
+ { where: { projectKey, legacyPostReviewId: reviewId, activeInboxId: null }, transaction }
353
+ );
354
+ if (released !== 1) conflict("Review project reservation changed");
355
+ });
356
+ return nextAttempt;
357
+ }
358
+ async releaseHold(reviewId, actor, roles, expectedAttempt) {
359
+ var _a, _b, _c;
360
+ if (!roles.includes("root")) {
361
+ const error = new Error("Permission denied");
362
+ error.status = 403;
363
+ throw error;
364
+ }
365
+ const currentRoles = await (0, import_review.resolveBackgroundReviewRoles)(this.app.db, actor);
366
+ if (!currentRoles.includes("root")) {
367
+ const error = new Error("Permission denied");
368
+ error.status = 403;
369
+ throw error;
370
+ }
371
+ const review = await this.app.db.getRepository("gitCodeReviews").findOne({ filterByTk: reviewId });
372
+ if (!review || value(review, "status") !== "completed" || value(review, "targetType") !== "mr" || ((_a = value(review, "metadata")) == null ? void 0 : _a.workflowManaged) || await this.app.db.getRepository("gitReviewInbox").findOne({ filter: { reviewId } }))
373
+ conflict("Legacy review is not available");
374
+ const projectKey = value(review, "legacyPostProjectKey") || ((_b = sourceOf(review)) == null ? void 0 : _b.projectKey);
375
+ if (!projectKey) conflict("Legacy review has no publication hold");
376
+ const db = this.app.db;
377
+ await db.sequelize.transaction(async (transaction) => {
378
+ var _a2;
379
+ const current = await db.getCollection("gitCodeReviews").model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
380
+ if (!current || (value(current, "legacyPostClaim") ?? null) !== expectedAttempt || !["posting", "post_unknown", "post_failed"].includes(value(current, "postStatus")) || (value(current, "legacyPostProjectKey") || ((_a2 = sourceOf(current)) == null ? void 0 : _a2.projectKey)) !== projectKey)
381
+ conflict("Review publication claim changed");
382
+ const project = await db.getCollection("gitReviewProjects").model.findOne({ where: { projectKey }, transaction, lock: transaction.LOCK.UPDATE });
383
+ const [changed] = await db.getCollection("gitCodeReviews").model.update(
384
+ {
385
+ postStatus: "post_unknown",
386
+ legacyPostClaim: (0, import_crypto.randomUUID)(),
387
+ legacyHoldReleasedBy: String(actor),
388
+ legacyHoldReleasedAt: /* @__PURE__ */ new Date()
389
+ },
390
+ { where: { id: reviewId, legacyPostClaim: expectedAttempt, status: "completed" }, transaction }
391
+ );
392
+ if (changed !== 1) conflict("Review publication claim changed");
393
+ if (project)
394
+ await db.getCollection("gitReviewProjects").model.update(
395
+ { legacyPostReviewId: null },
396
+ {
397
+ where: { projectKey, legacyPostReviewId: reviewId, activeInboxId: null },
398
+ transaction
399
+ }
400
+ );
401
+ });
402
+ const owner = this.app.pm.get("plugin-git-manager") || this.app.pm.get("git-manager");
403
+ await ((_c = owner.reviewService) == null ? void 0 : _c.reconcile().catch((error) => {
404
+ var _a2, _b2;
405
+ return (_b2 = (_a2 = this.app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b2.call(_a2, "Git review dispatch will be retried", error);
406
+ }));
407
+ }
408
+ }
409
+ // Annotate the CommonJS export names for ESM import in node:
410
+ 0 && (module.exports = {
411
+ LegacyPostService
412
+ });
@@ -73,7 +73,8 @@ const REGISTRY_GIT_FILE_NOT_FOUND = "REGISTRY_GIT_FILE_NOT_FOUND";
73
73
  const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
74
74
  const REGISTRY_GIT_CONTENT_CAPABILITIES = [
75
75
  "registry-content-with-actor",
76
- "registry-content-authorize-source"
76
+ "registry-content-authorize-source",
77
+ "registry-content-tree-limits"
77
78
  ];
78
79
  const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
79
80
  const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ["skill-hub-content-with-actor"];
@@ -292,11 +293,11 @@ class GitContentService {
292
293
  const output = await runGitBuffer(
293
294
  localPath,
294
295
  ["ls-tree", "-l", ...input.recursive ? ["-r"] : [], target],
295
- this.limits.maxTreeOutputBytes,
296
+ boundedPositive(input.maxTreeOutputBytes, this.limits.maxTreeOutputBytes, this.limits.maxTreeOutputBytes),
296
297
  DEFAULT_GIT_TIMEOUT_MS
297
298
  );
298
299
  const lines = output.toString("utf8").trim().split("\n").filter(Boolean);
299
- if (lines.length > this.limits.maxTreeEntries) {
300
+ if (lines.length > boundedPositive(input.maxTreeEntries, this.limits.maxTreeEntries, this.limits.maxTreeEntries)) {
300
301
  throw new RegistryContentLimitError("Git tree contains too many entries for registry export.");
301
302
  }
302
303
  return lines.map((line) => parseTreeLine(line, rootPath)).filter((entry) => entry !== null).sort((left, right) => left.path.localeCompare(right.path));