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
@@ -48,13 +48,18 @@ var import_sequelize = require("sequelize");
48
48
  var gitActions = __toESM(require("./actions/git-actions"));
49
49
  var gitlabApi = __toESM(require("./actions/gitlab-api"));
50
50
  var reviewActions = __toESM(require("./actions/review"));
51
+ var reviewCutoverActions = __toESM(require("./actions/review-cutover"));
51
52
  var pollerActions = __toESM(require("./actions/poller"));
52
53
  var rolePermissionsActions = __toESM(require("./actions/role-permissions"));
53
54
  var subtreeActions = __toESM(require("./actions/subtree"));
54
55
  var import_review = require("./actions/review");
55
56
  var import_ai_tools = require("./ai-tools");
57
+ var import_request_method_policy = require("./request-method-policy");
56
58
  var import_poller = require("./poller");
57
59
  var import_registry_content_service = require("./services/registry-content-service");
60
+ var import_review_service = require("./services/review-service");
61
+ var import_legacy_post_service = require("./services/legacy-post-service");
62
+ var import_review_control_access = require("./review-control-access");
58
63
  var import_repository_access = require("./repository-access");
59
64
  var import_redact = require("./utils/redact");
60
65
  var import_url_security = require("./utils/url-security");
@@ -65,7 +70,11 @@ function isGitConfigurationUrlMutation(resourceName, actionName) {
65
70
  class PluginGitManagerServer extends import_server.Plugin {
66
71
  registryContentService;
67
72
  skillHubContentService;
73
+ reviewService;
74
+ legacyPostService;
68
75
  async afterAdd() {
76
+ this.reviewService = new import_review_service.GitReviewService(this.app);
77
+ this.legacyPostService = new import_legacy_post_service.LegacyPostService(this.app);
69
78
  this.registryContentService = new import_registry_content_service.RegistryGitContentService(
70
79
  this.db,
71
80
  void 0,
@@ -88,6 +97,7 @@ class PluginGitManagerServer extends import_server.Plugin {
88
97
  });
89
98
  }
90
99
  async load() {
100
+ var _a;
91
101
  const dayjsLib = require("dayjs");
92
102
  const utcPlugin = require("dayjs/plugin/utc");
93
103
  const timezonePlugin = require("dayjs/plugin/timezone");
@@ -113,7 +123,17 @@ class PluginGitManagerServer extends import_server.Plugin {
113
123
  mergeRequestNotes: gitlabApi.mergeRequestNotes,
114
124
  triggerReview: reviewActions.triggerReview,
115
125
  reviewApprovePost: reviewActions.reviewApprovePost,
126
+ reviewLegacyPostStatus: reviewActions.reviewLegacyPostStatus,
127
+ reviewLegacyRetryPost: reviewActions.reviewLegacyRetryPost,
128
+ reviewLegacyReleaseHold: reviewActions.reviewLegacyReleaseHold,
116
129
  reviewReject: reviewActions.reviewReject,
130
+ reviewWorkflowRetryPost: reviewActions.reviewWorkflowRetryPost,
131
+ reviewCutoverStatus: reviewCutoverActions.reviewCutoverStatus,
132
+ reviewConfirmCutover: reviewCutoverActions.reviewConfirmCutover,
133
+ reviewCancelLegacy: reviewCutoverActions.reviewCancelLegacy,
134
+ reviewRecover: reviewCutoverActions.reviewRecover,
135
+ reviewResetPostClaim: reviewCutoverActions.reviewResetPostClaim,
136
+ reviewCancelQueued: reviewCutoverActions.reviewCancelQueued,
117
137
  pollNow: pollerActions.pollNow,
118
138
  pollerStatus: pollerActions.pollerStatus,
119
139
  rolePermissions: rolePermissionsActions.rolePermissions,
@@ -124,6 +144,18 @@ class PluginGitManagerServer extends import_server.Plugin {
124
144
  subtreeReplace: subtreeActions.subtreeRunOnAppProcess
125
145
  }
126
146
  });
147
+ const legacyApprovalAction = this.app.acl.getAvailableAction("reviewApprovePost");
148
+ const priorAliases = (_a = legacyApprovalAction == null ? void 0 : legacyApprovalAction.options) == null ? void 0 : _a.aliases;
149
+ this.app.acl.setAvailableAction("reviewApprovePost", {
150
+ ...legacyApprovalAction == null ? void 0 : legacyApprovalAction.options,
151
+ aliases: [
152
+ ...Array.isArray(priorAliases) ? priorAliases : priorAliases ? [priorAliases] : [],
153
+ "reviewLegacyPostStatus",
154
+ "reviewLegacyRetryPost"
155
+ ]
156
+ });
157
+ this.app.resourceManager.use(import_request_method_policy.enforceGitRequestMethod);
158
+ this.app.resourceManager.use(import_review_control_access.enforceReviewControlAccess);
127
159
  this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
128
160
  this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
129
161
  this.app.use(async (ctx, next) => {
@@ -138,34 +170,30 @@ class PluginGitManagerServer extends import_server.Plugin {
138
170
  }
139
171
  return next();
140
172
  });
141
- (0, import_review.registerReviewQueue)(this.app);
142
173
  (0, import_ai_tools.registerGitReviewAiTools)(this.app);
143
174
  this.app.on("afterStart", async () => {
144
175
  await ensureAutoReviewFlowSchema(this.app).catch(
145
176
  (err) => {
146
- var _a, _b;
147
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: ensure schema error", err);
148
- }
149
- );
150
- (0, import_review.recoverStuckReviews)(this.app).catch(
151
- (err) => {
152
- var _a, _b;
153
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recoverStuckReviews error", err);
177
+ var _a2, _b;
178
+ return (_b = (_a2 = this.app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b.call(_a2, "plugin-git-manager: ensure schema error", err);
154
179
  }
155
180
  );
181
+ this.reviewService.start();
156
182
  subtreeActions.recoverStuckSubtreeRuns(this.app).catch((err) => {
157
- var _a, _b;
158
- return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recover subtree runs error", err);
183
+ var _a2, _b;
184
+ return (_b = (_a2 = this.app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b.call(_a2, "plugin-git-manager: recover subtree runs error", err);
159
185
  });
160
186
  (0, import_poller.startPoller)(this.app);
161
187
  });
162
188
  this.app.on("beforeStop", () => {
163
189
  (0, import_review.unregisterReviewQueue)(this.app);
164
- (0, import_poller.stopPoller)();
190
+ this.reviewService.stop();
191
+ (0, import_poller.stopPoller)(this.app);
165
192
  });
166
193
  this.app.on("beforeDestroy", () => {
167
194
  (0, import_review.unregisterReviewQueue)(this.app);
168
- (0, import_poller.stopPoller)();
195
+ this.reviewService.stop();
196
+ (0, import_poller.stopPoller)(this.app);
169
197
  });
170
198
  this.app.acl.registerSnippet({
171
199
  name: `pm.${this.name}.read`,
@@ -216,7 +244,10 @@ class PluginGitManagerServer extends import_server.Plugin {
216
244
  "gitManager:checkout",
217
245
  "gitManager:triggerReview",
218
246
  "gitManager:reviewApprovePost",
247
+ "gitManager:reviewLegacyPostStatus",
248
+ "gitManager:reviewLegacyRetryPost",
219
249
  "gitManager:reviewReject",
250
+ "gitManager:reviewWorkflowRetryPost",
220
251
  "gitManager:pollNow",
221
252
  "gitSubtreeConfigs:create",
222
253
  "gitSubtreeConfigs:update",
@@ -247,8 +278,8 @@ class PluginGitManagerServer extends import_server.Plugin {
247
278
  ]
248
279
  });
249
280
  this.app.resourceManager.use(async (ctx, next) => {
250
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
251
- const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
281
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
282
+ const resource = (_a2 = ctx.action) == null ? void 0 : _a2.resourceName;
252
283
  if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b = ctx.action) == null ? void 0 : _b.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
253
284
  try {
254
285
  subtreeActions.validateSubtreeConfigInput(ctx.action.params.values);
@@ -306,8 +337,8 @@ class PluginGitManagerServer extends import_server.Plugin {
306
337
  return next();
307
338
  });
308
339
  this.app.resourceManager.use(async (ctx, next) => {
309
- var _a;
310
- const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
340
+ var _a2;
341
+ const resource = (_a2 = ctx.action) == null ? void 0 : _a2.resourceName;
311
342
  if (!(0, import_redact.isGitManagerResourceResponse)(resource)) {
312
343
  return next();
313
344
  }
@@ -316,19 +347,25 @@ class PluginGitManagerServer extends import_server.Plugin {
316
347
  });
317
348
  }
318
349
  async install() {
319
- var _a, _b, _c, _d;
350
+ var _a, _b, _c, _d, _e, _f, _g, _h;
320
351
  await ((_a = this.app.db.getCollection("gitAccounts")) == null ? void 0 : _a.sync());
321
352
  await ((_b = this.app.db.getCollection("gitRepositories")) == null ? void 0 : _b.sync());
322
353
  await ((_c = this.app.db.getCollection("gitSubtreeConfigs")) == null ? void 0 : _c.sync());
323
354
  await ((_d = this.app.db.getCollection("gitSubtreeRuns")) == null ? void 0 : _d.sync());
355
+ await ((_e = this.app.db.getCollection("gitReviewProjects")) == null ? void 0 : _e.sync());
356
+ await ((_f = this.app.db.getCollection("gitReviewInbox")) == null ? void 0 : _f.sync());
357
+ await ((_g = this.app.db.getCollection("gitReviewRequests")) == null ? void 0 : _g.sync());
358
+ await ((_h = this.app.db.getCollection("gitReviewCutover")) == null ? void 0 : _h.sync());
324
359
  }
325
360
  async beforeDisable() {
326
361
  (0, import_review.unregisterReviewQueue)(this.app);
327
- (0, import_poller.stopPoller)();
362
+ this.reviewService.stop();
363
+ (0, import_poller.stopPoller)(this.app);
328
364
  }
329
365
  async beforeUnload() {
330
366
  (0, import_review.unregisterReviewQueue)(this.app);
331
- (0, import_poller.stopPoller)();
367
+ this.reviewService.stop();
368
+ (0, import_poller.stopPoller)(this.app);
332
369
  }
333
370
  }
334
371
  async function ensureAutoReviewFlowSchema(app) {
@@ -38,33 +38,38 @@ var import_gitlab_url = require("./utils/gitlab-url");
38
38
  var import_get_repo_account = require("./utils/get-repo-account");
39
39
  const POLL_INTERVAL_MS = 5 * 60 * 1e3;
40
40
  const MR_PAGE_SIZE = 50;
41
- const STALE_POLL_TIMEOUT_MS = 10 * 60 * 1e3;
42
- let timer = null;
43
- let isPolling = false;
44
- let pollStartedAt = null;
45
- let lastTickAt = null;
46
- let lastError = null;
41
+ const pollers = /* @__PURE__ */ new WeakMap();
42
+ function stateFor(app) {
43
+ let state = pollers.get(app);
44
+ if (!state) {
45
+ state = { timer: null, polling: false, lastTickAt: null, lastError: null };
46
+ pollers.set(app, state);
47
+ }
48
+ return state;
49
+ }
47
50
  function startPoller(app) {
48
51
  var _a, _b;
49
- if (timer) return;
52
+ const state = stateFor(app);
53
+ if (state.timer) return;
50
54
  (_b = (_a = app.log) == null ? void 0 : _a.info) == null ? void 0 : _b.call(_a, "plugin-git-manager: starting MR poller (interval 5min)");
51
- timer = setInterval(() => tick(app).catch((e) => {
55
+ state.timer = setInterval(() => tick(app).catch((e) => {
52
56
  var _a2, _b2;
53
57
  return (_b2 = (_a2 = app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b2.call(_a2, "poller tick error", e);
54
58
  }), POLL_INTERVAL_MS);
55
59
  }
56
- function stopPoller() {
57
- if (timer) {
58
- clearInterval(timer);
59
- timer = null;
60
- }
60
+ function stopPoller(app) {
61
+ const state = stateFor(app);
62
+ if (state.timer) clearInterval(state.timer);
63
+ state.timer = null;
61
64
  }
62
- function getPollerStatus() {
65
+ function getPollerStatus(app) {
66
+ var _a;
67
+ const state = stateFor(app);
63
68
  return {
64
- running: !!timer,
65
- polling: isPolling,
66
- lastTickAt: (lastTickAt == null ? void 0 : lastTickAt.toISOString()) ?? null,
67
- lastError,
69
+ running: !!state.timer,
70
+ polling: state.polling,
71
+ lastTickAt: ((_a = state.lastTickAt) == null ? void 0 : _a.toISOString()) ?? null,
72
+ lastError: state.lastError,
68
73
  intervalSec: POLL_INTERVAL_MS / 1e3
69
74
  };
70
75
  }
@@ -133,46 +138,38 @@ async function tryAcquirePollerLock(app) {
133
138
  }
134
139
  }
135
140
  async function pollAllRepos(app) {
136
- var _a, _b, _c, _d, _e, _f, _g, _h;
137
- if (isPolling) {
138
- if (pollStartedAt && Date.now() - pollStartedAt > STALE_POLL_TIMEOUT_MS) {
139
- (_b = (_a = app.log) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "poller: stale isPolling flag detected \u2014 forcibly resetting");
140
- isPolling = false;
141
- pollStartedAt = null;
142
- } else {
143
- return { scanned: 0, triggered: 0 };
144
- }
145
- }
146
- const lock = await tryAcquirePollerLock(app);
147
- if (!lock) {
148
- (_d = (_c = app.log) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, "poller: another node holds the advisory lock \u2014 skipping");
149
- return { scanned: 0, triggered: 0 };
150
- }
151
- isPolling = true;
152
- pollStartedAt = Date.now();
153
- lastTickAt = /* @__PURE__ */ new Date();
154
- lastError = null;
141
+ var _a, _b, _c, _d;
142
+ const state = stateFor(app);
143
+ if (state.polling) return { scanned: 0, triggered: 0 };
144
+ state.polling = true;
145
+ let lock = null;
155
146
  let scanned = 0;
156
147
  let triggered = 0;
157
148
  try {
149
+ lock = await tryAcquirePollerLock(app);
150
+ if (!lock) return { scanned: 0, triggered: 0 };
151
+ state.lastTickAt = /* @__PURE__ */ new Date();
152
+ state.lastError = null;
158
153
  const reposRepo = app.db.getRepository("gitRepositories");
159
154
  const repos = await reposRepo.find({ filter: { autoReview: true } });
160
155
  for (const repo of repos) {
161
156
  try {
162
- const result = await pollOneRepo(app, repo);
157
+ const result = await pollOneRepoUnlocked(app, repo);
163
158
  scanned += result.scanned;
164
159
  triggered += result.triggered;
165
160
  } catch (err) {
166
- (_f = (_e = app.log) == null ? void 0 : _e.error) == null ? void 0 : _f.call(_e, `poller: repo ${repo.get("id")} failed: ${err == null ? void 0 : err.message}`);
161
+ (_b = (_a = app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, `poller: repo ${repo.get("id")} failed: ${err == null ? void 0 : err.message}`);
167
162
  }
168
163
  }
169
164
  } catch (err) {
170
- lastError = (err == null ? void 0 : err.message) || String(err);
171
- (_h = (_g = app.log) == null ? void 0 : _g.error) == null ? void 0 : _h.call(_g, "poller: cycle failed", err);
165
+ state.lastError = (err == null ? void 0 : err.message) || String(err);
166
+ (_d = (_c = app.log) == null ? void 0 : _c.error) == null ? void 0 : _d.call(_c, "poller: cycle failed", err);
172
167
  } finally {
173
- isPolling = false;
174
- pollStartedAt = null;
175
- await lock.release();
168
+ try {
169
+ await (lock == null ? void 0 : lock.release());
170
+ } finally {
171
+ state.polling = false;
172
+ }
176
173
  }
177
174
  return { scanned, triggered };
178
175
  }
@@ -180,6 +177,23 @@ async function tick(app) {
180
177
  await pollAllRepos(app);
181
178
  }
182
179
  async function pollOneRepo(app, repo) {
180
+ const state = stateFor(app);
181
+ if (state.polling) return { scanned: 0, triggered: 0 };
182
+ state.polling = true;
183
+ let lock = null;
184
+ try {
185
+ lock = await tryAcquirePollerLock(app);
186
+ if (!lock) return { scanned: 0, triggered: 0 };
187
+ return await pollOneRepoUnlocked(app, repo);
188
+ } finally {
189
+ try {
190
+ await (lock == null ? void 0 : lock.release());
191
+ } finally {
192
+ state.polling = false;
193
+ }
194
+ }
195
+ }
196
+ async function pollOneRepoUnlocked(app, repo) {
183
197
  var _a, _b;
184
198
  const flowsRepo = app.db.getRepository("gitReviewFlows");
185
199
  const reviewsRepo = app.db.getRepository("gitCodeReviews");
@@ -198,9 +212,10 @@ async function pollOneRepo(app, repo) {
198
212
  const account = await (0, import_get_repo_account.getRepoAccount)(app.db, repo);
199
213
  const pat = (account == null ? void 0 : account.pat) || "";
200
214
  if (!pat) return { scanned: 0, triggered: 0 };
201
- const lastPolledAt = repo.get("lastPolledAt");
202
- const mrs = await listMergeRequests(repo, pat, lastPolledAt);
215
+ const pollStartedAt = /* @__PURE__ */ new Date();
216
+ const mrs = await listMergeRequests(repo, pat);
203
217
  let triggered = 0;
218
+ let failed = false;
204
219
  for (const mr of mrs) {
205
220
  const flow = primaryFlow && (0, import_review.branchMatches)(primaryFlow, mr.source_branch) ? primaryFlow : flows.find((f) => (0, import_review.branchMatches)(f, mr.source_branch));
206
221
  if (!flow) continue;
@@ -209,7 +224,8 @@ async function pollOneRepo(app, repo) {
209
224
  repositoryId: repo.get("id"),
210
225
  targetType: "mr",
211
226
  mrIid: mr.iid
212
- }
227
+ },
228
+ sort: ["-id"]
213
229
  });
214
230
  if (existing) {
215
231
  if (existing.get("latestSha") !== mr.sha) {
@@ -218,7 +234,7 @@ async function pollOneRepo(app, repo) {
218
234
  values: { latestSha: mr.sha }
219
235
  });
220
236
  }
221
- continue;
237
+ if (!flow.get("reviewOnNewCommits") || existing.get("headSha") === mr.sha) continue;
222
238
  }
223
239
  try {
224
240
  await (0, import_review.triggerReviewInternal)(app, {
@@ -228,22 +244,25 @@ async function pollOneRepo(app, repo) {
228
244
  mrIid: mr.iid,
229
245
  branch: mr.source_branch,
230
246
  headSha: mr.sha,
231
- triggeredBy: "poll"
247
+ triggeredBy: "poll",
248
+ eventType: existing ? "head_changed" : "change_opened"
232
249
  });
233
250
  triggered++;
234
251
  } catch (err) {
252
+ failed = true;
235
253
  (_b = (_a = app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, `poller: triggerReviewInternal failed for MR !${mr.iid}: ${err == null ? void 0 : err.message}`);
236
254
  }
237
255
  }
256
+ if (failed) throw new Error("One or more merge requests could not be queued");
238
257
  await reposRepo.update({
239
258
  filterByTk: repo.get("id"),
240
- values: { lastPolledAt: /* @__PURE__ */ new Date() }
259
+ values: { lastPolledAt: pollStartedAt }
241
260
  });
242
261
  return { scanned: mrs.length, triggered };
243
262
  }
244
- async function listMergeRequests(repo, pat, updatedAfter) {
263
+ async function listMergeRequests(repo, pat) {
245
264
  const repoUrl = repo.get("repoUrl");
246
- const isGitHub = typeof repoUrl === "string" && repoUrl.includes("github.com");
265
+ const isGitHub = typeof repoUrl === "string" && new URL(repoUrl).hostname === "github.com";
247
266
  if (isGitHub) {
248
267
  const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
249
268
  const params2 = new URLSearchParams({
@@ -254,18 +273,18 @@ async function listMergeRequests(repo, pat, updatedAfter) {
254
273
  });
255
274
  const headers = { Accept: "application/vnd.github.v3+json" };
256
275
  if (pat) headers["Authorization"] = `Bearer ${pat}`;
257
- const response2 = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, { headers });
258
- if (!response2.ok) {
259
- const body = await response2.text().catch(() => "");
260
- throw new Error(`GitHub API error ${response2.status}: ${body}`);
261
- }
262
- let prs = await response2.json();
263
- if (Array.isArray(prs) && updatedAfter) {
264
- const cutoff = updatedAfter.getTime() - 1e3;
265
- prs = prs.filter((pr) => {
266
- const t = (pr == null ? void 0 : pr.updated_at) ? new Date(pr.updated_at).getTime() : 0;
267
- return t >= cutoff;
276
+ const prs = [];
277
+ for (let page = 1; ; page++) {
278
+ params2.set("page", String(page));
279
+ const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, {
280
+ headers,
281
+ redirect: "error"
268
282
  });
283
+ if (!response.ok) throw new Error(`GitHub API error ${response.status}`);
284
+ const items = await response.json();
285
+ if (!Array.isArray(items)) throw new Error("Invalid GitHub pull request response");
286
+ prs.push(...items);
287
+ if (items.length < MR_PAGE_SIZE) break;
269
288
  }
270
289
  return (prs || []).map((pr) => {
271
290
  var _a, _b, _c;
@@ -284,18 +303,20 @@ async function listMergeRequests(repo, pat, updatedAfter) {
284
303
  order_by: "updated_at",
285
304
  sort: "desc"
286
305
  });
287
- if (updatedAfter) {
288
- const safeBound = new Date(updatedAfter.getTime() - 1e3);
289
- params.set("updated_after", safeBound.toISOString());
290
- }
291
- const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
292
- headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
293
- });
294
- if (!response.ok) {
295
- const body = await response.text().catch(() => "");
296
- throw new Error(`GitLab API error ${response.status}: ${body}`);
306
+ const mrs = [];
307
+ for (let page = 1; ; page++) {
308
+ params.set("page", String(page));
309
+ const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
310
+ redirect: "error",
311
+ headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
312
+ });
313
+ if (!response.ok) throw new Error(`GitLab API error ${response.status}`);
314
+ const items = await response.json();
315
+ if (!Array.isArray(items)) throw new Error("Invalid GitLab merge request response");
316
+ mrs.push(...items);
317
+ if (items.length < MR_PAGE_SIZE) break;
297
318
  }
298
- return response.json();
319
+ return mrs;
299
320
  }
300
321
  // Annotate the CommonJS export names for ESM import in node:
301
322
  0 && (module.exports = {
@@ -54,7 +54,14 @@ const REPOSITORY_ID_ACTIONS = /* @__PURE__ */ new Set([
54
54
  "subtreeOptions"
55
55
  ]);
56
56
  const SUBTREE_CONFIG_ACTIONS = /* @__PURE__ */ new Set(["subtreePreview", "subtreeRun", "subtreeReplace"]);
57
- const REVIEW_ID_ACTIONS = /* @__PURE__ */ new Set(["reviewApprovePost", "reviewReject"]);
57
+ const REVIEW_ID_ACTIONS = /* @__PURE__ */ new Set([
58
+ "reviewApprovePost",
59
+ "reviewReject",
60
+ "reviewWorkflowRetryPost",
61
+ "reviewLegacyPostStatus",
62
+ "reviewLegacyRetryPost",
63
+ "reviewLegacyReleaseHold"
64
+ ]);
58
65
  function asRecord(value) {
59
66
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
60
67
  }
@@ -427,13 +434,25 @@ async function requireScopedRunConfigValue(ctx, values, scope, actionName) {
427
434
  }
428
435
  }
429
436
  async function enforceRepositoryCollectionAccess(ctx, next) {
430
- var _a, _b, _c;
437
+ var _a, _b, _c, _d, _e, _f;
431
438
  const collectionName = scopedCollectionName(ctx);
432
439
  if (!collectionName) {
433
440
  await next();
434
441
  return;
435
442
  }
436
443
  rejectTargetCollectionOverride(ctx, collectionName);
444
+ const actionName = (_a = ctx.action) == null ? void 0 : _a.actionName;
445
+ if (collectionName === "gitCodeReviews" && actionName && ["create", "update", "destroy"].includes(actionName)) {
446
+ ctx.throw(403, "Permission denied");
447
+ }
448
+ if (collectionName === "gitReviewFlows" && actionName && ["create", "update"].includes(actionName)) {
449
+ const bindingFields = /* @__PURE__ */ new Set(["workflowId", "workflowKey"]);
450
+ if ([(_b = ctx.action) == null ? void 0 : _b.params, (_c = ctx.request) == null ? void 0 : _c.body, ctx.query, (_d = ctx.request) == null ? void 0 : _d.query].some(
451
+ (source) => containsMutationField(source, bindingFields)
452
+ )) {
453
+ ctx.throw(403, "Permission denied");
454
+ }
455
+ }
437
456
  const roles = currentRoles(ctx);
438
457
  if (roles.includes("root")) {
439
458
  await next();
@@ -448,7 +467,7 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
448
467
  await next();
449
468
  return;
450
469
  }
451
- const scope = resolveRepositoryScope((_a = repositoryPermission.params) == null ? void 0 : _a.filter);
470
+ const scope = resolveRepositoryScope((_e = repositoryPermission.params) == null ? void 0 : _e.filter);
452
471
  if (!scope.supported) {
453
472
  ctx.throw(403, "Permission denied");
454
473
  }
@@ -456,7 +475,6 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
456
475
  await next();
457
476
  return;
458
477
  }
459
- const actionName = (_b = ctx.action) == null ? void 0 : _b.actionName;
460
478
  if (!actionName || !STANDARD_COLLECTION_ACTIONS.has(actionName)) {
461
479
  ctx.throw(403, "Permission denied");
462
480
  }
@@ -469,7 +487,7 @@ async function enforceRepositoryCollectionAccess(ctx, next) {
469
487
  rejectScopedCredentialAssociationRoute(ctx);
470
488
  rejectScopedRepositoryCredentialAssociationRead(ctx, actionName);
471
489
  rejectScopedBulkMutationValues(ctx, actionName);
472
- const mergeParams = (_c = ctx.action) == null ? void 0 : _c.mergeParams;
490
+ const mergeParams = (_f = ctx.action) == null ? void 0 : _f.mergeParams;
473
491
  if (!mergeParams) {
474
492
  ctx.throw(403, "Permission denied");
475
493
  }
@@ -0,0 +1,76 @@
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 request_method_policy_exports = {};
28
+ __export(request_method_policy_exports, {
29
+ enforceGitRequestMethod: () => enforceGitRequestMethod
30
+ });
31
+ module.exports = __toCommonJS(request_method_policy_exports);
32
+ const READ_ACTIONS = /* @__PURE__ */ new Set([
33
+ "diff",
34
+ "status",
35
+ "log",
36
+ "branches",
37
+ "fileTree",
38
+ "fileContent",
39
+ "commitDetail",
40
+ "mergeRequests",
41
+ "mergeRequestDetail",
42
+ "mergeRequestNotes",
43
+ "pollerStatus",
44
+ "rolePermissions",
45
+ "reviewCutoverStatus"
46
+ ]);
47
+ async function enforceGitRequestMethod(ctx, next) {
48
+ var _a, _b;
49
+ if (((_a = ctx.action) == null ? void 0 : _a.resourceName) === "gitManager") {
50
+ const allowed = READ_ACTIONS.has(ctx.action.actionName) ? ["GET", "HEAD", "POST"] : ["POST"];
51
+ if (!allowed.includes(ctx.method.toUpperCase())) {
52
+ ctx.set("Allow", allowed.join(", "));
53
+ ctx.throw(405, ctx.t("Method not allowed", { ns: "plugin-git-manager" }));
54
+ }
55
+ }
56
+ try {
57
+ await next();
58
+ } catch (error) {
59
+ const securityMessages = [
60
+ "Invalid repository or account URL",
61
+ "Only HTTPS repository and account URLs are allowed",
62
+ "Repository URL must match the Git account origin",
63
+ "GitHub accounts currently require github.com",
64
+ "Invalid local path",
65
+ "Invalid local path: path traversal detected or path is outside the allowed base directory"
66
+ ];
67
+ if (((_b = ctx.action) == null ? void 0 : _b.resourceName) === "gitManager" && error instanceof Error && securityMessages.includes(error.message)) {
68
+ ctx.throw(400, ctx.t(error.message, { ns: "plugin-git-manager" }));
69
+ }
70
+ throw error;
71
+ }
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ enforceGitRequestMethod
76
+ });