nitor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.json +10 -0
- package/.editorconfig +16 -0
- package/.eslintrc.js +29 -0
- package/.gitattributes +2 -0
- package/.prettierrc +5 -0
- package/.releaserc.json +34 -0
- package/CHANGELOG.md +72 -0
- package/README.md +125 -0
- package/favicon.png +0 -0
- package/index.js +15 -0
- package/package.json +80 -0
- package/services/build.js +55 -0
- package/services/create-branch.js +29 -0
- package/services/deploy.js +21 -0
- package/services/enums/actions.enum.js +14 -0
- package/services/merge.js +34 -0
- package/services/mongodb-backup.js +169 -0
- package/services/process-commands.js +280 -0
- package/services/refactor.js +37 -0
- package/services/review.js +50 -0
- package/services/utils.js +352 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const { backupConfig, restoreConfig } = require('./utils');
|
|
4
|
+
|
|
5
|
+
// ANSI color codes
|
|
6
|
+
const colors = {
|
|
7
|
+
red: '\x1b[31m',
|
|
8
|
+
green: '\x1b[32m',
|
|
9
|
+
reset: '\x1b[0m',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Execute MongoDB restore from local backup to Docker container
|
|
14
|
+
* @param {Object} config - Restore configuration
|
|
15
|
+
* @param {string} config.containerName - Name of the Docker container (default: 'mongodb')
|
|
16
|
+
* @param {string} config.localBackupPath - Local path where backup is stored (default: '~/backups/mongo')
|
|
17
|
+
* @param {string} config.containerBackupPath - Path inside container for backup (default: '/data/backup')
|
|
18
|
+
*/
|
|
19
|
+
const executeMongoRestore = async (config) => {
|
|
20
|
+
const {
|
|
21
|
+
containerName = 'mongodb',
|
|
22
|
+
localBackupPath = os.homedir() + '/backups/mongo',
|
|
23
|
+
containerBackupPath = '/data/backup',
|
|
24
|
+
} = config;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const expandedLocalPath = localBackupPath.replace('~', os.homedir());
|
|
28
|
+
|
|
29
|
+
console.log(`\nStarting MongoDB restore to container: ${containerName}`);
|
|
30
|
+
|
|
31
|
+
// Step 1: Copy backup from local to Docker container
|
|
32
|
+
const copyCommand = `docker cp ${expandedLocalPath} ${containerName}:${containerBackupPath}`;
|
|
33
|
+
|
|
34
|
+
console.log(`Copying backup to container...`);
|
|
35
|
+
execSync(copyCommand, { stdio: 'inherit' });
|
|
36
|
+
console.log(`${colors.green}✓ Backup copied to container${colors.reset}`);
|
|
37
|
+
|
|
38
|
+
// Step 2: Execute mongorestore inside the container
|
|
39
|
+
const restoreCommand = `docker exec -it ${containerName} mongorestore ${containerBackupPath}`;
|
|
40
|
+
|
|
41
|
+
console.log('Executing mongorestore...');
|
|
42
|
+
execSync(restoreCommand, { stdio: 'inherit' });
|
|
43
|
+
console.log(`${colors.green}✓ Mongorestore completed successfully${colors.reset}`);
|
|
44
|
+
|
|
45
|
+
// Step 3: Remove backup data from container
|
|
46
|
+
const cleanupCommand = `docker exec -it ${containerName} rm -rf ${containerBackupPath}`;
|
|
47
|
+
|
|
48
|
+
console.log('Cleaning up backup data from container...');
|
|
49
|
+
execSync(cleanupCommand, { stdio: 'inherit' });
|
|
50
|
+
console.log(`${colors.green}✓ Backup data removed from container${colors.reset}`);
|
|
51
|
+
|
|
52
|
+
console.log(`${colors.green}Restore completed successfully!${colors.reset}\n`);
|
|
53
|
+
|
|
54
|
+
return { success: true };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(`${colors.red}Error during MongoDB restore: ${error.message}${colors.reset}`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Execute MongoDB backup using kubectl
|
|
63
|
+
* @param {Object} config - Backup configuration
|
|
64
|
+
* @param {string} config.pod - Name of the pod
|
|
65
|
+
* @param {string} config.username - MongoDB username
|
|
66
|
+
* @param {string} config.password - MongoDB password
|
|
67
|
+
* @param {string} config.database - Database name (used for authentication and backup)
|
|
68
|
+
* @param {string} config.backupPath - Path inside pod for backup (default: '/data/backup')
|
|
69
|
+
* @param {string} config.localBackupPath - Local path to copy backup (default: '~/backups/mongo/')
|
|
70
|
+
*/
|
|
71
|
+
const executeMongoBackup = async (config) => {
|
|
72
|
+
const {
|
|
73
|
+
pod,
|
|
74
|
+
username,
|
|
75
|
+
password,
|
|
76
|
+
database,
|
|
77
|
+
backupPath = '/data/backup',
|
|
78
|
+
localBackupPath = '~/backups/mongo/',
|
|
79
|
+
} = config;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
console.log(`\nStarting MongoDB backup for pod: ${pod}, database: ${database}`);
|
|
83
|
+
|
|
84
|
+
const mongodumpCommand = `kubectl exec -it ${pod} -- mongodump --username ${username} --password ${password} --authenticationDatabase ${database} --db ${database} --out ${backupPath}`;
|
|
85
|
+
|
|
86
|
+
console.log('Executing mongodump...');
|
|
87
|
+
execSync(mongodumpCommand, { stdio: 'inherit' });
|
|
88
|
+
console.log(`${colors.green}✓ Mongodump completed successfully${colors.reset}`);
|
|
89
|
+
|
|
90
|
+
const expandedLocalPath = localBackupPath.replace('~', os.homedir());
|
|
91
|
+
const destinationPath = `${expandedLocalPath}${database}`;
|
|
92
|
+
const copyCommand = `kubectl cp ${pod}:${backupPath}/${database} ${destinationPath}`;
|
|
93
|
+
const cleanupCommand = `kubectl exec -it ${pod} -- rm -rf ${backupPath}`;
|
|
94
|
+
|
|
95
|
+
console.log(`Copying backup to ${destinationPath}...`);
|
|
96
|
+
execSync(copyCommand, { stdio: 'inherit' });
|
|
97
|
+
console.log(`${colors.green}✓ Backup copied successfully${colors.reset}`);
|
|
98
|
+
|
|
99
|
+
console.log('Cleaning up backup data from pod...');
|
|
100
|
+
execSync(cleanupCommand, { stdio: 'inherit' });
|
|
101
|
+
console.log(`${colors.green}✓ Backup data removed from pod${colors.reset}`);
|
|
102
|
+
|
|
103
|
+
console.log(
|
|
104
|
+
`${colors.green}Backup completed! Files saved to: ${destinationPath}${colors.reset}\n`,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return { success: true, localPath: destinationPath };
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`${colors.red}Error during MongoDB backup: ${error.message}${colors.reset}`);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const backup = async (values) => {
|
|
115
|
+
if (!backupConfig) {
|
|
116
|
+
console.error(`${colors.red}BACKUP_CONFIG not found in environment variables${colors.reset}`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let projects;
|
|
121
|
+
|
|
122
|
+
if (values.project) {
|
|
123
|
+
projects = values.project.split(' ');
|
|
124
|
+
} else {
|
|
125
|
+
projects = Object.keys(backupConfig);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
console.log(`Starting backup process for projects: ${projects.join(', ')}`);
|
|
129
|
+
|
|
130
|
+
for (const project of projects) {
|
|
131
|
+
const projectConfigs = backupConfig[project];
|
|
132
|
+
|
|
133
|
+
if (!projectConfigs || !Array.isArray(projectConfigs)) {
|
|
134
|
+
console.warn(`No configuration found for project: ${project}`);
|
|
135
|
+
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.log(`\n========================================`);
|
|
140
|
+
console.log(`Processing backup for project: ${project}`);
|
|
141
|
+
console.log(`========================================`);
|
|
142
|
+
|
|
143
|
+
for (const dbConfig of projectConfigs) {
|
|
144
|
+
try {
|
|
145
|
+
await executeMongoBackup(dbConfig);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(
|
|
148
|
+
`${colors.red}Failed to backup database ${dbConfig.database} for project ${project}${colors.reset}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
console.log('\n========================================');
|
|
155
|
+
console.log(`${colors.green}Backup process completed!${colors.reset}`);
|
|
156
|
+
console.log('========================================');
|
|
157
|
+
|
|
158
|
+
console.log(`\n========================================`);
|
|
159
|
+
console.log(`Starting restore process for projects: ${projects.join(', ')}`);
|
|
160
|
+
console.log(`========================================`);
|
|
161
|
+
|
|
162
|
+
await executeMongoRestore(restoreConfig);
|
|
163
|
+
|
|
164
|
+
console.log('\n========================================');
|
|
165
|
+
console.log(`${colors.green}Restore process completed!${colors.reset}`);
|
|
166
|
+
console.log('========================================');
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
module.exports = { backup };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// const { checkConfig } = require('./init-config');
|
|
2
|
+
const { build, buildStatus } = require('./build');
|
|
3
|
+
const { deploy } = require('./deploy');
|
|
4
|
+
const { ACTIONS } = require('./enums/actions.enum');
|
|
5
|
+
const { convertParamsToMap, wait } = require('./utils');
|
|
6
|
+
const { createBranch } = require('./create-branch');
|
|
7
|
+
const { mrAIReview } = require('./review');
|
|
8
|
+
const { refactor } = require('./refactor');
|
|
9
|
+
const { backup } = require('./mongodb-backup');
|
|
10
|
+
const { merge } = require('./merge');
|
|
11
|
+
|
|
12
|
+
const processArgs = async (type, value) => {
|
|
13
|
+
try {
|
|
14
|
+
let values;
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
type !== ACTIONS.HELP &&
|
|
18
|
+
type !== ACTIONS.VERSION &&
|
|
19
|
+
!value.includes('--h') &&
|
|
20
|
+
!value.includes('-help')
|
|
21
|
+
) {
|
|
22
|
+
values = await convertParamsToMap(value, type);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (type === ACTIONS.REFACTOR) {
|
|
26
|
+
values = value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (values === null) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
switch (type) {
|
|
34
|
+
case ACTIONS.BUILD: {
|
|
35
|
+
if (value === '-help' || value === '--h') {
|
|
36
|
+
console.log(`usage: \tnu build [-project <project name>] [-components <component name>] [-instance <instance name>]
|
|
37
|
+
\tnu build [-p <project name>] [-c <component name>] [-i <instance name>]
|
|
38
|
+
|
|
39
|
+
Build specified components
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
-p, --project <name> project name | portal, gateway, phr, configService, healthRecords, centralAuth, mpi, phrAdminBackend, phrAdminClient, terminologyService
|
|
43
|
+
-c, --components <name> component name | client, administration, provider, rest-api
|
|
44
|
+
-i, --instance <name> instance name | dev, qa, pilot`);
|
|
45
|
+
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await build(values);
|
|
50
|
+
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
case ACTIONS.BUILD_DEPLOY: {
|
|
55
|
+
if (value === '-help' || value === '--h') {
|
|
56
|
+
console.log(`usage: \tnu build-deploy [-project <project name>] [-components <component name>] [-instance <instance name>]
|
|
57
|
+
\tnu build-deploy [-p <project name>] [-c <component name>] [-i <instance name>]
|
|
58
|
+
|
|
59
|
+
Build and deploy specified components
|
|
60
|
+
|
|
61
|
+
Options:
|
|
62
|
+
-p, --project <name> project name | portal, gateway, phr, configService, healthRecords, centralAuth, mpi, phrAdminBackend, phrAdminClient, terminologyService
|
|
63
|
+
-c, --components <name> component name | client, administration, provider, rest-api
|
|
64
|
+
-i, --instance <name> instance name | dev, qa, pilot`);
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const configs = await build(values);
|
|
70
|
+
|
|
71
|
+
console.log('Build in progress...');
|
|
72
|
+
|
|
73
|
+
await wait(240000);
|
|
74
|
+
await buildStatus(values, configs);
|
|
75
|
+
|
|
76
|
+
if (Object.values(configs).every(({ status }) => status === 'passed')) {
|
|
77
|
+
console.log('Deploy in progress...');
|
|
78
|
+
|
|
79
|
+
await deploy(values);
|
|
80
|
+
} else {
|
|
81
|
+
console.log('Build failed. Deploy skipped.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
case ACTIONS.DEPLOY: {
|
|
88
|
+
if (value === '-help' || value === '--h') {
|
|
89
|
+
console.log(`usage: \tnu deploy [-project <project name>] [-components <component name>] [-instance <instance name>]
|
|
90
|
+
\tnu deploy [-p <project name>] [-c <component name>] [-i <instance name>]
|
|
91
|
+
|
|
92
|
+
Deploy specified components
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
-p, --project <name> project name | portal, gateway, phr, configService, healthRecords, centralAuth, mpi, phrAdminBackend, phrAdminClient, terminologyService
|
|
96
|
+
-c, --components <name> component name | client, administration, provider, rest-api
|
|
97
|
+
-i, --instance <name> instance name | dev, qa, pilot`);
|
|
98
|
+
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await deploy(values);
|
|
103
|
+
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
case ACTIONS.CREATE_BRANCH: {
|
|
108
|
+
if (value === '-help' || value === '--h') {
|
|
109
|
+
console.log(`usage: \tnu create-branch [-task <task number>] [-type <feat|fix>] [-description <description>] [-project <project short name>]
|
|
110
|
+
\tnu create-branch [-t <task number>] [-ty <feat|fix>] [-d <description>] [-p <project short name>]
|
|
111
|
+
|
|
112
|
+
Create git branch
|
|
113
|
+
|
|
114
|
+
Options:
|
|
115
|
+
-t, --task <number> task number
|
|
116
|
+
-ty, --type <type> type | feat, fix
|
|
117
|
+
-d, --description <description> description
|
|
118
|
+
-p, --project <project short name> project short name | portal, gateway, phr, configService, healthRecords, centralAuth, mpi, phrAdminBackend, phrAdminClient, terminologyService`);
|
|
119
|
+
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await createBranch(values);
|
|
124
|
+
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case ACTIONS.REVIEW: {
|
|
129
|
+
if (value === '-help' || value === '--h') {
|
|
130
|
+
console.log(`usage: \tnu review [-project <project short name>] [-mergeId <merge id>]
|
|
131
|
+
\tnu review [-p <project short name>] [-mId <merge id>]
|
|
132
|
+
|
|
133
|
+
Review merge request
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
-p, --project <project short name> project short name | portal, gateway, phr, configService, healthRecords, centralAuth, mpi, phrAdminBackend, phrAdminClient, terminologyService
|
|
137
|
+
-mId, --mergeId <merge id> merge id
|
|
138
|
+
-r, --repository <repository name> repository name
|
|
139
|
+
|
|
140
|
+
Repository list:
|
|
141
|
+
portalClient
|
|
142
|
+
portalBackend
|
|
143
|
+
portalDeployment
|
|
144
|
+
portalAutomation
|
|
145
|
+
gatewayBackend
|
|
146
|
+
gatewayClient
|
|
147
|
+
gatewayDeployment
|
|
148
|
+
phrClient
|
|
149
|
+
phrBackend
|
|
150
|
+
phrDeployment
|
|
151
|
+
configService
|
|
152
|
+
healthRecords
|
|
153
|
+
centralAuth
|
|
154
|
+
mpi
|
|
155
|
+
phrAdminBackend
|
|
156
|
+
phrAdminClient
|
|
157
|
+
terminologyService`);
|
|
158
|
+
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await mrAIReview(values);
|
|
163
|
+
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case ACTIONS.REFACTOR: {
|
|
168
|
+
if (value === '-help' || value === '--h') {
|
|
169
|
+
console.log(`Usage: \tnu refactor <text>
|
|
170
|
+
|
|
171
|
+
Enhance the provided text for improved clarity, conciseness, and professional quality.`);
|
|
172
|
+
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
await refactor(values);
|
|
177
|
+
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case ACTIONS.BACKUP: {
|
|
182
|
+
if (value === '-help' || value === '--h') {
|
|
183
|
+
console.log(`Usage: \tnu backup [-project <project name>] [-components <component name>]
|
|
184
|
+
|
|
185
|
+
Backup mongodb for specified project and components.
|
|
186
|
+
|
|
187
|
+
project list:
|
|
188
|
+
- configCervice
|
|
189
|
+
- medicaCentralAuth
|
|
190
|
+
- medicaPortal
|
|
191
|
+
- phr`);
|
|
192
|
+
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
await backup(values);
|
|
197
|
+
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
case ACTIONS.MERGE: {
|
|
202
|
+
if (value === '-help' || value === '--h') {
|
|
203
|
+
console.log(`usage: \tnu merge [-source <source branch>] [-target <target branch>]
|
|
204
|
+
\tnu merge [-s <source branch>] [-ta <target branch>]
|
|
205
|
+
|
|
206
|
+
Merge source branch into target branch
|
|
207
|
+
|
|
208
|
+
Options:
|
|
209
|
+
-s, --source <branch> source branch name
|
|
210
|
+
-ta, --target <branch> target branch name
|
|
211
|
+
|
|
212
|
+
This command will:
|
|
213
|
+
1. Pull latest changes
|
|
214
|
+
2. Checkout source branch and pull
|
|
215
|
+
3. Checkout target branch and pull
|
|
216
|
+
4. Merge source into target
|
|
217
|
+
5. Push changes`);
|
|
218
|
+
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await merge(values);
|
|
223
|
+
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
case ACTIONS.VERSION: {
|
|
228
|
+
const path = require('path');
|
|
229
|
+
const packageJson = require(path.resolve(__dirname, '../package.json'));
|
|
230
|
+
const packageVersion = packageJson.version;
|
|
231
|
+
|
|
232
|
+
console.log('Package version:', packageVersion);
|
|
233
|
+
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
case ACTIONS.HELP: {
|
|
238
|
+
console.log(`usage: nu \t[${ACTIONS.VERSION}] [${ACTIONS.HELP}]
|
|
239
|
+
\t[${ACTIONS.BUILD}] [${ACTIONS.DEPLOY}] [${ACTIONS.BUILD_DEPLOY}]
|
|
240
|
+
\t[${ACTIONS.CREATE_BRANCH}] [${ACTIONS.REVIEW}] [${ACTIONS.MERGE}]\n
|
|
241
|
+
Available commands:\n
|
|
242
|
+
build : Build specified components
|
|
243
|
+
deploy : Deploy specified components
|
|
244
|
+
build-deploy : Build and then deploy
|
|
245
|
+
create-branch : Create git branch
|
|
246
|
+
review : AI Review specified merge request
|
|
247
|
+
refactor : REFACTOR the provided text for improved clarity, conciseness, and professional quality.
|
|
248
|
+
merge : Merge source branch into target branch
|
|
249
|
+
version : Show version info
|
|
250
|
+
help : Show help
|
|
251
|
+
|
|
252
|
+
For details of each actions run 'nu <action> -help'
|
|
253
|
+
|
|
254
|
+
Example usage:\n
|
|
255
|
+
nu build -project <project> -components <components> -instance <instance>
|
|
256
|
+
nu deploy -project <project> -components <components> -instance <instance>
|
|
257
|
+
nu build-deploy -project <project> -components <components> -instance <instance>
|
|
258
|
+
nu create-branch -task <task number> -type <feat|fix> -description <description> -project <project short name>
|
|
259
|
+
nu review -project <project short name> -mergeId <merge id> -repository <repository name>
|
|
260
|
+
nu refactor <text>
|
|
261
|
+
nu merge -source <source branch> -target <target branch>
|
|
262
|
+
|
|
263
|
+
Running 'nu help' will list available subcommands and provide some conceptual guides.`);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
default: {
|
|
268
|
+
console.error(`nu: '${type}' is not a nu command. See 'nu help'.`);
|
|
269
|
+
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.log(error);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
process.exit(1);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
module.exports = { processArgs };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { GoogleGenerativeAI } = require('@google/generative-ai');
|
|
2
|
+
const { openAIKey, openAIModel } = require('./utils.js');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
|
|
5
|
+
const refactorText = async function (text) {
|
|
6
|
+
try {
|
|
7
|
+
const genAI = new GoogleGenerativeAI(openAIKey);
|
|
8
|
+
const model = genAI.getGenerativeModel({ model: openAIModel });
|
|
9
|
+
const prompt = `
|
|
10
|
+
Refactor this text into a professional version.
|
|
11
|
+
Provide exactly 3 different suggestions.
|
|
12
|
+
Format the output as follows:
|
|
13
|
+
1. [First suggestion]
|
|
14
|
+
2. [Second suggestion]
|
|
15
|
+
3. [Third suggestion]
|
|
16
|
+
|
|
17
|
+
Make each suggestion clear, concise, and professional.
|
|
18
|
+
Keep the core meaning but vary the tone and structure.
|
|
19
|
+
|
|
20
|
+
Text: "${text}"
|
|
21
|
+
`;
|
|
22
|
+
const result = await model.generateContent(prompt);
|
|
23
|
+
|
|
24
|
+
return result.response.text();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.log('Error during text refactoring:', error);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const refactor = async (text) => {
|
|
31
|
+
console.log(chalk.blue('🔄 Refactoring text...\n'));
|
|
32
|
+
const suggestions = await refactorText(text);
|
|
33
|
+
console.log(chalk.green('✅ Professional Suggestions:\n'));
|
|
34
|
+
console.log(chalk.white(suggestions));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = { refactor };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { gitlabToken, projectIdMap, mrPrompt, mrLang, mrApiUri } = require('./utils');
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
|
|
4
|
+
const executeMergeRequestReview = async (values) => {
|
|
5
|
+
const config = {
|
|
6
|
+
method: 'post',
|
|
7
|
+
maxBodyLength: Infinity,
|
|
8
|
+
url: `${mrApiUri}/${projectIdMap[values.project]}/mergeid/${values.mergeId}`,
|
|
9
|
+
headers: { 'Content-Type': 'application/json' },
|
|
10
|
+
data: JSON.stringify({
|
|
11
|
+
language: mrLang,
|
|
12
|
+
gitlabToken,
|
|
13
|
+
llmModel: 'claude',
|
|
14
|
+
prompt: mrPrompt,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return await axios
|
|
19
|
+
.request(config)
|
|
20
|
+
.then((response) => response.data)
|
|
21
|
+
.catch((error) => {
|
|
22
|
+
console.log(error);
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const mrAIReview = async (values) => {
|
|
29
|
+
if (!projectIdMap[values.project]) {
|
|
30
|
+
console.log('Invalid project name');
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
console.log('Executing merge request review...');
|
|
37
|
+
|
|
38
|
+
const result = await executeMergeRequestReview(values);
|
|
39
|
+
|
|
40
|
+
if (result) {
|
|
41
|
+
console.log('Merge request review completed successfully');
|
|
42
|
+
} else {
|
|
43
|
+
console.log('Merge request review failed');
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Error port forwarding:', error.message);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
module.exports = { mrAIReview };
|