plugin-git-manager 1.1.7 → 1.1.10

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 (38) hide show
  1. package/dist/client/187.08dd0bf4d0f68036.js +10 -0
  2. package/dist/client/components/LLMModelSelect.d.ts +10 -0
  3. package/dist/client/components/RunReviewButton.d.ts +1 -1
  4. package/dist/client/context/GitManagerContext.d.ts +2 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/externalVersion.js +6 -4
  7. package/dist/locale/en-US.json +8 -1
  8. package/dist/server/actions/gitlab-api.js +14 -13
  9. package/dist/server/actions/review.js +15 -9
  10. package/dist/server/ai-tools.js +29 -3
  11. package/dist/server/collections/gitCodeReviews.d.ts +1 -1
  12. package/dist/server/collections/gitRepositories.d.ts +1 -1
  13. package/dist/server/collections/gitRepositories.js +12 -0
  14. package/dist/server/collections/gitReviewFlows.d.ts +1 -1
  15. package/dist/server/migrations/20260508000000-add-auto-review-flow-id.d.ts +6 -0
  16. package/dist/server/migrations/20260508000000-add-auto-review-flow-id.js +57 -0
  17. package/dist/server/plugin.d.ts +4 -0
  18. package/dist/server/plugin.js +38 -6
  19. package/dist/server/poller.js +3 -1
  20. package/package.json +1 -1
  21. package/src/client/components/CommitHistory.tsx +18 -3
  22. package/src/client/components/GitOperations.tsx +29 -16
  23. package/src/client/components/LLMModelSelect.tsx +63 -0
  24. package/src/client/components/PollingStatus.tsx +27 -1
  25. package/src/client/components/RepositoryConfig.tsx +76 -3
  26. package/src/client/components/ReviewFlows.tsx +17 -2
  27. package/src/client/components/RunReviewButton.tsx +375 -278
  28. package/src/client/context/GitManagerContext.tsx +2 -0
  29. package/src/client/index.tsx +31 -31
  30. package/src/locale/en-US.json +8 -1
  31. package/src/server/actions/gitlab-api.ts +8 -4
  32. package/src/server/actions/review.ts +9 -3
  33. package/src/server/ai-tools.ts +31 -3
  34. package/src/server/collections/gitRepositories.ts +12 -0
  35. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -0
  36. package/src/server/plugin.ts +216 -180
  37. package/src/server/poller.ts +11 -2
  38. package/dist/client/322.c934c7c0e25a75b0.js +0 -10
@@ -1,180 +1,216 @@
1
- import { Plugin } from '@nocobase/server';
2
- import { resolve } from 'path';
3
- import * as gitActions from './actions/git-actions';
4
- import * as gitlabApi from './actions/gitlab-api';
5
- import * as reviewActions from './actions/review';
6
- import * as pollerActions from './actions/poller';
7
- import { recoverStuckReviews } from './actions/review';
8
- import { registerGitReviewAiTools } from './ai-tools';
9
- import { startPoller, stopPoller } from './poller';
10
-
11
-
12
- export class PluginGitManagerServer extends Plugin {
13
- async load() {
14
- // Ensure dayjs timezone + utc plugins are loaded globally to prevent 'm.startOf is not a function' errors
15
- const dayjsLib = require('dayjs');
16
- const utcPlugin = require('dayjs/plugin/utc');
17
- const timezonePlugin = require('dayjs/plugin/timezone');
18
- dayjsLib.extend(utcPlugin);
19
- dayjsLib.extend(timezonePlugin);
20
-
21
- await this.db.import({
22
- directory: resolve(__dirname, 'collections'),
23
- });
24
-
25
- this.app.resourceManager.define({
26
- name: 'gitManager',
27
- actions: {
28
- clone: gitActions.clone,
29
- pull: gitActions.pull,
30
- push: gitActions.push,
31
- fetch: gitActions.fetch,
32
- diff: gitActions.diff,
33
- status: gitActions.status,
34
- log: gitActions.log,
35
- branches: gitActions.branches,
36
- checkout: gitActions.checkout,
37
- fileTree: gitActions.fileTree,
38
- fileContent: gitActions.fileContent,
39
- commitDetail: gitActions.commitDetail,
40
- mergeRequests: gitlabApi.mergeRequests,
41
- mergeRequestDetail: gitlabApi.mergeRequestDetail,
42
- mergeRequestNotes: gitlabApi.mergeRequestNotes,
43
- triggerReview: reviewActions.triggerReview,
44
- reviewApprovePost: reviewActions.reviewApprovePost,
45
- reviewReject: reviewActions.reviewReject,
46
- pollNow: pollerActions.pollNow,
47
- pollerStatus: pollerActions.pollerStatus,
48
- },
49
- });
50
-
51
- // Suppress noisy workflow pre-action/post-action warnings for custom resources
52
- this.app.use(async (ctx, next) => {
53
- if (ctx.logger && ctx.logger.warn) {
54
- const originalWarn = ctx.logger.warn.bind(ctx.logger);
55
- ctx.logger.warn = (message: any, ...args: any[]) => {
56
- if (
57
- typeof message === 'string' &&
58
- message.includes('[Workflow') &&
59
- message.includes('collection') &&
60
- message.includes('not found')
61
- ) {
62
- return ctx.logger;
63
- }
64
- return originalWarn(message, ...args);
65
- };
66
- }
67
- return next();
68
- });
69
-
70
- registerGitReviewAiTools(this.app);
71
-
72
- this.app.on('afterStart', () => {
73
- // Sweep any review left in `running` state from a previous process.
74
- recoverStuckReviews(this.app).catch((err) =>
75
- this.app.log?.error?.('plugin-git-manager: recoverStuckReviews error', err),
76
- );
77
- startPoller(this.app);
78
- });
79
- this.app.on('beforeStop', () => {
80
- stopPoller();
81
- });
82
- this.app.on('beforeDestroy', () => {
83
- stopPoller();
84
- });
85
-
86
- // Read-only operations available to all plugin users
87
- this.app.acl.registerSnippet({
88
- name: `pm.${this.name}.read`,
89
- actions: [
90
- 'gitRepositories:list',
91
- 'gitRepositories:get',
92
- 'gitReviewFlows:list',
93
- 'gitReviewFlows:get',
94
- 'gitCodeReviews:list',
95
- 'gitCodeReviews:get',
96
- 'gitManager:status',
97
- 'gitManager:log',
98
- 'gitManager:branches',
99
- 'gitManager:diff',
100
- 'gitManager:fileTree',
101
- 'gitManager:fileContent',
102
- 'gitManager:commitDetail',
103
- 'gitManager:mergeRequests',
104
- 'gitManager:mergeRequestDetail',
105
- 'gitManager:mergeRequestNotes',
106
- 'gitManager:pollerStatus',
107
- ],
108
- });
109
-
110
- // Write operations require separate permission
111
- this.app.acl.registerSnippet({
112
- name: `pm.${this.name}.write`,
113
- actions: [
114
- 'gitRepositories:create',
115
- 'gitRepositories:update',
116
- 'gitRepositories:destroy',
117
- 'gitReviewFlows:create',
118
- 'gitReviewFlows:update',
119
- 'gitReviewFlows:destroy',
120
- 'gitCodeReviews:create',
121
- 'gitCodeReviews:update',
122
- 'gitCodeReviews:destroy',
123
- 'gitManager:clone',
124
- 'gitManager:pull',
125
- 'gitManager:push',
126
- 'gitManager:fetch',
127
- 'gitManager:checkout',
128
- 'gitManager:triggerReview',
129
- 'gitManager:reviewApprovePost',
130
- 'gitManager:reviewReject',
131
- 'gitManager:pollNow',
132
- ],
133
- });
134
-
135
- // Prevent overwriting PAT with obfuscated value on updates
136
- this.app.resourceManager.use(async (ctx, next) => {
137
- if (
138
- ctx.action?.resourceName === 'gitRepositories' &&
139
- ['create', 'update'].includes(ctx.action?.actionName)
140
- ) {
141
- if (ctx.action.params?.values?.pat === '••••••••') {
142
- delete ctx.action.params.values.pat;
143
- }
144
- if (ctx.request.body?.pat === '••••••••') {
145
- delete ctx.request.body.pat;
146
- }
147
- }
148
- return next();
149
- });
150
-
151
- // Strip PAT from API responses — scoped to gitRepositories only
152
- this.app.resourceManager.use(async (ctx, next) => {
153
- if (ctx.action?.resourceName !== 'gitRepositories') {
154
- return next();
155
- }
156
- await next();
157
- if (ctx.body) {
158
- const items = Array.isArray(ctx.body) ? ctx.body : ctx.body?.data ? (Array.isArray(ctx.body.data) ? ctx.body.data : [ctx.body.data]) : [ctx.body];
159
- items.forEach((item) => {
160
- if (item && typeof item === 'object') {
161
- if (item.pat) item.pat = '••••••••';
162
- if (item.dataValues?.pat) item.dataValues.pat = '••••••••';
163
- }
164
- });
165
- }
166
- });
167
- }
168
-
169
- async install() {}
170
-
171
- async beforeDisable() {
172
- stopPoller();
173
- }
174
-
175
- async beforeUnload() {
176
- stopPoller();
177
- }
178
- }
179
-
180
- export default PluginGitManagerServer;
1
+ import { Plugin } from '@nocobase/server';
2
+ import { resolve } from 'path';
3
+ import { DataTypes } from 'sequelize';
4
+ import * as gitActions from './actions/git-actions';
5
+ import * as gitlabApi from './actions/gitlab-api';
6
+ import * as reviewActions from './actions/review';
7
+ import * as pollerActions from './actions/poller';
8
+ import { recoverStuckReviews } from './actions/review';
9
+ import { registerGitReviewAiTools } from './ai-tools';
10
+ import { startPoller, stopPoller } from './poller';
11
+
12
+ export class PluginGitManagerServer extends Plugin {
13
+ // @ts-ignore
14
+ declare app: any;
15
+ // @ts-ignore
16
+ declare db: any;
17
+ async beforeLoad() {
18
+ await (this as any).app.db.import({
19
+ directory: resolve(__dirname, 'collections'),
20
+ });
21
+
22
+ (this as any).app.db.addMigrations({
23
+ namespace: (this as any).name,
24
+ directory: resolve(__dirname, 'migrations'),
25
+ context: { plugin: this },
26
+ });
27
+ }
28
+
29
+ async load() {
30
+ // Ensure dayjs timezone + utc plugins are loaded globally to prevent 'm.startOf is not a function' errors
31
+ const dayjsLib = require('dayjs');
32
+ const utcPlugin = require('dayjs/plugin/utc');
33
+ const timezonePlugin = require('dayjs/plugin/timezone');
34
+ dayjsLib.extend(utcPlugin);
35
+ dayjsLib.extend(timezonePlugin);
36
+
37
+ (this as any).app.resourceManager.define({
38
+ name: 'gitManager',
39
+ actions: {
40
+ clone: gitActions.clone,
41
+ pull: gitActions.pull,
42
+ push: gitActions.push,
43
+ fetch: gitActions.fetch,
44
+ diff: gitActions.diff,
45
+ status: gitActions.status,
46
+ log: gitActions.log,
47
+ branches: gitActions.branches,
48
+ checkout: gitActions.checkout,
49
+ fileTree: gitActions.fileTree,
50
+ fileContent: gitActions.fileContent,
51
+ commitDetail: gitActions.commitDetail,
52
+ mergeRequests: gitlabApi.mergeRequests,
53
+ mergeRequestDetail: gitlabApi.mergeRequestDetail,
54
+ mergeRequestNotes: gitlabApi.mergeRequestNotes,
55
+ triggerReview: reviewActions.triggerReview,
56
+ reviewApprovePost: reviewActions.reviewApprovePost,
57
+ reviewReject: reviewActions.reviewReject,
58
+ pollNow: pollerActions.pollNow,
59
+ pollerStatus: pollerActions.pollerStatus,
60
+ },
61
+ });
62
+
63
+ // Suppress noisy workflow pre-action/post-action warnings for custom resources
64
+ (this as any).app.use(async (ctx, next) => {
65
+ if (ctx.logger && ctx.logger.warn) {
66
+ const originalWarn = ctx.logger.warn.bind(ctx.logger);
67
+ ctx.logger.warn = (message: any, ...args: any[]) => {
68
+ if (
69
+ typeof message === 'string' &&
70
+ message.includes('[Workflow') &&
71
+ message.includes('collection') &&
72
+ message.includes('not found')
73
+ ) {
74
+ return ctx.logger;
75
+ }
76
+ return originalWarn(message, ...args);
77
+ };
78
+ }
79
+ return next();
80
+ });
81
+
82
+ registerGitReviewAiTools((this as any).app);
83
+
84
+ (this as any).app.on('afterStart', async () => {
85
+ await ensureAutoReviewFlowSchema((this as any).app).catch(
86
+ (err) => (this as any).app.log?.error?.('plugin-git-manager: ensure schema error', err),
87
+ );
88
+ // Sweep any review left in `running` state from a previous process.
89
+ recoverStuckReviews((this as any).app).catch(
90
+ (err) => (this as any).app.log?.error?.('plugin-git-manager: recoverStuckReviews error', err),
91
+ );
92
+ startPoller((this as any).app);
93
+ });
94
+ (this as any).app.on('beforeStop', () => {
95
+ stopPoller();
96
+ });
97
+ (this as any).app.on('beforeDestroy', () => {
98
+ stopPoller();
99
+ });
100
+
101
+ // Read-only operations available to all plugin users
102
+ (this as any).app.acl.registerSnippet({
103
+ name: `pm.${(this as any).name}.read`,
104
+ actions: [
105
+ 'gitRepositories:list',
106
+ 'gitRepositories:get',
107
+ 'gitReviewFlows:list',
108
+ 'gitReviewFlows:get',
109
+ 'gitCodeReviews:list',
110
+ 'gitCodeReviews:get',
111
+ 'gitManager:status',
112
+ 'gitManager:log',
113
+ 'gitManager:branches',
114
+ 'gitManager:diff',
115
+ 'gitManager:fileTree',
116
+ 'gitManager:fileContent',
117
+ 'gitManager:commitDetail',
118
+ 'gitManager:mergeRequests',
119
+ 'gitManager:mergeRequestDetail',
120
+ 'gitManager:mergeRequestNotes',
121
+ 'gitManager:pollerStatus',
122
+ ],
123
+ });
124
+
125
+ // Write operations require separate permission
126
+ (this as any).app.acl.registerSnippet({
127
+ name: `pm.${(this as any).name}.write`,
128
+ actions: [
129
+ 'gitRepositories:create',
130
+ 'gitRepositories:update',
131
+ 'gitRepositories:destroy',
132
+ 'gitReviewFlows:create',
133
+ 'gitReviewFlows:update',
134
+ 'gitReviewFlows:destroy',
135
+ 'gitCodeReviews:create',
136
+ 'gitCodeReviews:update',
137
+ 'gitCodeReviews:destroy',
138
+ 'gitManager:clone',
139
+ 'gitManager:pull',
140
+ 'gitManager:push',
141
+ 'gitManager:fetch',
142
+ 'gitManager:checkout',
143
+ 'gitManager:triggerReview',
144
+ 'gitManager:reviewApprovePost',
145
+ 'gitManager:reviewReject',
146
+ 'gitManager:pollNow',
147
+ ],
148
+ });
149
+
150
+ // Prevent overwriting PAT with obfuscated value on updates
151
+ (this as any).app.resourceManager.use(async (ctx, next) => {
152
+ if (ctx.action?.resourceName === 'gitRepositories' && ['create', 'update'].includes(ctx.action?.actionName)) {
153
+ if (ctx.action.params?.values?.pat === '••••••••') {
154
+ delete ctx.action.params.values.pat;
155
+ }
156
+ if (ctx.request.body?.pat === '••••••••') {
157
+ delete ctx.request.body.pat;
158
+ }
159
+ }
160
+ return next();
161
+ });
162
+
163
+ // Strip PAT from API responses — scoped to gitRepositories only
164
+ (this as any).app.resourceManager.use(async (ctx, next) => {
165
+ if (ctx.action?.resourceName !== 'gitRepositories') {
166
+ return next();
167
+ }
168
+ await next();
169
+ if (ctx.body) {
170
+ const items = Array.isArray(ctx.body)
171
+ ? ctx.body
172
+ : ctx.body?.data
173
+ ? Array.isArray(ctx.body.data)
174
+ ? ctx.body.data
175
+ : [ctx.body.data]
176
+ : [ctx.body];
177
+ items.forEach((item) => {
178
+ if (item && typeof item === 'object') {
179
+ if (item.pat) item.pat = '••••••••';
180
+ if (item.dataValues?.pat) item.dataValues.pat = '••••••••';
181
+ }
182
+ });
183
+ }
184
+ });
185
+ }
186
+
187
+ async install() {
188
+ await (this as any).app.db.getCollection('gitRepositories')?.sync();
189
+ }
190
+
191
+ async beforeDisable() {
192
+ stopPoller();
193
+ }
194
+
195
+ async beforeUnload() {
196
+ stopPoller();
197
+ }
198
+ }
199
+
200
+ export async function ensureAutoReviewFlowSchema(app: any) {
201
+ const sequelize = app.db?.sequelize;
202
+ const queryInterface = sequelize?.getQueryInterface?.();
203
+ if (!queryInterface) return;
204
+
205
+ const tablePrefix = app.db.options?.tablePrefix || '';
206
+ const tableName = `${tablePrefix}gitRepositories`;
207
+ const tableInfo = await queryInterface.describeTable(tableName).catch(() => null);
208
+ if (!tableInfo || tableInfo.autoReviewFlowId) return;
209
+
210
+ await queryInterface.addColumn(tableName, 'autoReviewFlowId', {
211
+ type: DataTypes.INTEGER,
212
+ allowNull: true,
213
+ });
214
+ }
215
+
216
+ export default PluginGitManagerServer;
@@ -218,6 +218,11 @@ export async function pollOneRepo(
218
218
  });
219
219
  if (!flows?.length) return { scanned: 0, triggered: 0 };
220
220
 
221
+ const primaryFlowId = repo.get('autoReviewFlowId') as number | null;
222
+ const primaryFlow = primaryFlowId
223
+ ? flows.find((flow: any) => Number(flow.get('id')) === Number(primaryFlowId))
224
+ : null;
225
+
221
226
  // Need PAT to query GitLab
222
227
  const pat = repo.get('pat') as string;
223
228
  if (!pat) return { scanned: 0, triggered: 0 };
@@ -227,8 +232,12 @@ export async function pollOneRepo(
227
232
 
228
233
  let triggered = 0;
229
234
  for (const mr of mrs) {
230
- // Pick first flow whose branchFilter matches this MR's source branch
231
- const flow = flows.find((f: any) => branchMatches(f, mr.source_branch));
235
+ // Prefer the repository's configured primary auto-review flow, then fall
236
+ // back to the first matching auto-trigger flow.
237
+ const flow =
238
+ primaryFlow && branchMatches(primaryFlow, mr.source_branch)
239
+ ? primaryFlow
240
+ : flows.find((f: any) => branchMatches(f, mr.source_branch));
232
241
  if (!flow) continue;
233
242
 
234
243
  // Auto-poll only triggers for MRs that have NEVER been reviewed.