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
@@ -34,7 +34,11 @@ __export(review_exports, {
34
34
  resolveBackgroundReviewRoles: () => resolveBackgroundReviewRoles,
35
35
  resolveImmutableReviewActorId: () => resolveImmutableReviewActorId,
36
36
  reviewApprovePost: () => reviewApprovePost,
37
+ reviewLegacyPostStatus: () => reviewLegacyPostStatus,
38
+ reviewLegacyReleaseHold: () => reviewLegacyReleaseHold,
39
+ reviewLegacyRetryPost: () => reviewLegacyRetryPost,
37
40
  reviewReject: () => reviewReject,
41
+ reviewWorkflowRetryPost: () => reviewWorkflowRetryPost,
38
42
  triggerReview: () => triggerReview,
39
43
  triggerReviewInternal: () => triggerReviewInternal,
40
44
  unregisterReviewQueue: () => unregisterReviewQueue
@@ -80,12 +84,14 @@ async function withTriggerLock(app, key, fn) {
80
84
  return app.lockManager.runExclusive(lockKey, fn, TRIGGER_LOCK_TTL_MS);
81
85
  }
82
86
  async function triggerReview(ctx, next) {
83
- var _a, _b;
87
+ var _a, _b, _c;
84
88
  const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
85
89
  const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
86
90
  if (!repositoryId) ctx.throw(400, "repositoryId is required");
87
91
  if (!targetType) ctx.throw(400, "targetType is required");
88
- if (!["mr", "commit", "branch", "folder"].includes(targetType)) ctx.throw(400, "invalid targetType");
92
+ if (targetType !== "mr" && targetType !== "commit" && targetType !== "branch" && targetType !== "folder") {
93
+ ctx.throw(400, "invalid targetType");
94
+ }
89
95
  if (targetType === "mr" && !mrIid) ctx.throw(400, "mrIid is required for MR review");
90
96
  if (targetType === "commit" && !commitSha) ctx.throw(400, "commitSha is required for commit review");
91
97
  if (targetType === "branch" && !branch) ctx.throw(400, "branch is required for branch review");
@@ -96,25 +102,33 @@ async function triggerReview(ctx, next) {
96
102
  const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
97
103
  try {
98
104
  const reviewId = await triggerReviewInternal(ctx.app, {
99
- flowId,
105
+ flowId: flowId != null ? Number(flowId) : null,
100
106
  repositoryId: Number(repositoryId),
101
107
  targetType,
102
108
  mrIid: mrIid != null ? Number(mrIid) : null,
103
- commitSha: commitSha || null,
104
- branch: branch || null,
105
- folderPath: targetType === "folder" ? folderPath : null,
106
- extraInstructions,
109
+ commitSha: typeof commitSha === "string" ? commitSha : null,
110
+ branch: typeof branch === "string" ? branch : null,
111
+ folderPath: targetType === "folder" && typeof folderPath === "string" ? folderPath : null,
112
+ extraInstructions: typeof extraInstructions === "string" ? extraInstructions : void 0,
107
113
  triggeredBy: "manual",
108
- userId
114
+ userId,
115
+ actorRoles: Array.isArray((_c = ctx.state) == null ? void 0 : _c.currentRoles) ? ctx.state.currentRoles.filter((role) => typeof role === "string") : []
109
116
  });
110
117
  ctx.body = { success: true, data: { reviewId } };
111
118
  } catch (err) {
112
- ctx.throw(err.status || 400, err.message || "Failed to trigger review");
119
+ const errorMessage = err.message || "Failed to trigger review";
120
+ const providerError = /^Git provider request failed \((\d+)\)$/.exec(errorMessage);
121
+ ctx.throw(
122
+ err.status || 400,
123
+ providerError ? ctx.t("Git provider request failed ({{status}})", { ns: "plugin-git-manager", status: providerError[1] }) : ctx.t(errorMessage, { ns: "plugin-git-manager" })
124
+ );
113
125
  }
114
126
  await next();
115
127
  }
116
128
  async function triggerReviewInternal(app, args) {
117
- return withTriggerLock(app, targetKey(args), () => triggerReviewInternalLocked(app, args));
129
+ const plugin = app.pm.get("plugin-git-manager") || app.pm.get("git-manager");
130
+ if (!(plugin == null ? void 0 : plugin.reviewService)) throw new Error("Git review workflow service is unavailable");
131
+ return plugin.reviewService.enqueue(args);
118
132
  }
119
133
  async function triggerReviewInternalLocked(app, args) {
120
134
  const db = app.db;
@@ -530,7 +544,7 @@ async function failQueuedReview(app, reviewId, err) {
530
544
  }
531
545
  async function processQueuedReview(app, message) {
532
546
  await withReviewProcessLock(app, message.reviewId, async () => {
533
- var _a, _b, _c, _d, _e, _f;
547
+ var _a, _b, _c, _d, _e, _f, _g;
534
548
  const db = app.db;
535
549
  const reviewsRepo = db.getRepository("gitCodeReviews");
536
550
  const review = await reviewsRepo.findOne({ filterByTk: message.reviewId });
@@ -538,8 +552,8 @@ async function processQueuedReview(app, message) {
538
552
  (_b = (_a = app.log) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, `git review queue: review ${message.reviewId} not found, skipping`);
539
553
  return;
540
554
  }
541
- if (review.get("status") !== "pending") {
542
- (_d = (_c = app.log) == null ? void 0 : _c.info) == null ? void 0 : _d.call(_c, `git review queue: review ${message.reviewId} is ${review.get("status")}, skipping`);
555
+ if (review.get("status") !== "pending" || ((_c = review.get("metadata")) == null ? void 0 : _c.workflowManaged)) {
556
+ (_e = (_d = app.log) == null ? void 0 : _d.info) == null ? void 0 : _e.call(_d, `git review queue: review ${message.reviewId} is ${review.get("status")}, skipping`);
543
557
  return;
544
558
  }
545
559
  const metadata = getQueuedReviewMetadata(review);
@@ -580,64 +594,141 @@ async function processQueuedReview(app, message) {
580
594
  userId: actorUserId
581
595
  });
582
596
  } catch (err) {
583
- (_f = (_e = app.log) == null ? void 0 : _e.error) == null ? void 0 : _f.call(_e, "git review queue: failed before review execution", err);
597
+ (_g = (_f = app.log) == null ? void 0 : _f.error) == null ? void 0 : _g.call(_f, "git review queue: failed before review execution", {
598
+ error: (0, import_redact.redactPat)(err instanceof Error ? err.message : String(err))
599
+ });
584
600
  await failQueuedReview(app, message.reviewId, err);
585
601
  }
586
602
  });
587
603
  }
604
+ function legacyPostContext(ctx) {
605
+ var _a, _b, _c;
606
+ const actor = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
607
+ const roles = (_c = ctx.state) == null ? void 0 : _c.currentRoles;
608
+ if (typeof actor !== "string" && typeof actor !== "number" || !Array.isArray(roles) || !roles.every((role) => typeof role === "string")) {
609
+ ctx.throw(403, "Permission denied");
610
+ }
611
+ const plugin = ctx.app.pm.get("plugin-git-manager") || ctx.app.pm.get("git-manager");
612
+ if (!(plugin == null ? void 0 : plugin.legacyPostService)) ctx.throw(503, "Git review workflow service is unavailable");
613
+ return { service: plugin.legacyPostService, actor, roles };
614
+ }
615
+ async function legacyPostAction(ctx, run) {
616
+ try {
617
+ ctx.body = { success: true, data: await run() };
618
+ } catch (error) {
619
+ const status = error && typeof error === "object" && "status" in error && typeof error.status === "number" ? error.status : 400;
620
+ ctx.throw(
621
+ status,
622
+ ctx.t(error instanceof Error ? error.message : "Failed to reconcile review publication", {
623
+ ns: "plugin-git-manager"
624
+ })
625
+ );
626
+ }
627
+ }
588
628
  async function reviewApprovePost(ctx, next) {
589
- var _a, _b;
629
+ const { reviewId, editedMarkdown, baseConfirmation } = (0, import_repository_access.getEffectiveActionParams)(ctx);
630
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
631
+ const { service, actor, roles } = legacyPostContext(ctx);
632
+ await legacyPostAction(ctx, () => service.approve(reviewId, actor, roles, editedMarkdown, baseConfirmation));
633
+ await next();
634
+ }
635
+ async function reviewLegacyPostStatus(ctx, next) {
636
+ const { reviewId } = (0, import_repository_access.getEffectiveActionParams)(ctx);
637
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
638
+ const { service, actor, roles } = legacyPostContext(ctx);
639
+ await legacyPostAction(ctx, () => service.status(reviewId, actor, roles));
640
+ await next();
641
+ }
642
+ async function reviewLegacyRetryPost(ctx, next) {
590
643
  const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
591
- const { reviewId, editedMarkdown } = params;
592
- if (!reviewId) ctx.throw(400, "reviewId is required");
593
- const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
594
- const review = await reviewsRepo.findOne({ filterByTk: reviewId });
595
- if (!review) ctx.throw(404, "Review not found");
596
- if (review.get("status") !== "completed") ctx.throw(400, "Review is not completed");
597
- if (review.get("targetType") !== "mr") ctx.throw(400, "Only MR reviews can be posted");
598
- const markdown = editedMarkdown ?? review.get("reviewMarkdown");
599
- if (!markdown) ctx.throw(400, "No review content to post");
600
- const repo = await ctx.db.getRepository("gitRepositories").findOne({
601
- filterByTk: review.get("repositoryId")
602
- });
603
- if (!repo) ctx.throw(404, "Repository not found");
604
- const noteId = await postNoteToGitLab(ctx.db, repo, Number(review.get("mrIid")), markdown);
605
- const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
606
- await reviewsRepo.update({
607
- filterByTk: reviewId,
608
- values: {
609
- reviewMarkdown: markdown,
610
- postStatus: "posted",
611
- postedNoteId: String(noteId),
612
- approvedBy: userId ? String(userId) : null,
613
- approvedAt: /* @__PURE__ */ new Date(),
614
- error: null
615
- }
644
+ const { reviewId, confirmation, expectedAttempt, baseConfirmation } = params;
645
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
646
+ if (Object.prototype.hasOwnProperty.call(params, "editedMarkdown")) {
647
+ ctx.throw(400, ctx.t("Review content cannot change while publication is unresolved", { ns: "plugin-git-manager" }));
648
+ }
649
+ if (confirmation !== "OUTBOUND_POST_STOPPED")
650
+ ctx.throw(400, ctx.t("Outbound post stop confirmation is required", { ns: "plugin-git-manager" }));
651
+ if (!Object.prototype.hasOwnProperty.call(params, "expectedAttempt") || expectedAttempt !== null && typeof expectedAttempt !== "string") {
652
+ ctx.throw(400, ctx.t("Refresh publication status before recovery", { ns: "plugin-git-manager" }));
653
+ }
654
+ const { service, actor, roles } = legacyPostContext(ctx);
655
+ await legacyPostAction(ctx, () => service.retry(reviewId, actor, roles, expectedAttempt, baseConfirmation));
656
+ await next();
657
+ }
658
+ async function reviewLegacyReleaseHold(ctx, next) {
659
+ const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
660
+ const { reviewId, confirmation, expectedAttempt } = params;
661
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
662
+ if (confirmation !== "OUTBOUND_POST_STOPPED")
663
+ ctx.throw(400, ctx.t("Outbound post stop confirmation is required", { ns: "plugin-git-manager" }));
664
+ if (!Object.prototype.hasOwnProperty.call(params, "expectedAttempt") || expectedAttempt !== null && typeof expectedAttempt !== "string") {
665
+ ctx.throw(400, ctx.t("Refresh publication status before recovery", { ns: "plugin-git-manager" }));
666
+ }
667
+ const { service, actor, roles } = legacyPostContext(ctx);
668
+ await legacyPostAction(ctx, async () => {
669
+ await service.releaseHold(reviewId, actor, roles, expectedAttempt);
670
+ return { reviewId };
616
671
  });
617
- ctx.body = { success: true, data: { reviewId, postedNoteId: noteId } };
618
672
  await next();
619
673
  }
620
674
  async function reviewReject(ctx, next) {
621
- var _a, _b;
675
+ var _a, _b, _c;
622
676
  const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
623
677
  const { reviewId, reason } = params;
624
- if (!reviewId) ctx.throw(400, "reviewId is required");
678
+ if (!reviewId || typeof reviewId !== "string" && typeof reviewId !== "number") {
679
+ ctx.throw(400, "reviewId is required");
680
+ }
625
681
  const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
626
682
  const review = await reviewsRepo.findOne({ filterByTk: reviewId });
627
683
  if (!review) ctx.throw(404, "Review not found");
628
- const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
629
- await reviewsRepo.update({
630
- filterByTk: reviewId,
631
- values: {
684
+ if (((_a = review.get("metadata")) == null ? void 0 : _a.workflowManaged) || await ctx.db.getRepository("gitReviewInbox").findOne({ filter: { reviewId } })) {
685
+ ctx.throw(409, ctx.t("Use the workflow approval task for this review", { ns: "plugin-git-manager" }));
686
+ }
687
+ const userId = (_c = (_b = ctx.state) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.id;
688
+ const [changed] = await ctx.db.getCollection("gitCodeReviews").model.update(
689
+ {
632
690
  postStatus: "rejected",
633
691
  approvedBy: userId ? String(userId) : null,
634
692
  approvedAt: /* @__PURE__ */ new Date(),
635
693
  error: reason ? `Rejected: ${reason}` : "Rejected"
636
- }
637
- });
694
+ },
695
+ { where: { id: reviewId, status: "completed", targetType: "mr", postStatus: "pending_approval" } }
696
+ );
697
+ if (changed !== 1) ctx.throw(409, "Review is not awaiting approval");
638
698
  ctx.body = { success: true, data: { reviewId } };
639
699
  await next();
640
700
  }
701
+ async function reviewWorkflowRetryPost(ctx, next) {
702
+ var _a, _b, _c;
703
+ const { reviewId, confirmation } = (0, import_repository_access.getEffectiveActionParams)(ctx);
704
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
705
+ if (confirmation != null && confirmation !== "OUTBOUND_POST_STOPPED")
706
+ ctx.throw(400, ctx.t("Invalid publication confirmation", { ns: "plugin-git-manager" }));
707
+ const actor = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
708
+ const roles = (_c = ctx.state) == null ? void 0 : _c.currentRoles;
709
+ if (!actor || !Array.isArray(roles) || !roles.every((role) => typeof role === "string"))
710
+ ctx.throw(403, "Permission denied");
711
+ const plugin = ctx.app.pm.get("plugin-git-manager") || ctx.app.pm.get("git-manager");
712
+ if (!(plugin == null ? void 0 : plugin.reviewService)) ctx.throw(503, "Git review workflow service is unavailable");
713
+ try {
714
+ const result = await plugin.reviewService.retryPost(
715
+ reviewId,
716
+ actor,
717
+ roles,
718
+ confirmation === "OUTBOUND_POST_STOPPED"
719
+ );
720
+ ctx.body = { success: true, data: result };
721
+ } catch (error) {
722
+ const status = error && typeof error === "object" && "status" in error && typeof error.status === "number" ? error.status : 400;
723
+ ctx.throw(
724
+ status,
725
+ ctx.t(error instanceof Error ? error.message : "Failed to reconcile review publication", {
726
+ ns: "plugin-git-manager"
727
+ })
728
+ );
729
+ }
730
+ await next();
731
+ }
641
732
  async function runReview(app, args) {
642
733
  var _a, _b, _c, _d, _e, _f;
643
734
  const db = app.db;
@@ -961,11 +1052,12 @@ async function fetchMrHeadSha(db, repo, mrIid) {
961
1052
  const pat = (account == null ? void 0 : account.pat) || "";
962
1053
  if (!pat) return null;
963
1054
  const repoUrl = repo.get("repoUrl");
964
- const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.includes("github.com");
1055
+ const isGitHub = (account == null ? void 0 : account.provider) === "github" || new URL(repoUrl).hostname === "github.com";
965
1056
  try {
966
1057
  if (isGitHub) {
967
1058
  const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
968
1059
  const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls/${mrIid}`, {
1060
+ redirect: "error",
969
1061
  headers: { Authorization: `Bearer ${pat}`, Accept: "application/vnd.github.v3+json" }
970
1062
  });
971
1063
  if (!response.ok) return null;
@@ -974,6 +1066,7 @@ async function fetchMrHeadSha(db, repo, mrIid) {
974
1066
  } else {
975
1067
  const { apiBase, encodedProject } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
976
1068
  const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}`, {
1069
+ redirect: "error",
977
1070
  headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
978
1071
  });
979
1072
  if (!response.ok) return null;
@@ -988,11 +1081,12 @@ async function postNoteToGitLab(db, repo, mrIid, body) {
988
1081
  const account = await (0, import_get_repo_account.getRepoAccount)(db, repo);
989
1082
  const pat = (account == null ? void 0 : account.pat) || "";
990
1083
  const repoUrl = repo.get("repoUrl");
991
- const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.includes("github.com");
1084
+ const isGitHub = (account == null ? void 0 : account.provider) === "github" || new URL(repoUrl).hostname === "github.com";
992
1085
  if (isGitHub) {
993
1086
  if (!pat) throw new Error("Repository has no PAT configured");
994
1087
  const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
995
1088
  const response = await fetch(`https://api.github.com/repos/${projectPath}/issues/${mrIid}/comments`, {
1089
+ redirect: "error",
996
1090
  method: "POST",
997
1091
  headers: {
998
1092
  Authorization: `Bearer ${pat}`,
@@ -1011,6 +1105,7 @@ async function postNoteToGitLab(db, repo, mrIid, body) {
1011
1105
  if (!pat) throw new Error("Repository has no PAT configured");
1012
1106
  const { apiBase, encodedProject } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
1013
1107
  const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}/notes`, {
1108
+ redirect: "error",
1014
1109
  method: "POST",
1015
1110
  headers: {
1016
1111
  "PRIVATE-TOKEN": pat,
@@ -1127,7 +1222,11 @@ async function recoverStuckReviews(app) {
1127
1222
  resolveBackgroundReviewRoles,
1128
1223
  resolveImmutableReviewActorId,
1129
1224
  reviewApprovePost,
1225
+ reviewLegacyPostStatus,
1226
+ reviewLegacyReleaseHold,
1227
+ reviewLegacyRetryPost,
1130
1228
  reviewReject,
1229
+ reviewWorkflowRetryPost,
1131
1230
  triggerReview,
1132
1231
  triggerReviewInternal,
1133
1232
  unregisterReviewQueue
@@ -67,6 +67,7 @@ const GIT_WRITE_ACTIONS = [
67
67
  "triggerReview",
68
68
  "reviewApprovePost",
69
69
  "reviewReject",
70
+ "reviewWorkflowRetryPost",
70
71
  "pollNow",
71
72
  "subtreeRun"
72
73
  ];
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(ai_tools_exports);
42
42
  var import_zod = require("zod");
43
43
  var gitlabApi = __toESM(require("./actions/gitlab-api"));
44
44
  var gitActions = __toESM(require("./actions/git-actions"));
45
+ var import_repository_access = require("./repository-access");
45
46
  function registerGitReviewAiTools(app) {
46
47
  var _a, _b, _c, _d, _e;
47
48
  const aiManager = app.aiManager;
@@ -49,10 +50,10 @@ function registerGitReviewAiTools(app) {
49
50
  (_c = (_b = app.log) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "plugin-git-manager: AIManager.toolsManager not available; skipping AI tool registration");
50
51
  return;
51
52
  }
52
- const enforceAcl = (ctx, resource, action, params) => {
53
+ const enforceAcl = async (ctx, resource, action, params) => {
53
54
  var _a2, _b2, _c2, _d2;
54
55
  if (ctx.isBackgroundReview) {
55
- if (params.repositoryId && params.repositoryId !== ctx.reviewTargetRepositoryId) {
56
+ if (String(params.repositoryId) !== String(ctx.reviewTargetRepositoryId)) {
56
57
  const err = new Error("Permission denied: AI cannot access other repositories");
57
58
  err.status = 403;
58
59
  throw err;
@@ -66,14 +67,13 @@ function registerGitReviewAiTools(app) {
66
67
  throw err;
67
68
  }
68
69
  const acl = (_b2 = ctx.app) == null ? void 0 : _b2.acl;
69
- if (!(acl == null ? void 0 : acl.can)) return;
70
- const role = ((_c2 = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c2.currentRole) || Array.isArray(user.roles) && ((_d2 = user.roles[0]) == null ? void 0 : _d2.name) || null;
71
- if (!role) {
70
+ const roles = Array.isArray((_c2 = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c2.currentRoles) ? ctx.state.currentRoles.filter((role) => typeof role === "string") : typeof ((_d2 = ctx == null ? void 0 : ctx.state) == null ? void 0 : _d2.currentRole) === "string" ? [ctx.state.currentRole] : [];
71
+ if (!roles.length || !(acl == null ? void 0 : acl.can)) {
72
72
  const err = new Error("AI tool requires a resolvable role on the current user");
73
73
  err.status = 403;
74
74
  throw err;
75
75
  }
76
- const allowed = acl.can({ role, resource, action });
76
+ const allowed = resource === "gitManager" && await (0, import_repository_access.hasRepositoryAccess)({ acl, roles, repositoryId: params.repositoryId, action });
77
77
  if (!allowed) {
78
78
  const err = new Error(`Permission denied: ${resource}:${action}`);
79
79
  err.status = 403;
@@ -97,14 +97,13 @@ function registerGitReviewAiTools(app) {
97
97
  return obj;
98
98
  };
99
99
  const runResourceAction = async (ctx, handler, params, gate) => {
100
- var _a2;
101
- enforceAcl(ctx, gate.resource, gate.action, params);
100
+ await enforceAcl(ctx, gate.resource, gate.action, params);
102
101
  const synthCtx = {
103
102
  ...ctx,
104
103
  app: ctx.app,
105
104
  db: ctx.db,
106
105
  action: { params },
107
- request: { ...ctx.request || {}, body: ((_a2 = ctx.request) == null ? void 0 : _a2.body) || {} },
106
+ request: { ...ctx.request || {}, body: {} },
108
107
  throw: (status, message) => {
109
108
  const err = new Error(message);
110
109
  err.status = status;
@@ -133,6 +133,7 @@ var gitCodeReviews_default = (0, import_database.defineCollection)({
133
133
  "x-component": "Select",
134
134
  enum: [
135
135
  { value: "pending", label: "Pending" },
136
+ { value: "queued", label: "Queued" },
136
137
  { value: "running", label: "Running" },
137
138
  { value: "completed", label: "Completed" },
138
139
  { value: "failed", label: "Failed" }
@@ -184,6 +185,15 @@ var gitCodeReviews_default = (0, import_database.defineCollection)({
184
185
  name: "postedNoteId",
185
186
  interface: "input"
186
187
  },
188
+ { type: "string", name: "legacyPostFingerprint" },
189
+ { type: "string", name: "legacyPostClaim" },
190
+ { type: "string", name: "legacyPostProjectKey" },
191
+ { type: "json", name: "legacyPostSource" },
192
+ { type: "string", name: "legacyBaseProvenance" },
193
+ { type: "string", name: "legacyBaseAcknowledgedBy" },
194
+ { type: "date", name: "legacyBaseAcknowledgedAt" },
195
+ { type: "string", name: "legacyHoldReleasedBy" },
196
+ { type: "date", name: "legacyHoldReleasedAt" },
187
197
  {
188
198
  type: "string",
189
199
  name: "approvedBy",
@@ -0,0 +1,44 @@
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 gitReviewCutover_exports = {};
28
+ __export(gitReviewCutover_exports, {
29
+ default: () => gitReviewCutover_default
30
+ });
31
+ module.exports = __toCommonJS(gitReviewCutover_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var gitReviewCutover_default = (0, import_database.defineCollection)({
34
+ name: "gitReviewCutover",
35
+ autoGenId: true,
36
+ createdAt: true,
37
+ updatedAt: true,
38
+ fields: [
39
+ { name: "key", type: "string", unique: true, allowNull: false },
40
+ { name: "state", type: "string", allowNull: false },
41
+ { name: "confirmedBy", type: "string" },
42
+ { name: "confirmedAt", type: "date" }
43
+ ]
44
+ });
@@ -39,6 +39,9 @@ var gitReviewFlows_default = (0, import_database.defineCollection)({
39
39
  createdAt: true,
40
40
  updatedAt: true,
41
41
  fields: [
42
+ { type: "bigInt", name: "workflowId" },
43
+ { type: "string", name: "workflowKey" },
44
+ { type: "boolean", name: "reviewOnNewCommits", defaultValue: false },
42
45
  {
43
46
  type: "string",
44
47
  name: "name",
@@ -0,0 +1,51 @@
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 gitReviewInbox_exports = {};
28
+ __export(gitReviewInbox_exports, {
29
+ default: () => gitReviewInbox_default
30
+ });
31
+ module.exports = __toCommonJS(gitReviewInbox_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var gitReviewInbox_default = (0, import_database.defineCollection)({
34
+ name: "gitReviewInbox",
35
+ autoGenId: true,
36
+ createdAt: true,
37
+ updatedAt: true,
38
+ fields: [
39
+ { name: "projectKey", type: "string", allowNull: false, index: true },
40
+ { name: "repositoryId", type: "integer", allowNull: false },
41
+ { name: "reviewId", type: "integer", allowNull: false, unique: true },
42
+ { name: "legacyReviewId", type: "integer", unique: true },
43
+ { name: "eventKey", type: "string", unique: true },
44
+ { name: "queuedAt", type: "date", allowNull: false },
45
+ { name: "recoveredBy", type: "string" },
46
+ { name: "recoveredAt", type: "date" },
47
+ { name: "state", type: "string", allowNull: false, defaultValue: "queued" },
48
+ { name: "blockedReason", type: "string" },
49
+ { name: "payload", type: "json", allowNull: false }
50
+ ]
51
+ });
@@ -0,0 +1,43 @@
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 gitReviewProjects_exports = {};
28
+ __export(gitReviewProjects_exports, {
29
+ default: () => gitReviewProjects_default
30
+ });
31
+ module.exports = __toCommonJS(gitReviewProjects_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var gitReviewProjects_default = (0, import_database.defineCollection)({
34
+ name: "gitReviewProjects",
35
+ autoGenId: true,
36
+ createdAt: true,
37
+ updatedAt: true,
38
+ fields: [
39
+ { name: "projectKey", type: "string", unique: true, allowNull: false },
40
+ { name: "activeInboxId", type: "integer" },
41
+ { name: "legacyPostReviewId", type: "integer" }
42
+ ]
43
+ });
@@ -0,0 +1,56 @@
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 gitReviewRequests_exports = {};
28
+ __export(gitReviewRequests_exports, {
29
+ default: () => gitReviewRequests_default
30
+ });
31
+ module.exports = __toCommonJS(gitReviewRequests_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var gitReviewRequests_default = (0, import_database.defineCollection)({
34
+ name: "gitReviewRequests",
35
+ autoGenId: true,
36
+ createdAt: true,
37
+ updatedAt: true,
38
+ fields: [
39
+ { name: "inboxId", type: "integer", allowNull: false, unique: true },
40
+ { name: "reviewId", type: "integer", allowNull: false },
41
+ { name: "repositoryId", type: "integer", allowNull: false },
42
+ { name: "flowId", type: "integer", allowNull: false },
43
+ { name: "workflowId", type: "bigInt", allowNull: false },
44
+ { name: "workflowKey", type: "string" },
45
+ { name: "eventType", type: "string", allowNull: false },
46
+ { name: "executionId", type: "bigInt", unique: true },
47
+ { name: "fenced", type: "boolean", allowNull: false, defaultValue: false },
48
+ { name: "llmClaims", type: "json" },
49
+ { name: "resultFingerprint", type: "string" },
50
+ { name: "postClaim", type: "string" },
51
+ { name: "postClaimedAt", type: "date" },
52
+ { name: "postResetBy", type: "string" },
53
+ { name: "postResetAt", type: "date" },
54
+ { name: "aiSettled", type: "boolean", allowNull: false, defaultValue: false }
55
+ ]
56
+ });
@@ -36,13 +36,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
  var server_exports = {};
38
38
  __export(server_exports, {
39
+ GitReviewService: () => import_review_service.GitReviewService,
39
40
  PluginGitManagerServer: () => import_plugin2.PluginGitManagerServer,
40
- default: () => import_plugin.default
41
+ default: () => import_plugin.default,
42
+ hasRepositoryAccess: () => import_repository_access.hasRepositoryAccess
41
43
  });
42
44
  module.exports = __toCommonJS(server_exports);
43
45
  var import_plugin = __toESM(require("./plugin"));
44
46
  var import_plugin2 = require("./plugin");
47
+ var import_review_service = require("./services/review-service");
48
+ var import_repository_access = require("./repository-access");
45
49
  // Annotate the CommonJS export names for ESM import in node:
46
50
  0 && (module.exports = {
47
- PluginGitManagerServer
51
+ GitReviewService,
52
+ PluginGitManagerServer,
53
+ hasRepositoryAccess
48
54
  });