plugin-git-manager 1.2.28 → 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.
- package/README.md +58 -40
- package/dist/client/941.1793e67472872992.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/locale/en-US.json +90 -1
- package/dist/locale/vi-VN.json +90 -1
- package/dist/locale/zh-CN.json +90 -1
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/review-cutover.js +137 -0
- package/dist/server/actions/review.js +132 -43
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +51 -16
- package/dist/server/poller.js +54 -34
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +2 -1
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- package/package.json +2 -2
- package/src/client/__tests__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +46 -35
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/components/CommitHistory.tsx +61 -6
- package/src/client/components/ReviewFlows.tsx +90 -41
- package/src/client/components/ReviewHistory.tsx +245 -15
- package/src/client/components/RunReviewButton.tsx +12 -136
- package/src/client/workflowRoutes.ts +42 -0
- package/src/locale/en-US.json +90 -1
- package/src/locale/vi-VN.json +90 -1
- package/src/locale/zh-CN.json +90 -1
- package/src/server/__tests__/repository-access.test.ts +11 -3
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +37 -98
- package/src/server/actions/review-cutover.ts +121 -0
- package/src/server/actions/review.ts +148 -38
- package/src/server/actions/role-permissions.ts +10 -0
- package/src/server/ai-tools.ts +23 -8
- package/src/server/collections/gitCodeReviews.ts +19 -0
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +12 -0
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/index.ts +12 -0
- package/src/server/plugin.ts +43 -6
- package/src/server/poller.ts +54 -40
- package/src/server/repository-access.ts +32 -2
- package/src/server/request-method-policy.ts +1 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- package/dist/client/900.a48beac7e2ebee7d.js +0 -10
- package/dist/client-v2/900.e6155002a9c97e7f.js +0 -10
|
@@ -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
|
+
});
|