plugin-git-manager 1.2.27 → 1.2.28
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 +133 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/900.a48beac7e2ebee7d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +752 -752
- package/src/server/__tests__/review.test.ts +137 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,1369 +1,1388 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function
|
|
331
|
-
return {
|
|
332
|
-
get(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
function
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
await
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
await
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
await
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
await
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
values: {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
},
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
const
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
)
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
//
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
lines.push(
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
lines.push(
|
|
1081
|
-
`
|
|
1082
|
-
'
|
|
1083
|
-
|
|
1084
|
-
);
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
return false;
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
const
|
|
1158
|
-
if (
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
if (
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
const
|
|
1297
|
-
if (
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
return
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
return 0;
|
|
1368
|
-
|
|
1369
|
-
|
|
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
|
+
import { Context } from '@nocobase/actions';
|
|
11
|
+
import type { Application } from '@nocobase/server';
|
|
12
|
+
import { getEffectiveActionParams } from '../repository-access';
|
|
13
|
+
import { parseGitLabProject } from '../utils/gitlab-url';
|
|
14
|
+
import { redactPat } from '../utils/redact';
|
|
15
|
+
import { getRepoAccount } from '../utils/get-repo-account';
|
|
16
|
+
|
|
17
|
+
export const WORKER_JOB_GIT_REVIEW_PROCESS = 'git-review:process';
|
|
18
|
+
const REVIEW_QUEUE_CHANNEL = 'plugin-git-manager.review';
|
|
19
|
+
const REVIEW_WORKER_ALIASES = [REVIEW_QUEUE_CHANNEL, 'plugin-git-manager:review:queue'];
|
|
20
|
+
const REVIEW_QUEUE_CONCURRENCY = Math.max(
|
|
21
|
+
1,
|
|
22
|
+
Number.parseInt(process.env.GIT_REVIEW_QUEUE_CONCURRENCY || process.env.GIT_REVIEW_MAX_CONCURRENCY || '3', 10) || 3,
|
|
23
|
+
);
|
|
24
|
+
const REVIEW_QUEUE_TIMEOUT_MS = Math.max(
|
|
25
|
+
60_000,
|
|
26
|
+
Number.parseInt(process.env.GIT_REVIEW_QUEUE_TIMEOUT_MS || '', 10) || 10 * 60 * 1000,
|
|
27
|
+
);
|
|
28
|
+
const REVIEW_QUEUE_POLL_INTERVAL_MS = Math.max(
|
|
29
|
+
1000,
|
|
30
|
+
Number.parseInt(process.env.GIT_REVIEW_QUEUE_POLL_INTERVAL_MS || '', 10) || 5000,
|
|
31
|
+
);
|
|
32
|
+
const REVIEW_PROCESS_LOCK_TTL_MS = Math.max(REVIEW_QUEUE_TIMEOUT_MS + 60_000, 11 * 60 * 1000);
|
|
33
|
+
const REVIEW_QUEUE_WAKE_CHANNEL = 'plugin-git-manager.review.wake';
|
|
34
|
+
const REVIEW_QUEUE_REDIS_CONNECTION = 'plugin-git-manager.review.queue';
|
|
35
|
+
|
|
36
|
+
interface TriggerArgs {
|
|
37
|
+
flowId?: number | null;
|
|
38
|
+
repositoryId: number;
|
|
39
|
+
targetType: 'mr' | 'commit' | 'branch' | 'folder';
|
|
40
|
+
mrIid?: number | null;
|
|
41
|
+
commitSha?: string | null;
|
|
42
|
+
branch?: string | null;
|
|
43
|
+
folderPath?: string | null;
|
|
44
|
+
headSha?: string | null;
|
|
45
|
+
extraInstructions?: string;
|
|
46
|
+
triggeredBy?: 'manual' | 'poll';
|
|
47
|
+
userId?: number | string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ReviewFlowSnapshot {
|
|
51
|
+
id: number;
|
|
52
|
+
name?: string;
|
|
53
|
+
postMode?: string;
|
|
54
|
+
llmService?: string | null;
|
|
55
|
+
model?: string | null;
|
|
56
|
+
instructions?: string | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface ReviewQueueMessage {
|
|
60
|
+
reviewId: number;
|
|
61
|
+
repositoryId: number;
|
|
62
|
+
targetType: 'mr' | 'commit' | 'branch' | 'folder';
|
|
63
|
+
mrIid?: number | null;
|
|
64
|
+
commitSha?: string | null;
|
|
65
|
+
branch?: string | null;
|
|
66
|
+
folderPath?: string | null;
|
|
67
|
+
headSha?: string | null;
|
|
68
|
+
aiEmployeeUsername: string;
|
|
69
|
+
extraInstructions?: string;
|
|
70
|
+
userId?: number | string | null;
|
|
71
|
+
flowSnapshot?: ReviewFlowSnapshot;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface QueuedReviewMetadata {
|
|
75
|
+
queuedAt?: string;
|
|
76
|
+
aiEmployeeUsername?: string;
|
|
77
|
+
extraInstructions?: string | null;
|
|
78
|
+
userId?: number | string | null;
|
|
79
|
+
flowSnapshot?: ReviewFlowSnapshot;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let reviewQueueTimer: NodeJS.Timeout | null = null;
|
|
83
|
+
let reviewQueueKickTimer: NodeJS.Timeout | null = null;
|
|
84
|
+
let reviewQueueProcessing = false;
|
|
85
|
+
let reviewWakeHandler: ((message?: any) => Promise<void>) | null = null;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Per-target mutex to prevent two concurrent calls to
|
|
89
|
+
* `triggerReviewInternal` for the same MR / commit / branch from racing
|
|
90
|
+
* `findOne` → `create` and producing two duplicate review rows or
|
|
91
|
+
* scheduling two `runReview`s.
|
|
92
|
+
*
|
|
93
|
+
* Uses `app.lockManager` so the same code path covers both single-node
|
|
94
|
+
* (in-memory `async-mutex`) and HA cluster (Redis-backed Redlock when
|
|
95
|
+
* `plugin-cluster-manager` is active and `LOCK_ADAPTER_DEFAULT=redis`).
|
|
96
|
+
* The locked region only does an upsert + queue publish (a few ms), so a 30s
|
|
97
|
+
* TTL is generous and auto-releases if the process crashes.
|
|
98
|
+
*/
|
|
99
|
+
function targetKey(args: TriggerArgs): string {
|
|
100
|
+
if (args.targetType === 'mr') return `${args.repositoryId}:mr:${args.mrIid}`;
|
|
101
|
+
if (args.targetType === 'commit') return `${args.repositoryId}:commit:${args.commitSha}`;
|
|
102
|
+
if (args.targetType === 'folder') {
|
|
103
|
+
return `${args.repositoryId}:folder:${args.branch || 'HEAD'}:${args.folderPath || '/'}`;
|
|
104
|
+
}
|
|
105
|
+
return `${args.repositoryId}:branch:${args.branch}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const TRIGGER_LOCK_TTL_MS = 30_000;
|
|
109
|
+
|
|
110
|
+
async function withTriggerLock<T>(app: Application, key: string, fn: () => Promise<T>): Promise<T> {
|
|
111
|
+
const lockKey = `git-review:trigger:${key}`;
|
|
112
|
+
return app.lockManager.runExclusive(lockKey, fn, TRIGGER_LOCK_TTL_MS);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Trigger an AI-driven code review for an MR / commit / branch.
|
|
117
|
+
* The review record is upserted synchronously, then queued for an available
|
|
118
|
+
* git-review worker. The action returns immediately with the reviewId.
|
|
119
|
+
*/
|
|
120
|
+
export async function triggerReview(ctx: Context, next: () => Promise<void>) {
|
|
121
|
+
const params = getEffectiveActionParams(ctx);
|
|
122
|
+
const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
|
|
123
|
+
|
|
124
|
+
if (!repositoryId) ctx.throw(400, 'repositoryId is required');
|
|
125
|
+
if (!targetType) ctx.throw(400, 'targetType is required');
|
|
126
|
+
if (targetType !== 'mr' && targetType !== 'commit' && targetType !== 'branch' && targetType !== 'folder') {
|
|
127
|
+
ctx.throw(400, 'invalid targetType');
|
|
128
|
+
}
|
|
129
|
+
if (targetType === 'mr' && !mrIid) ctx.throw(400, 'mrIid is required for MR review');
|
|
130
|
+
if (targetType === 'commit' && !commitSha) ctx.throw(400, 'commitSha is required for commit review');
|
|
131
|
+
if (targetType === 'branch' && !branch) ctx.throw(400, 'branch is required for branch review');
|
|
132
|
+
if (targetType === 'folder') {
|
|
133
|
+
if (typeof folderPath !== 'string') ctx.throw(400, 'folderPath is required for folder review');
|
|
134
|
+
if (folderPath.includes('..')) ctx.throw(400, 'Invalid folder path');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const userId = (ctx as any).state?.currentUser?.id;
|
|
138
|
+
try {
|
|
139
|
+
const reviewId = await triggerReviewInternal(ctx.app, {
|
|
140
|
+
flowId: flowId != null ? Number(flowId) : null,
|
|
141
|
+
repositoryId: Number(repositoryId),
|
|
142
|
+
targetType,
|
|
143
|
+
mrIid: mrIid != null ? Number(mrIid) : null,
|
|
144
|
+
commitSha: typeof commitSha === 'string' ? commitSha : null,
|
|
145
|
+
branch: typeof branch === 'string' ? branch : null,
|
|
146
|
+
folderPath: targetType === 'folder' && typeof folderPath === 'string' ? folderPath : null,
|
|
147
|
+
extraInstructions: typeof extraInstructions === 'string' ? extraInstructions : undefined,
|
|
148
|
+
triggeredBy: 'manual',
|
|
149
|
+
userId,
|
|
150
|
+
});
|
|
151
|
+
ctx.body = { success: true, data: { reviewId } };
|
|
152
|
+
} catch (err: any) {
|
|
153
|
+
ctx.throw(err.status || 400, err.message || 'Failed to trigger review');
|
|
154
|
+
}
|
|
155
|
+
await next();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Programmatic entry point — used by manual action and by the poller.
|
|
160
|
+
* Returns the reviewId of the upserted record.
|
|
161
|
+
*/
|
|
162
|
+
export async function triggerReviewInternal(app: Application, args: TriggerArgs): Promise<number> {
|
|
163
|
+
return withTriggerLock(app, targetKey(args), () => triggerReviewInternalLocked(app, args));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function triggerReviewInternalLocked(app: Application, args: TriggerArgs): Promise<number> {
|
|
167
|
+
const db = app.db;
|
|
168
|
+
const flowsRepo = db.getRepository('gitReviewFlows');
|
|
169
|
+
|
|
170
|
+
// Resolve flow
|
|
171
|
+
let flow: any = null;
|
|
172
|
+
if (args.flowId) {
|
|
173
|
+
flow = await flowsRepo.findOne({ filterByTk: args.flowId });
|
|
174
|
+
if (!flow) throwHttp(404, 'Review flow not found');
|
|
175
|
+
if (!flow.get('enabled')) throwHttp(400, 'Review flow is disabled');
|
|
176
|
+
const flowRepositoryId = flow.get('repositoryId');
|
|
177
|
+
if (flowRepositoryId != null && String(flowRepositoryId) !== String(args.repositoryId)) {
|
|
178
|
+
throwHttp(400, 'Review flow does not belong to this repository');
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
// Find flows scoped to repo or global, prefer repo-specific
|
|
182
|
+
const candidates = await flowsRepo.find({
|
|
183
|
+
filter: {
|
|
184
|
+
enabled: true,
|
|
185
|
+
$or: [{ repositoryId: args.repositoryId }, { repositoryId: null }],
|
|
186
|
+
},
|
|
187
|
+
sort: ['-repositoryId'],
|
|
188
|
+
});
|
|
189
|
+
flow = pickFlowMatchingBranch(candidates, args.branch || undefined);
|
|
190
|
+
if (!flow) throwHttp(400, 'No enabled review flow found for this repository');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Apply branchFilter even when flow is explicitly given (consistency)
|
|
194
|
+
if (args.branch && !branchMatches(flow, args.branch)) {
|
|
195
|
+
throwHttp(400, `Branch '${args.branch}' does not match flow's branchFilter`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const aiEmployeeUsername = flow.get('aiEmployeeUsername') as string;
|
|
199
|
+
if (!aiEmployeeUsername) throwHttp(400, 'Flow has no AI employee configured');
|
|
200
|
+
|
|
201
|
+
const repo = await db.getRepository('gitRepositories').findOne({ filterByTk: args.repositoryId });
|
|
202
|
+
if (!repo) throwHttp(404, 'Repository not found');
|
|
203
|
+
|
|
204
|
+
// For MR targets, ensure we know the head SHA so the "new commits" indicator
|
|
205
|
+
// works regardless of whether the trigger came from poller or manual UI.
|
|
206
|
+
let headSha = args.headSha || null;
|
|
207
|
+
if (args.targetType === 'mr' && !headSha && args.mrIid) {
|
|
208
|
+
headSha = await fetchMrHeadSha(db, repo, args.mrIid).catch(() => null);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Upsert review record (1 per MR/commit/branch target)
|
|
212
|
+
const reviewsRepo = db.getRepository('gitCodeReviews');
|
|
213
|
+
const targetFilter: any = {
|
|
214
|
+
repositoryId: args.repositoryId,
|
|
215
|
+
targetType: args.targetType,
|
|
216
|
+
};
|
|
217
|
+
if (args.targetType === 'mr') targetFilter.mrIid = args.mrIid;
|
|
218
|
+
else if (args.targetType === 'commit') targetFilter.commitSha = args.commitSha;
|
|
219
|
+
else if (args.targetType === 'branch') targetFilter.branch = args.branch;
|
|
220
|
+
else if (args.targetType === 'folder') {
|
|
221
|
+
targetFilter.folderPath = args.folderPath ?? '';
|
|
222
|
+
targetFilter.branch = args.branch || null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const existing = await reviewsRepo.findOne({ filter: targetFilter });
|
|
226
|
+
// Preserve a poller-tracked latestSha if we don't have a fresher one.
|
|
227
|
+
const existingLatestSha = existing?.get('latestSha') as string | null | undefined;
|
|
228
|
+
// The actor must be selected from a server-owned field when the worker
|
|
229
|
+
// executes. Refresh it on every manual requeue so an old, more-privileged
|
|
230
|
+
// creator cannot be reused. Poll-triggered reviews deliberately have no
|
|
231
|
+
// user and retain the established system/admin worker behavior.
|
|
232
|
+
const queuedActorId = args.triggeredBy === 'poll' ? null : args.userId ?? null;
|
|
233
|
+
const baseValues: any = {
|
|
234
|
+
flowId: flow.get('id'),
|
|
235
|
+
repositoryId: args.repositoryId,
|
|
236
|
+
targetType: args.targetType,
|
|
237
|
+
mrIid: args.targetType === 'mr' ? args.mrIid : null,
|
|
238
|
+
commitSha: args.targetType === 'commit' ? args.commitSha : null,
|
|
239
|
+
branch: args.branch || null,
|
|
240
|
+
folderPath: args.targetType === 'folder' ? args.folderPath ?? '' : null,
|
|
241
|
+
headSha: headSha,
|
|
242
|
+
latestSha: headSha || existingLatestSha || null,
|
|
243
|
+
triggeredBy: args.triggeredBy || 'manual',
|
|
244
|
+
status: 'pending',
|
|
245
|
+
// `startedAt` is stamped by the queue worker when execution actually
|
|
246
|
+
// starts. Pending rows are durable queue items for worker polling.
|
|
247
|
+
startedAt: null,
|
|
248
|
+
finishedAt: null,
|
|
249
|
+
durationMs: null,
|
|
250
|
+
postStatus: getInitialPostStatus(flow, args.targetType),
|
|
251
|
+
error: null,
|
|
252
|
+
metadata: {
|
|
253
|
+
queuedAt: new Date().toISOString(),
|
|
254
|
+
aiEmployeeUsername,
|
|
255
|
+
extraInstructions: args.extraInstructions || null,
|
|
256
|
+
userId: args.userId ?? null,
|
|
257
|
+
flowSnapshot: createFlowSnapshot(flow),
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
let reviewId: number;
|
|
262
|
+
if (existing) {
|
|
263
|
+
const st = existing.get('status');
|
|
264
|
+
// Treat `pending` the same as `running`: between this fn returning and
|
|
265
|
+
// the scheduled `runReview` flipping the row to `running`, a second
|
|
266
|
+
// caller would otherwise slip past and schedule a duplicate runReview.
|
|
267
|
+
// Stuck `pending` rows (process died before runReview ran) are swept
|
|
268
|
+
// by `recoverStuckReviews` on next startup.
|
|
269
|
+
if (st === 'running' || st === 'pending') {
|
|
270
|
+
return existing.get('id') as number;
|
|
271
|
+
}
|
|
272
|
+
await reviewsRepo.update({
|
|
273
|
+
filterByTk: existing.get('id'),
|
|
274
|
+
values: {
|
|
275
|
+
...baseValues,
|
|
276
|
+
createdById: queuedActorId,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
reviewId = existing.get('id') as number;
|
|
280
|
+
} else {
|
|
281
|
+
const review = await reviewsRepo.create({
|
|
282
|
+
values: {
|
|
283
|
+
...baseValues,
|
|
284
|
+
// The worker later derives its acting user from this server-owned
|
|
285
|
+
// field rather than mutable review metadata.
|
|
286
|
+
createdById: queuedActorId,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
reviewId = review.get('id') as number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Queue for background workers; the action returns as soon as the message is published.
|
|
293
|
+
await enqueueReview(app, {
|
|
294
|
+
reviewId,
|
|
295
|
+
repositoryId: args.repositoryId,
|
|
296
|
+
targetType: args.targetType,
|
|
297
|
+
mrIid: args.targetType === 'mr' ? args.mrIid : null,
|
|
298
|
+
commitSha: args.targetType === 'commit' ? args.commitSha : null,
|
|
299
|
+
branch: args.branch || undefined,
|
|
300
|
+
folderPath: args.targetType === 'folder' ? args.folderPath ?? '' : null,
|
|
301
|
+
headSha,
|
|
302
|
+
aiEmployeeUsername,
|
|
303
|
+
extraInstructions: args.extraInstructions,
|
|
304
|
+
userId: args.userId ?? null,
|
|
305
|
+
flowSnapshot: createFlowSnapshot(flow),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
return reviewId;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function registerReviewQueue(app: Application) {
|
|
312
|
+
app.eventQueue.subscribe(REVIEW_QUEUE_CHANNEL, {
|
|
313
|
+
concurrency: REVIEW_QUEUE_CONCURRENCY,
|
|
314
|
+
idle: () => isGitReviewWorker(app),
|
|
315
|
+
process: async (message: ReviewQueueMessage) => {
|
|
316
|
+
await processQueuedReview(app, message);
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
if (!isGitReviewWorker(app)) {
|
|
320
|
+
app.on('afterStart', () => clearLocalReviewMemoryQueue(app));
|
|
321
|
+
}
|
|
322
|
+
startReviewQueueProcessor(app);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function unregisterReviewQueue(app: Application) {
|
|
326
|
+
app.eventQueue.unsubscribe(REVIEW_QUEUE_CHANNEL);
|
|
327
|
+
stopReviewQueueProcessor(app);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function createFlowSnapshot(flow: any): ReviewFlowSnapshot {
|
|
331
|
+
return {
|
|
332
|
+
id: Number(flow.get('id')),
|
|
333
|
+
name: flow.get('name') as string,
|
|
334
|
+
postMode: flow.get('postMode') as string,
|
|
335
|
+
llmService: flow.get('llmService') as string | null,
|
|
336
|
+
model: flow.get('model') as string | null,
|
|
337
|
+
instructions: flow.get('instructions') as string | null,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function createFlowFromSnapshot(snapshot: ReviewFlowSnapshot | undefined, fallback?: any) {
|
|
342
|
+
return {
|
|
343
|
+
get(name: string) {
|
|
344
|
+
if (snapshot && Object.prototype.hasOwnProperty.call(snapshot, name)) {
|
|
345
|
+
return (snapshot as any)[name];
|
|
346
|
+
}
|
|
347
|
+
return fallback?.get?.(name);
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function isGitReviewWorker(app: Application): boolean {
|
|
353
|
+
return app.serving(WORKER_JOB_GIT_REVIEW_PROCESS) || workerModeServesGitReview();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function workerModeServesGitReview(): boolean {
|
|
357
|
+
const workerMode = process.env.WORKER_MODE || '';
|
|
358
|
+
const workerModes = workerMode
|
|
359
|
+
.split(',')
|
|
360
|
+
.map((mode) => mode.trim())
|
|
361
|
+
.filter(Boolean);
|
|
362
|
+
|
|
363
|
+
return workerModes.some((mode) => {
|
|
364
|
+
if (mode === '*' || mode === 'worker' || mode === 'task' || mode === WORKER_JOB_GIT_REVIEW_PROCESS) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
return REVIEW_WORKER_ALIASES.some((alias) => mode === alias || mode.endsWith(`:${alias}`));
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function clearLocalReviewMemoryQueue(app: Application) {
|
|
372
|
+
const eventQueue = (app as any).eventQueue;
|
|
373
|
+
const adapter = eventQueue?.adapter;
|
|
374
|
+
const fullChannel = eventQueue?.getFullChannel?.(REVIEW_QUEUE_CHANNEL);
|
|
375
|
+
const queue = fullChannel ? adapter?.queues?.get?.(fullChannel) : null;
|
|
376
|
+
if (!queue?.length) return;
|
|
377
|
+
|
|
378
|
+
adapter.queues.set(fullChannel, []);
|
|
379
|
+
app.log?.warn?.(
|
|
380
|
+
`git review queue: cleared ${queue.length} stale local memory message(s) on non-worker node; pending DB rows will be picked up by workers`,
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getReviewQueueRedisKey(app: Application): string {
|
|
385
|
+
const appName = (app as any).name || process.env.APP_NAME || 'main';
|
|
386
|
+
return `${appName}:plugin-git-manager:review:queue`;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function getReviewQueueRedis(app: Application): Promise<any | null> {
|
|
390
|
+
const manager = (app as any).redisConnectionManager;
|
|
391
|
+
if (!manager?.getConnectionSync) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
try {
|
|
396
|
+
const connectionString = process.env.QUEUE_ADAPTER_REDIS_URL || process.env.REDIS_URL;
|
|
397
|
+
return await manager.getConnectionSync(
|
|
398
|
+
REVIEW_QUEUE_REDIS_CONNECTION,
|
|
399
|
+
connectionString ? { connectionString } : undefined,
|
|
400
|
+
);
|
|
401
|
+
} catch (err: any) {
|
|
402
|
+
app.log?.debug?.(`git review queue: Redis queue unavailable, falling back to DB polling: ${err?.message || err}`);
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function enqueueReviewToRedis(app: Application, message: ReviewQueueMessage): Promise<boolean> {
|
|
408
|
+
const redis = await getReviewQueueRedis(app);
|
|
409
|
+
if (!redis) return false;
|
|
410
|
+
|
|
411
|
+
await redis.sendCommand(['RPUSH', getReviewQueueRedisKey(app), JSON.stringify(message)]);
|
|
412
|
+
app.log?.debug?.(`git review queue: enqueued review ${message.reviewId} to Redis`);
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function publishReviewQueueWake(app: Application, reviewId?: number) {
|
|
417
|
+
try {
|
|
418
|
+
await (app as any).pubSubManager?.publish?.(
|
|
419
|
+
REVIEW_QUEUE_WAKE_CHANNEL,
|
|
420
|
+
{ reviewId },
|
|
421
|
+
{ skipSelf: !isGitReviewWorker(app) },
|
|
422
|
+
);
|
|
423
|
+
} catch (err: any) {
|
|
424
|
+
app.log?.debug?.(`git review queue: wake publish skipped: ${err?.message || err}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function startReviewQueueProcessor(app: Application) {
|
|
429
|
+
if (!isGitReviewWorker(app)) {
|
|
430
|
+
app.log?.debug?.('plugin-git-manager: review queue processor disabled on non-worker node');
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (reviewQueueTimer) return;
|
|
434
|
+
|
|
435
|
+
reviewWakeHandler = async () => {
|
|
436
|
+
scheduleReviewQueueTick(app, 0);
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const subscribe = (app as any).pubSubManager?.subscribe?.(REVIEW_QUEUE_WAKE_CHANNEL, reviewWakeHandler);
|
|
440
|
+
if (subscribe?.catch) {
|
|
441
|
+
subscribe.catch((err: any) => app.log?.debug?.(`git review queue: wake subscribe skipped: ${err?.message || err}`));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
reviewQueueTimer = setInterval(() => scheduleReviewQueueTick(app, 0), REVIEW_QUEUE_POLL_INTERVAL_MS);
|
|
445
|
+
(reviewQueueTimer as any).unref?.();
|
|
446
|
+
scheduleReviewQueueTick(app, 1000);
|
|
447
|
+
app.log?.info?.(`plugin-git-manager: review queue processor started (interval ${REVIEW_QUEUE_POLL_INTERVAL_MS}ms)`);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function stopReviewQueueProcessor(app: Application) {
|
|
451
|
+
if (reviewQueueTimer) {
|
|
452
|
+
clearInterval(reviewQueueTimer);
|
|
453
|
+
reviewQueueTimer = null;
|
|
454
|
+
}
|
|
455
|
+
if (reviewQueueKickTimer) {
|
|
456
|
+
clearTimeout(reviewQueueKickTimer);
|
|
457
|
+
reviewQueueKickTimer = null;
|
|
458
|
+
}
|
|
459
|
+
if (reviewWakeHandler) {
|
|
460
|
+
const unsubscribe = (app as any).pubSubManager?.unsubscribe?.(REVIEW_QUEUE_WAKE_CHANNEL, reviewWakeHandler);
|
|
461
|
+
if (unsubscribe?.catch) {
|
|
462
|
+
unsubscribe.catch(() => undefined);
|
|
463
|
+
}
|
|
464
|
+
reviewWakeHandler = null;
|
|
465
|
+
}
|
|
466
|
+
reviewQueueProcessing = false;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function scheduleReviewQueueTick(app: Application, delayMs: number) {
|
|
470
|
+
if (reviewQueueKickTimer) return;
|
|
471
|
+
reviewQueueKickTimer = setTimeout(() => {
|
|
472
|
+
reviewQueueKickTimer = null;
|
|
473
|
+
runReviewQueueTick(app).catch((err) => app.log?.error?.('git review queue: processor tick failed', err));
|
|
474
|
+
}, delayMs);
|
|
475
|
+
(reviewQueueKickTimer as any).unref?.();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async function runReviewQueueTick(app: Application) {
|
|
479
|
+
if (reviewQueueProcessing || !isGitReviewWorker(app)) return;
|
|
480
|
+
|
|
481
|
+
reviewQueueProcessing = true;
|
|
482
|
+
try {
|
|
483
|
+
const redisMessages = await drainRedisReviewQueue(app, REVIEW_QUEUE_CONCURRENCY);
|
|
484
|
+
await processReviewQueueMessages(app, redisMessages);
|
|
485
|
+
|
|
486
|
+
const remaining = Math.max(1, REVIEW_QUEUE_CONCURRENCY - redisMessages.length);
|
|
487
|
+
await processPendingReviews(app, remaining);
|
|
488
|
+
} finally {
|
|
489
|
+
reviewQueueProcessing = false;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
async function drainRedisReviewQueue(app: Application, count: number): Promise<ReviewQueueMessage[]> {
|
|
494
|
+
const redis = await getReviewQueueRedis(app);
|
|
495
|
+
if (!redis) return [];
|
|
496
|
+
|
|
497
|
+
const key = getReviewQueueRedisKey(app);
|
|
498
|
+
const messages: ReviewQueueMessage[] = [];
|
|
499
|
+
for (let i = 0; i < count; i += 1) {
|
|
500
|
+
const raw = await redis.sendCommand(['LPOP', key]);
|
|
501
|
+
if (!raw) break;
|
|
502
|
+
try {
|
|
503
|
+
messages.push(JSON.parse(String(raw)));
|
|
504
|
+
} catch (err: any) {
|
|
505
|
+
app.log?.warn?.(`git review queue: dropped invalid Redis message: ${err?.message || err}`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return messages;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function getQueuedReviewMetadata(review: any): QueuedReviewMetadata {
|
|
512
|
+
const raw = review?.get?.('metadata');
|
|
513
|
+
if (!raw) return {};
|
|
514
|
+
if (typeof raw === 'string') {
|
|
515
|
+
try {
|
|
516
|
+
return JSON.parse(raw) || {};
|
|
517
|
+
} catch {
|
|
518
|
+
return {};
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return typeof raw === 'object' ? raw : {};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
type ReviewRecord = {
|
|
525
|
+
get(attribute: string): unknown;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* A queued review's metadata can be changed by database mutations, so it must
|
|
530
|
+
* never select the user whose roles the background AI run receives. The
|
|
531
|
+
* server-owned field is refreshed only by the trusted queueing path.
|
|
532
|
+
*/
|
|
533
|
+
export function resolveImmutableReviewActorId(review: ReviewRecord): number | string | null {
|
|
534
|
+
const createdById = review.get('createdById');
|
|
535
|
+
if (typeof createdById === 'number' && Number.isFinite(createdById)) {
|
|
536
|
+
return createdById;
|
|
537
|
+
}
|
|
538
|
+
if (typeof createdById === 'string' && createdById.trim()) {
|
|
539
|
+
return createdById;
|
|
540
|
+
}
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function toNullableNumber(value: any): number | null {
|
|
545
|
+
if (value === null || value === undefined || value === '') return null;
|
|
546
|
+
const parsed = Number(value);
|
|
547
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function createReviewQueueMessageFromReview(review: any): ReviewQueueMessage {
|
|
551
|
+
const metadata = getQueuedReviewMetadata(review);
|
|
552
|
+
const targetType = review.get('targetType') as 'mr' | 'commit' | 'branch' | 'folder';
|
|
553
|
+
return {
|
|
554
|
+
reviewId: Number(review.get('id')),
|
|
555
|
+
repositoryId: Number(review.get('repositoryId')),
|
|
556
|
+
targetType,
|
|
557
|
+
mrIid: targetType === 'mr' ? toNullableNumber(review.get('mrIid')) : null,
|
|
558
|
+
commitSha: targetType === 'commit' ? (review.get('commitSha') as string | null) : null,
|
|
559
|
+
branch: targetType === 'branch' || targetType === 'folder' ? (review.get('branch') as string | null) : null,
|
|
560
|
+
folderPath: targetType === 'folder' ? (review.get('folderPath') as string | null) ?? '' : null,
|
|
561
|
+
headSha: review.get('headSha') as string | null,
|
|
562
|
+
aiEmployeeUsername: metadata.aiEmployeeUsername || '',
|
|
563
|
+
extraInstructions: metadata.extraInstructions || undefined,
|
|
564
|
+
userId: metadata.userId ?? null,
|
|
565
|
+
flowSnapshot: metadata.flowSnapshot,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
async function processPendingReviews(app: Application, count: number) {
|
|
570
|
+
const pending = await app.db.getRepository('gitCodeReviews').find({
|
|
571
|
+
filter: { status: 'pending' },
|
|
572
|
+
sort: ['createdAt'],
|
|
573
|
+
limit: count,
|
|
574
|
+
});
|
|
575
|
+
if (!pending?.length) return;
|
|
576
|
+
await processReviewQueueMessages(app, pending.map(createReviewQueueMessageFromReview));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async function processReviewQueueMessages(app: Application, messages: ReviewQueueMessage[]) {
|
|
580
|
+
if (!messages.length) return;
|
|
581
|
+
await Promise.all(messages.map((message) => processQueuedReview(app, message)));
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async function withReviewProcessLock<T>(app: Application, reviewId: number, fn: () => Promise<T>): Promise<T> {
|
|
585
|
+
const lockKey = `git-review:process:${reviewId}`;
|
|
586
|
+
return app.lockManager.runExclusive(lockKey, fn, REVIEW_PROCESS_LOCK_TTL_MS);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
async function enqueueReview(app: Application, message: ReviewQueueMessage) {
|
|
590
|
+
try {
|
|
591
|
+
const queuedInRedis = await enqueueReviewToRedis(app, message);
|
|
592
|
+
if (queuedInRedis) {
|
|
593
|
+
await publishReviewQueueWake(app, message.reviewId);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
await publishReviewQueueWake(app, message.reviewId);
|
|
598
|
+
|
|
599
|
+
if (isGitReviewWorker(app)) {
|
|
600
|
+
await app.eventQueue.publish(REVIEW_QUEUE_CHANNEL, message, {
|
|
601
|
+
timeout: REVIEW_QUEUE_TIMEOUT_MS,
|
|
602
|
+
maxRetries: 1,
|
|
603
|
+
});
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
app.log?.warn?.(
|
|
608
|
+
`git review queue: Redis queue is unavailable; review ${message.reviewId} will remain pending until a worker DB poller picks it up`,
|
|
609
|
+
);
|
|
610
|
+
} catch (err: any) {
|
|
611
|
+
const safeMessage = redactPat(err?.message || String(err));
|
|
612
|
+
await app.db.getRepository('gitCodeReviews').update({
|
|
613
|
+
filterByTk: message.reviewId,
|
|
614
|
+
values: {
|
|
615
|
+
status: 'failed',
|
|
616
|
+
error: `Failed to enqueue review: ${safeMessage}`,
|
|
617
|
+
finishedAt: new Date(),
|
|
618
|
+
},
|
|
619
|
+
});
|
|
620
|
+
throw err;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async function failQueuedReview(app: Application, reviewId: number, err: any) {
|
|
625
|
+
const safeMessage = redactPat(err?.message || String(err));
|
|
626
|
+
await app.db.getRepository('gitCodeReviews').update({
|
|
627
|
+
filterByTk: reviewId,
|
|
628
|
+
values: {
|
|
629
|
+
status: 'failed',
|
|
630
|
+
error: safeMessage,
|
|
631
|
+
finishedAt: new Date(),
|
|
632
|
+
},
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
async function processQueuedReview(app: Application, message: ReviewQueueMessage) {
|
|
637
|
+
await withReviewProcessLock(app, message.reviewId, async () => {
|
|
638
|
+
const db = app.db;
|
|
639
|
+
const reviewsRepo = db.getRepository('gitCodeReviews');
|
|
640
|
+
const review = await reviewsRepo.findOne({ filterByTk: message.reviewId });
|
|
641
|
+
if (!review) {
|
|
642
|
+
app.log?.warn?.(`git review queue: review ${message.reviewId} not found, skipping`);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (review.get('status') !== 'pending') {
|
|
647
|
+
app.log?.info?.(`git review queue: review ${message.reviewId} is ${review.get('status')}, skipping`);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const metadata = getQueuedReviewMetadata(review);
|
|
652
|
+
const targetType = (message.targetType || review.get('targetType')) as 'mr' | 'commit' | 'branch' | 'folder';
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
const actorUserId = resolveImmutableReviewActorId(review);
|
|
656
|
+
if (actorUserId == null && review.get('triggeredBy') !== 'poll') {
|
|
657
|
+
throw new Error('Manual review has no immutable triggering user');
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const repo = await db.getRepository('gitRepositories').findOne({
|
|
661
|
+
filterByTk: message.repositoryId || review.get('repositoryId'),
|
|
662
|
+
});
|
|
663
|
+
if (!repo) throw new Error('Repository not found');
|
|
664
|
+
|
|
665
|
+
const flowSnapshot = message.flowSnapshot || metadata.flowSnapshot;
|
|
666
|
+
const storedFlow = await db.getRepository('gitReviewFlows').findOne({
|
|
667
|
+
filterByTk: flowSnapshot?.id || review.get('flowId'),
|
|
668
|
+
});
|
|
669
|
+
if (!storedFlow) throw new Error('Review flow not found');
|
|
670
|
+
const flowRepositoryId = storedFlow.get('repositoryId');
|
|
671
|
+
if (flowRepositoryId != null && String(flowRepositoryId) !== String(repo.get('id'))) {
|
|
672
|
+
throw new Error('Review flow does not belong to this repository');
|
|
673
|
+
}
|
|
674
|
+
const flow = createFlowFromSnapshot(flowSnapshot, storedFlow);
|
|
675
|
+
const aiEmployeeUsername =
|
|
676
|
+
message.aiEmployeeUsername || metadata.aiEmployeeUsername || (flow.get('aiEmployeeUsername') as string);
|
|
677
|
+
if (!aiEmployeeUsername) throw new Error('Flow has no AI employee configured');
|
|
678
|
+
|
|
679
|
+
await runReview(app, {
|
|
680
|
+
reviewId: message.reviewId,
|
|
681
|
+
flow,
|
|
682
|
+
repo,
|
|
683
|
+
targetType,
|
|
684
|
+
mrIid: targetType === 'mr' ? message.mrIid ?? toNullableNumber(review.get('mrIid')) : null,
|
|
685
|
+
commitSha: targetType === 'commit' ? message.commitSha || (review.get('commitSha') as string) : null,
|
|
686
|
+
branch: message.branch || (review.get('branch') as string | undefined),
|
|
687
|
+
folderPath:
|
|
688
|
+
targetType === 'folder' ? message.folderPath ?? (review.get('folderPath') as string | null) ?? '' : null,
|
|
689
|
+
headSha: message.headSha || (review.get('headSha') as string | null),
|
|
690
|
+
aiEmployeeUsername,
|
|
691
|
+
extraInstructions: message.extraInstructions ?? metadata.extraInstructions ?? undefined,
|
|
692
|
+
userId: actorUserId,
|
|
693
|
+
});
|
|
694
|
+
} catch (err) {
|
|
695
|
+
app.log?.error?.('git review queue: failed before review execution', err);
|
|
696
|
+
await failQueuedReview(app, message.reviewId, err);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Mark a review as approved and post its content to GitLab as an MR note.
|
|
703
|
+
*/
|
|
704
|
+
export async function reviewApprovePost(ctx: Context, next: () => Promise<void>) {
|
|
705
|
+
const params = getEffectiveActionParams(ctx);
|
|
706
|
+
const { reviewId, editedMarkdown } = params;
|
|
707
|
+
if (!reviewId || (typeof reviewId !== 'string' && typeof reviewId !== 'number')) {
|
|
708
|
+
ctx.throw(400, 'reviewId is required');
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const reviewsRepo = ctx.db.getRepository('gitCodeReviews');
|
|
712
|
+
const review = await reviewsRepo.findOne({ filterByTk: reviewId });
|
|
713
|
+
if (!review) ctx.throw(404, 'Review not found');
|
|
714
|
+
if (review.get('status') !== 'completed') ctx.throw(400, 'Review is not completed');
|
|
715
|
+
if (review.get('targetType') !== 'mr') ctx.throw(400, 'Only MR reviews can be posted');
|
|
716
|
+
|
|
717
|
+
const markdown = (editedMarkdown ?? review.get('reviewMarkdown')) as string;
|
|
718
|
+
if (!markdown) ctx.throw(400, 'No review content to post');
|
|
719
|
+
|
|
720
|
+
const repo = await ctx.db.getRepository('gitRepositories').findOne({
|
|
721
|
+
filterByTk: review.get('repositoryId'),
|
|
722
|
+
});
|
|
723
|
+
if (!repo) ctx.throw(404, 'Repository not found');
|
|
724
|
+
|
|
725
|
+
const noteId = await postNoteToGitLab(ctx.db, repo, Number(review.get('mrIid')), markdown);
|
|
726
|
+
|
|
727
|
+
const userId = (ctx as any).state?.currentUser?.id;
|
|
728
|
+
await reviewsRepo.update({
|
|
729
|
+
filterByTk: reviewId,
|
|
730
|
+
values: {
|
|
731
|
+
reviewMarkdown: markdown,
|
|
732
|
+
postStatus: 'posted',
|
|
733
|
+
postedNoteId: String(noteId),
|
|
734
|
+
approvedBy: userId ? String(userId) : null,
|
|
735
|
+
approvedAt: new Date(),
|
|
736
|
+
error: null,
|
|
737
|
+
},
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
ctx.body = { success: true, data: { reviewId, postedNoteId: noteId } };
|
|
741
|
+
await next();
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Reject a pending review (do not post to GitLab).
|
|
746
|
+
*/
|
|
747
|
+
export async function reviewReject(ctx: Context, next: () => Promise<void>) {
|
|
748
|
+
const params = getEffectiveActionParams(ctx);
|
|
749
|
+
const { reviewId, reason } = params;
|
|
750
|
+
if (!reviewId || (typeof reviewId !== 'string' && typeof reviewId !== 'number')) {
|
|
751
|
+
ctx.throw(400, 'reviewId is required');
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const reviewsRepo = ctx.db.getRepository('gitCodeReviews');
|
|
755
|
+
const review = await reviewsRepo.findOne({ filterByTk: reviewId });
|
|
756
|
+
if (!review) ctx.throw(404, 'Review not found');
|
|
757
|
+
|
|
758
|
+
const userId = (ctx as any).state?.currentUser?.id;
|
|
759
|
+
await reviewsRepo.update({
|
|
760
|
+
filterByTk: reviewId,
|
|
761
|
+
values: {
|
|
762
|
+
postStatus: 'rejected',
|
|
763
|
+
approvedBy: userId ? String(userId) : null,
|
|
764
|
+
approvedAt: new Date(),
|
|
765
|
+
error: reason ? `Rejected: ${reason}` : 'Rejected',
|
|
766
|
+
},
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
ctx.body = { success: true, data: { reviewId } };
|
|
770
|
+
await next();
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/* ───────── Helpers ───────── */
|
|
774
|
+
|
|
775
|
+
interface RunReviewArgs {
|
|
776
|
+
reviewId: number;
|
|
777
|
+
flow: any;
|
|
778
|
+
repo: any;
|
|
779
|
+
targetType: string;
|
|
780
|
+
mrIid: number | null;
|
|
781
|
+
commitSha: string | null;
|
|
782
|
+
branch?: string;
|
|
783
|
+
folderPath?: string | null;
|
|
784
|
+
headSha?: string | null;
|
|
785
|
+
aiEmployeeUsername: string;
|
|
786
|
+
extraInstructions?: string;
|
|
787
|
+
userId?: number | string | null;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
async function runReview(app: Application, args: RunReviewArgs) {
|
|
791
|
+
const db = app.db;
|
|
792
|
+
const reviewsRepo = db.getRepository('gitCodeReviews');
|
|
793
|
+
const startedAt = new Date();
|
|
794
|
+
let sessionId: string | null = null;
|
|
795
|
+
|
|
796
|
+
try {
|
|
797
|
+
await reviewsRepo.update({
|
|
798
|
+
filterByTk: args.reviewId,
|
|
799
|
+
values: { status: 'running', startedAt },
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
const employeeRecord = await db.getRepository('aiEmployees').findOne({
|
|
803
|
+
filter: { username: args.aiEmployeeUsername },
|
|
804
|
+
});
|
|
805
|
+
if (!employeeRecord) {
|
|
806
|
+
throw new Error(`AI employee '${args.aiEmployeeUsername}' not found`);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const conversation = await db.getRepository('aiConversations').create({
|
|
810
|
+
values: {
|
|
811
|
+
userId: args.userId ?? null,
|
|
812
|
+
aiEmployee: { username: args.aiEmployeeUsername },
|
|
813
|
+
options: {},
|
|
814
|
+
thread: 1,
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
// aiConversations uses sessionId (uuid) as primary key — no `id` field exists.
|
|
818
|
+
sessionId = (conversation.get('sessionId') as string) || null;
|
|
819
|
+
if (!sessionId) {
|
|
820
|
+
throw new Error('Failed to resolve sessionId from created aiConversation');
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
await reviewsRepo.update({
|
|
824
|
+
filterByTk: args.reviewId,
|
|
825
|
+
values: { sessionId },
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
const prompt = buildReviewPrompt(args);
|
|
829
|
+
const currentRoles = await resolveBackgroundReviewRoles(db, args.userId);
|
|
830
|
+
const currentUser = args.userId
|
|
831
|
+
? {
|
|
832
|
+
id: args.userId,
|
|
833
|
+
roles: currentRoles.map((name) => ({ name })),
|
|
834
|
+
}
|
|
835
|
+
: null;
|
|
836
|
+
|
|
837
|
+
// Synthesize a minimal ctx-shaped object that AIEmployee accepts.
|
|
838
|
+
// It needs `app`, `db`, `state.currentUser`, `get(headerName)`, `req.headers`,
|
|
839
|
+
// `action.params.values` (used in getSystemPrompt), and `res.write` (used by
|
|
840
|
+
// ChatStreamProtocol). All stubs are no-ops since we use `invoke` (not stream).
|
|
841
|
+
const syntheticCtx: any = {
|
|
842
|
+
app,
|
|
843
|
+
db,
|
|
844
|
+
isBackgroundReview: true,
|
|
845
|
+
reviewTargetRepositoryId: args.repo.get('id'),
|
|
846
|
+
state: {
|
|
847
|
+
currentUser,
|
|
848
|
+
currentRole: currentRoles[0],
|
|
849
|
+
currentRoles,
|
|
850
|
+
},
|
|
851
|
+
auth: { user: currentUser || { id: null } },
|
|
852
|
+
req: { headers: { 'x-timezone': '+00:00', 'x-locale': 'en-US' } },
|
|
853
|
+
// AIEmployee.getSystemPrompt reads ctx.action.params.values.important
|
|
854
|
+
action: { params: { values: {} } },
|
|
855
|
+
// ChatStreamProtocol.write calls ctx.res.write — stub for non-stream invoke
|
|
856
|
+
res: {
|
|
857
|
+
write() {},
|
|
858
|
+
end() {},
|
|
859
|
+
writableEnded: false,
|
|
860
|
+
},
|
|
861
|
+
log: app.logger || console,
|
|
862
|
+
logger: app.logger || console,
|
|
863
|
+
get(name: string) {
|
|
864
|
+
return this.req.headers[String(name).toLowerCase()];
|
|
865
|
+
},
|
|
866
|
+
getCurrentLocale() {
|
|
867
|
+
return 'en-US';
|
|
868
|
+
},
|
|
869
|
+
t(key: string) {
|
|
870
|
+
return key;
|
|
871
|
+
},
|
|
872
|
+
i18n: {
|
|
873
|
+
t(key: string) {
|
|
874
|
+
return key;
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
// H-3 fix: try multiple import paths for resilience against plugin-ai restructuring
|
|
880
|
+
let AIEmployee: any;
|
|
881
|
+
for (const importPath of [
|
|
882
|
+
'@nocobase/plugin-ai/dist/server/ai-employees/ai-employee.js',
|
|
883
|
+
'@nocobase/plugin-ai/dist/server/ai-employees/ai-employee',
|
|
884
|
+
'@nocobase/plugin-ai/server',
|
|
885
|
+
]) {
|
|
886
|
+
try {
|
|
887
|
+
const mod = await import(/* webpackIgnore: true */ importPath as any);
|
|
888
|
+
AIEmployee = (mod as any).AIEmployee || (mod as any).default?.AIEmployee;
|
|
889
|
+
if (AIEmployee) break;
|
|
890
|
+
} catch {
|
|
891
|
+
// try next path
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (!AIEmployee)
|
|
895
|
+
throw new Error('AIEmployee class not found — plugin-ai may not be installed or its exports changed');
|
|
896
|
+
|
|
897
|
+
const llmService = args.flow.get('llmService') as string | null;
|
|
898
|
+
const model = args.flow.get('model') as string | null;
|
|
899
|
+
const modelRef = llmService && model ? { llmService, model } : undefined;
|
|
900
|
+
|
|
901
|
+
const aiEmployee = new AIEmployee({
|
|
902
|
+
ctx: syntheticCtx,
|
|
903
|
+
employee: employeeRecord,
|
|
904
|
+
sessionId,
|
|
905
|
+
systemMessage: undefined,
|
|
906
|
+
skillSettings: undefined,
|
|
907
|
+
webSearch: false,
|
|
908
|
+
model: modelRef,
|
|
909
|
+
legacy: false,
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
// H-4 fix: enforce a timeout on AI review execution to prevent stuck reviews
|
|
913
|
+
const REVIEW_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
914
|
+
const result = await Promise.race([
|
|
915
|
+
aiEmployee.invoke({
|
|
916
|
+
userMessages: [
|
|
917
|
+
{
|
|
918
|
+
role: 'user',
|
|
919
|
+
content: { type: 'text', content: prompt },
|
|
920
|
+
},
|
|
921
|
+
],
|
|
922
|
+
}),
|
|
923
|
+
new Promise<never>((_resolve, reject) =>
|
|
924
|
+
setTimeout(() => reject(new Error('AI review timed out after 5 minutes')), REVIEW_TIMEOUT_MS),
|
|
925
|
+
),
|
|
926
|
+
]);
|
|
927
|
+
|
|
928
|
+
const content = extractLastAiMessageContent(result);
|
|
929
|
+
if (!content) {
|
|
930
|
+
throw new Error('AI employee returned empty review content');
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const finishedAt = new Date();
|
|
934
|
+
const durationMs = finishedAt.getTime() - startedAt.getTime();
|
|
935
|
+
|
|
936
|
+
const postMode = getFlowPostMode(args.flow);
|
|
937
|
+
let postStatus = getInitialPostStatus(args.flow, args.targetType);
|
|
938
|
+
let postedNoteId: string | null = null;
|
|
939
|
+
let autoPostError: string | null = null;
|
|
940
|
+
|
|
941
|
+
if (postMode === 'disabled') {
|
|
942
|
+
postStatus = 'skipped';
|
|
943
|
+
} else if (postMode === 'auto' && args.targetType === 'mr' && args.mrIid) {
|
|
944
|
+
try {
|
|
945
|
+
postedNoteId = String(await postNoteToGitLab(db, args.repo, args.mrIid, content));
|
|
946
|
+
postStatus = 'posted';
|
|
947
|
+
} catch (err: any) {
|
|
948
|
+
autoPostError = redactPat(err?.message || String(err));
|
|
949
|
+
postStatus = 'post_failed';
|
|
950
|
+
app.log?.error?.('Auto-post review note failed', err);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
await reviewsRepo.update({
|
|
955
|
+
filterByTk: args.reviewId,
|
|
956
|
+
values: {
|
|
957
|
+
status: 'completed',
|
|
958
|
+
reviewMarkdown: content,
|
|
959
|
+
rawOutput: JSON.stringify({
|
|
960
|
+
messageCount: result?.messages?.length ?? 0,
|
|
961
|
+
llmService: llmService || 'default',
|
|
962
|
+
model: model || 'default',
|
|
963
|
+
}),
|
|
964
|
+
durationMs,
|
|
965
|
+
finishedAt,
|
|
966
|
+
postStatus,
|
|
967
|
+
postedNoteId,
|
|
968
|
+
error: autoPostError ? `Auto-post failed: ${autoPostError}` : null,
|
|
969
|
+
metadata: {
|
|
970
|
+
flowName: args.flow.get('name'),
|
|
971
|
+
aiEmployeeUsername: args.aiEmployeeUsername,
|
|
972
|
+
llmService,
|
|
973
|
+
model,
|
|
974
|
+
postMode,
|
|
975
|
+
autoPostError,
|
|
976
|
+
},
|
|
977
|
+
},
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
if (sessionId) {
|
|
981
|
+
db.getRepository('aiConversations')
|
|
982
|
+
.destroy({ filterByTk: sessionId })
|
|
983
|
+
.catch(() => undefined);
|
|
984
|
+
}
|
|
985
|
+
} catch (err: any) {
|
|
986
|
+
const finishedAt = new Date();
|
|
987
|
+
// Redact PAT before persisting the error — simple-git / fetch errors
|
|
988
|
+
// can echo back the authenticated remote URL in their messages.
|
|
989
|
+
const safeMessage = redactPat(err?.message || String(err));
|
|
990
|
+
app.log?.error?.(`git review ${args.reviewId} failed: ${safeMessage}`, err);
|
|
991
|
+
await reviewsRepo.update({
|
|
992
|
+
filterByTk: args.reviewId,
|
|
993
|
+
values: {
|
|
994
|
+
status: 'failed',
|
|
995
|
+
error: safeMessage,
|
|
996
|
+
finishedAt,
|
|
997
|
+
durationMs: finishedAt.getTime() - startedAt.getTime(),
|
|
998
|
+
},
|
|
999
|
+
});
|
|
1000
|
+
if (sessionId) {
|
|
1001
|
+
db.getRepository('aiConversations')
|
|
1002
|
+
.destroy({ filterByTk: sessionId })
|
|
1003
|
+
.catch(() => undefined);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
type BackgroundReviewRoleRepository = {
|
|
1009
|
+
find(input: { filter?: { userId: number | string }; raw: true }): Promise<unknown>;
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
type BackgroundReviewRoleDatabase = {
|
|
1013
|
+
getRepository(name: 'users.roles' | 'rolesUsers', sourceKey?: number | string): BackgroundReviewRoleRepository;
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
export async function resolveBackgroundReviewRoles(
|
|
1017
|
+
db: BackgroundReviewRoleDatabase,
|
|
1018
|
+
userId?: number | string | null,
|
|
1019
|
+
): Promise<string[]> {
|
|
1020
|
+
if (!userId) return ['admin'];
|
|
1021
|
+
|
|
1022
|
+
try {
|
|
1023
|
+
const roles = await db.getRepository('users.roles', userId).find({ raw: true });
|
|
1024
|
+
const roleNames = (Array.isArray(roles) ? roles : [])
|
|
1025
|
+
.map((role: unknown) => (role && typeof role === 'object' ? (role as { name?: unknown }).name : undefined))
|
|
1026
|
+
.filter((name: unknown): name is string => typeof name === 'string' && !!name);
|
|
1027
|
+
if (roleNames.length) return roleNames;
|
|
1028
|
+
} catch {
|
|
1029
|
+
// Fall back to the through table below for apps where the association
|
|
1030
|
+
// repository is unavailable in a background worker context.
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
try {
|
|
1034
|
+
const mappings = await db.getRepository('rolesUsers').find({
|
|
1035
|
+
filter: { userId },
|
|
1036
|
+
raw: true,
|
|
1037
|
+
});
|
|
1038
|
+
const roleNames = (Array.isArray(mappings) ? mappings : [])
|
|
1039
|
+
.map((mapping: unknown) =>
|
|
1040
|
+
mapping && typeof mapping === 'object' ? (mapping as { roleName?: unknown }).roleName : undefined,
|
|
1041
|
+
)
|
|
1042
|
+
.filter((name: unknown): name is string => typeof name === 'string' && !!name);
|
|
1043
|
+
if (roleNames.length) return roleNames;
|
|
1044
|
+
} catch {
|
|
1045
|
+
// The manual actor must not inherit an administrative fallback.
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
throw new Error('Unable to resolve roles for review actor');
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function buildReviewPrompt(args: RunReviewArgs): string {
|
|
1052
|
+
const lines: string[] = [];
|
|
1053
|
+
lines.push(`You are performing a code review on repository "${args.repo.get('name')}" (id=${args.repo.get('id')}).`);
|
|
1054
|
+
lines.push('');
|
|
1055
|
+
|
|
1056
|
+
if (args.targetType === 'mr') {
|
|
1057
|
+
lines.push(`Target: Merge Request !${args.mrIid}.`);
|
|
1058
|
+
lines.push(
|
|
1059
|
+
`Use the \`git_get_merge_request\` tool with repositoryId=${args.repo.get('id')} and mrIid=${
|
|
1060
|
+
args.mrIid
|
|
1061
|
+
} to fetch the diff and metadata.`,
|
|
1062
|
+
);
|
|
1063
|
+
lines.push('Optionally call `git_get_merge_request_notes` to avoid duplicating prior comments.');
|
|
1064
|
+
} else if (args.targetType === 'commit') {
|
|
1065
|
+
lines.push(`Target: Commit ${args.commitSha}.`);
|
|
1066
|
+
lines.push(
|
|
1067
|
+
`Use the \`git_get_commit\` tool with repositoryId=${args.repo.get('id')} and commitHash=${
|
|
1068
|
+
args.commitSha
|
|
1069
|
+
} to fetch the diff.`,
|
|
1070
|
+
);
|
|
1071
|
+
} else if (args.targetType === 'folder') {
|
|
1072
|
+
const folderLabel = args.folderPath || '/';
|
|
1073
|
+
const ref = args.branch || 'HEAD';
|
|
1074
|
+
lines.push(
|
|
1075
|
+
`Target: Folder \`${folderLabel}\` at ref \`${ref}\` — review the FULL current code inside this folder (not a diff).`,
|
|
1076
|
+
);
|
|
1077
|
+
lines.push(
|
|
1078
|
+
'The repository may contain multiple projects; only review files inside this folder and its subfolders.',
|
|
1079
|
+
);
|
|
1080
|
+
lines.push(
|
|
1081
|
+
`First call \`git_list_files\` with repositoryId=${args.repo.get('id')}, treePath="${
|
|
1082
|
+
args.folderPath || ''
|
|
1083
|
+
}", ref="${ref}", recursive=true to enumerate all files.`,
|
|
1084
|
+
);
|
|
1085
|
+
lines.push(
|
|
1086
|
+
`Then read each file worth reviewing with \`git_get_file_content\` (repositoryId=${args.repo.get(
|
|
1087
|
+
'id',
|
|
1088
|
+
)}, ref="${ref}").`,
|
|
1089
|
+
);
|
|
1090
|
+
lines.push(
|
|
1091
|
+
'Prioritize source code and configuration files; skip binaries, images, lock files, and generated/vendored code. If the listing is truncated, focus on the most important files.',
|
|
1092
|
+
);
|
|
1093
|
+
} else {
|
|
1094
|
+
lines.push(`Target: Branch ${args.branch}.`);
|
|
1095
|
+
lines.push(
|
|
1096
|
+
`Use \`git_list_commits\`, \`git_get_diff\`, and \`git_get_file_content\` (with repositoryId=${args.repo.get(
|
|
1097
|
+
'id',
|
|
1098
|
+
)}) to inspect recent changes on this branch.`,
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
lines.push('');
|
|
1103
|
+
lines.push('Produce a thorough but concise code review report in Markdown. Required sections:');
|
|
1104
|
+
lines.push('1. **Summary** — overall assessment.');
|
|
1105
|
+
lines.push(
|
|
1106
|
+
'2. **Findings** — issues grouped by severity (`Critical`, `High`, `Medium`, `Low`, `Info`). For each finding include the file path, line/range when possible, the problem, and a suggested fix.',
|
|
1107
|
+
);
|
|
1108
|
+
lines.push('3. **Suggestions** — non-blocking improvements.');
|
|
1109
|
+
lines.push('4. **Verdict** — one of: `LGTM`, `Approve with comments`, `Request changes`, `Block`.');
|
|
1110
|
+
lines.push('');
|
|
1111
|
+
lines.push('Cite code snippets in fenced code blocks. Do not output anything outside the Markdown report.');
|
|
1112
|
+
|
|
1113
|
+
const flowInstructions = args.flow.get('instructions') as string;
|
|
1114
|
+
if (flowInstructions) {
|
|
1115
|
+
lines.push('');
|
|
1116
|
+
lines.push('---');
|
|
1117
|
+
lines.push('Additional instructions from the review flow:');
|
|
1118
|
+
lines.push(flowInstructions);
|
|
1119
|
+
}
|
|
1120
|
+
if (args.extraInstructions) {
|
|
1121
|
+
lines.push('');
|
|
1122
|
+
lines.push('---');
|
|
1123
|
+
lines.push('Additional instructions for this run:');
|
|
1124
|
+
lines.push(args.extraInstructions);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
return lines.join('\n');
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Pick the AI's final reply out of a LangChain-style message list.
|
|
1132
|
+
*
|
|
1133
|
+
* The previous implementation relied solely on `constructor.name`, which is
|
|
1134
|
+
* unsafe under bundling/minification (class names can be mangled to single
|
|
1135
|
+
* letters) and after JSON serialisation (instances become plain objects).
|
|
1136
|
+
* The new logic checks several signals in order: LangChain's `_getType()`,
|
|
1137
|
+
* an explicit `role` field, then the constructor name as a last resort.
|
|
1138
|
+
*/
|
|
1139
|
+
function extractLastAiMessageContent(result: any): string {
|
|
1140
|
+
const messages = result?.messages;
|
|
1141
|
+
if (!Array.isArray(messages)) return '';
|
|
1142
|
+
|
|
1143
|
+
const isAiMessage = (msg: any): boolean => {
|
|
1144
|
+
if (!msg) return false;
|
|
1145
|
+
if (typeof msg._getType === 'function') {
|
|
1146
|
+
try {
|
|
1147
|
+
return msg._getType() === 'ai';
|
|
1148
|
+
} catch {
|
|
1149
|
+
// fall through to other signals
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
if (typeof msg.role === 'string') {
|
|
1153
|
+
const r = msg.role.toLowerCase();
|
|
1154
|
+
return r === 'assistant' || r === 'ai';
|
|
1155
|
+
}
|
|
1156
|
+
if (typeof msg.type === 'string' && msg.type.toLowerCase() === 'ai') return true;
|
|
1157
|
+
const name = msg?.constructor?.name;
|
|
1158
|
+
if (name === 'AIMessage' || name === 'AIMessageChunk') return true;
|
|
1159
|
+
return false;
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
const getContent = (msg: any): string => {
|
|
1163
|
+
if (typeof msg.content === 'string') return msg.content;
|
|
1164
|
+
if (Array.isArray(msg.content)) {
|
|
1165
|
+
const textBlock = msg.content.find((c: any) => c?.type === 'text');
|
|
1166
|
+
if (typeof textBlock?.text === 'string') return textBlock.text;
|
|
1167
|
+
}
|
|
1168
|
+
return '';
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1172
|
+
const msg = messages[i];
|
|
1173
|
+
if (!isAiMessage(msg)) continue;
|
|
1174
|
+
const content = getContent(msg);
|
|
1175
|
+
if (content) return content;
|
|
1176
|
+
}
|
|
1177
|
+
return '';
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
async function fetchMrHeadSha(db: any, repo: any, mrIid: number): Promise<string | null> {
|
|
1181
|
+
const account = await getRepoAccount(db, repo);
|
|
1182
|
+
const pat = account?.pat || '';
|
|
1183
|
+
if (!pat) return null;
|
|
1184
|
+
const repoUrl = repo.get('repoUrl') as string;
|
|
1185
|
+
const isGitHub = account?.provider === 'github' || new URL(repoUrl).hostname === 'github.com';
|
|
1186
|
+
|
|
1187
|
+
try {
|
|
1188
|
+
if (isGitHub) {
|
|
1189
|
+
const { projectPath } = parseGitLabProject(repoUrl);
|
|
1190
|
+
const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls/${mrIid}`, {
|
|
1191
|
+
redirect: 'error',
|
|
1192
|
+
headers: { Authorization: `Bearer ${pat}`, Accept: 'application/vnd.github.v3+json' },
|
|
1193
|
+
});
|
|
1194
|
+
if (!response.ok) return null;
|
|
1195
|
+
const data = await response.json();
|
|
1196
|
+
return data?.head?.sha || null;
|
|
1197
|
+
} else {
|
|
1198
|
+
const { apiBase, encodedProject } = parseGitLabProject(repoUrl);
|
|
1199
|
+
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}`, {
|
|
1200
|
+
redirect: 'error',
|
|
1201
|
+
headers: { 'PRIVATE-TOKEN': pat, Accept: 'application/json' },
|
|
1202
|
+
});
|
|
1203
|
+
if (!response.ok) return null;
|
|
1204
|
+
const data = await response.json();
|
|
1205
|
+
return (data?.sha as string) || (data?.diff_refs?.head_sha as string) || null;
|
|
1206
|
+
}
|
|
1207
|
+
} catch {
|
|
1208
|
+
return null;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
async function postNoteToGitLab(db: any, repo: any, mrIid: number, body: string): Promise<number | string> {
|
|
1213
|
+
const account = await getRepoAccount(db, repo);
|
|
1214
|
+
const pat = account?.pat || '';
|
|
1215
|
+
const repoUrl = repo.get('repoUrl') as string;
|
|
1216
|
+
const isGitHub = account?.provider === 'github' || new URL(repoUrl).hostname === 'github.com';
|
|
1217
|
+
|
|
1218
|
+
if (isGitHub) {
|
|
1219
|
+
if (!pat) throw new Error('Repository has no PAT configured');
|
|
1220
|
+
const { projectPath } = parseGitLabProject(repoUrl);
|
|
1221
|
+
|
|
1222
|
+
const response = await fetch(`https://api.github.com/repos/${projectPath}/issues/${mrIid}/comments`, {
|
|
1223
|
+
redirect: 'error',
|
|
1224
|
+
method: 'POST',
|
|
1225
|
+
headers: {
|
|
1226
|
+
Authorization: `Bearer ${pat}`,
|
|
1227
|
+
'Content-Type': 'application/json',
|
|
1228
|
+
Accept: 'application/vnd.github.v3+json',
|
|
1229
|
+
},
|
|
1230
|
+
body: JSON.stringify({ body }),
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
if (!response.ok) {
|
|
1234
|
+
const text = await response.text().catch(() => '');
|
|
1235
|
+
throw new Error(`GitHub note post failed ${response.status}: ${text}`);
|
|
1236
|
+
}
|
|
1237
|
+
const data = await response.json();
|
|
1238
|
+
return data?.id;
|
|
1239
|
+
} else {
|
|
1240
|
+
if (!pat) throw new Error('Repository has no PAT configured');
|
|
1241
|
+
|
|
1242
|
+
const { apiBase, encodedProject } = parseGitLabProject(repoUrl);
|
|
1243
|
+
|
|
1244
|
+
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}/notes`, {
|
|
1245
|
+
redirect: 'error',
|
|
1246
|
+
method: 'POST',
|
|
1247
|
+
headers: {
|
|
1248
|
+
'PRIVATE-TOKEN': pat,
|
|
1249
|
+
'Content-Type': 'application/json',
|
|
1250
|
+
Accept: 'application/json',
|
|
1251
|
+
},
|
|
1252
|
+
body: JSON.stringify({ body }),
|
|
1253
|
+
});
|
|
1254
|
+
if (!response.ok) {
|
|
1255
|
+
const text = await response.text().catch(() => '');
|
|
1256
|
+
throw new Error(`GitLab note post failed ${response.status}: ${text}`);
|
|
1257
|
+
}
|
|
1258
|
+
const data = await response.json();
|
|
1259
|
+
return data?.id;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/* ───────── Flow matching helpers ───────── */
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* H-1 fix: guard against ReDoS by limiting regex length and wrapping
|
|
1267
|
+
* execution in a try-catch.
|
|
1268
|
+
*
|
|
1269
|
+
* Fail-closed: an invalid or oversized pattern means "no branch matches".
|
|
1270
|
+
* Reviewing all branches when a user explicitly configured a filter is more
|
|
1271
|
+
* dangerous (auto-posts to GitLab, consumes LLM credits) than skipping a
|
|
1272
|
+
* malformed flow. The poller logs once per process so misconfiguration is
|
|
1273
|
+
* still observable.
|
|
1274
|
+
*/
|
|
1275
|
+
const MAX_BRANCH_FILTER_LENGTH = 200;
|
|
1276
|
+
const loggedBadFilters = new Set<string>();
|
|
1277
|
+
|
|
1278
|
+
type ReviewPostMode = 'auto' | 'manual' | 'disabled';
|
|
1279
|
+
|
|
1280
|
+
function getFlowPostMode(flow: any): ReviewPostMode {
|
|
1281
|
+
const rawValue = flow?.get?.('postMode');
|
|
1282
|
+
const value = rawValue && typeof rawValue === 'object' && 'value' in rawValue ? rawValue.value : rawValue;
|
|
1283
|
+
const normalized = String(value || 'manual')
|
|
1284
|
+
.trim()
|
|
1285
|
+
.toLowerCase()
|
|
1286
|
+
.replace(/[\s-]+/g, '_');
|
|
1287
|
+
|
|
1288
|
+
if (['auto', 'auto_post', 'autopost', 'auto_post_to_mr'].includes(normalized)) return 'auto';
|
|
1289
|
+
if (['disabled', 'disable', 'do_not_post', 'dont_post', 'none', 'skip', 'skipped'].includes(normalized)) {
|
|
1290
|
+
return 'disabled';
|
|
1291
|
+
}
|
|
1292
|
+
return 'manual';
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function getInitialPostStatus(flow: any, targetType: string): string {
|
|
1296
|
+
const postMode = getFlowPostMode(flow);
|
|
1297
|
+
if (postMode === 'disabled') return 'skipped';
|
|
1298
|
+
// Folder reviews have no MR to post to.
|
|
1299
|
+
if (targetType === 'folder') return 'skipped';
|
|
1300
|
+
if (postMode === 'auto' && targetType !== 'mr') return 'skipped';
|
|
1301
|
+
return 'pending_approval';
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
function warnInvalidBranchFilter(filter: string, reason: string) {
|
|
1305
|
+
if (loggedBadFilters.has(filter)) return;
|
|
1306
|
+
loggedBadFilters.add(filter);
|
|
1307
|
+
console.warn(
|
|
1308
|
+
`[plugin-git-manager] branchFilter rejected (${reason}): ${JSON.stringify(
|
|
1309
|
+
filter,
|
|
1310
|
+
)}. Flow will not match any branch.`,
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
export function branchMatches(flow: any, branch: string): boolean {
|
|
1315
|
+
const filter = flow.get('branchFilter') as string | null;
|
|
1316
|
+
if (!filter) return true;
|
|
1317
|
+
if (filter.length > MAX_BRANCH_FILTER_LENGTH) {
|
|
1318
|
+
warnInvalidBranchFilter(filter, `too long (>${MAX_BRANCH_FILTER_LENGTH} chars)`);
|
|
1319
|
+
return false;
|
|
1320
|
+
}
|
|
1321
|
+
try {
|
|
1322
|
+
return new RegExp(filter).test(branch);
|
|
1323
|
+
} catch (err: any) {
|
|
1324
|
+
warnInvalidBranchFilter(filter, `invalid regex: ${err?.message || err}`);
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export function pickFlowMatchingBranch(flows: any[], branch?: string): any | null {
|
|
1330
|
+
if (!flows?.length) return null;
|
|
1331
|
+
if (!branch) return flows[0];
|
|
1332
|
+
for (const f of flows) {
|
|
1333
|
+
if (branchMatches(f, branch)) return f;
|
|
1334
|
+
}
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
function throwHttp(status: number, message: string): never {
|
|
1339
|
+
const err: any = new Error(message);
|
|
1340
|
+
err.status = status;
|
|
1341
|
+
throw err;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* Review execution is delegated to worker queue processing. When a worker
|
|
1346
|
+
* restarts mid-run, the DB record can stay in `status='running'` indefinitely.
|
|
1347
|
+
* On startup we sweep any `running` review whose `startedAt` is older than the
|
|
1348
|
+
* in-process timeout (5 min) plus a safety margin and mark it as failed.
|
|
1349
|
+
*
|
|
1350
|
+
* The cutoff is intentionally larger than the runtime timeout so concurrent
|
|
1351
|
+
* reviews running on a *different* node in an HA cluster aren't clobbered.
|
|
1352
|
+
*/
|
|
1353
|
+
const STUCK_REVIEW_CUTOFF_MS = 10 * 60 * 1000; // 10 minutes
|
|
1354
|
+
|
|
1355
|
+
export async function recoverStuckReviews(app: Application): Promise<number> {
|
|
1356
|
+
try {
|
|
1357
|
+
const reviewsRepo = app.db.getRepository('gitCodeReviews');
|
|
1358
|
+
const cutoff = new Date(Date.now() - STUCK_REVIEW_CUTOFF_MS);
|
|
1359
|
+
// Pending rows are the durable queue source of truth and are picked up by
|
|
1360
|
+
// worker DB polling, so only sweep reviews that were actually claimed.
|
|
1361
|
+
const stuck = await reviewsRepo.find({
|
|
1362
|
+
filter: {
|
|
1363
|
+
status: 'running',
|
|
1364
|
+
startedAt: { $lt: cutoff },
|
|
1365
|
+
},
|
|
1366
|
+
});
|
|
1367
|
+
if (!stuck?.length) return 0;
|
|
1368
|
+
const finishedAt = new Date();
|
|
1369
|
+
for (const review of stuck) {
|
|
1370
|
+
const startedAt = review.get('startedAt') as Date | null;
|
|
1371
|
+
const durationMs = startedAt ? finishedAt.getTime() - new Date(startedAt).getTime() : null;
|
|
1372
|
+
await reviewsRepo.update({
|
|
1373
|
+
filterByTk: review.get('id'),
|
|
1374
|
+
values: {
|
|
1375
|
+
status: 'failed',
|
|
1376
|
+
error: 'Review interrupted by application restart',
|
|
1377
|
+
finishedAt,
|
|
1378
|
+
durationMs,
|
|
1379
|
+
},
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
app.log?.info?.(`plugin-git-manager: marked ${stuck.length} stuck review(s) as failed after restart`);
|
|
1383
|
+
return stuck.length;
|
|
1384
|
+
} catch (err: any) {
|
|
1385
|
+
app.log?.error?.(`plugin-git-manager: recoverStuckReviews failed: ${err?.message}`);
|
|
1386
|
+
return 0;
|
|
1387
|
+
}
|
|
1388
|
+
}
|