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,352 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
const { ACTIONS } = require('./enums/actions.enum');
|
|
4
|
+
|
|
5
|
+
require('dotenv').config({ path: path.resolve(require('os').homedir(), 'Desktop/.env.nu') });
|
|
6
|
+
|
|
7
|
+
const csrfToken = process.env.CSRF_TOKEN;
|
|
8
|
+
const Cookie = process.env.COOKIE;
|
|
9
|
+
const Origin = process.env.ORIGIN;
|
|
10
|
+
const gitlabToken = process.env.GITLAB_TOKEN;
|
|
11
|
+
const mrPrompt = process.env.MR_PROMPT;
|
|
12
|
+
const mrLang = process.env.MR_LANG;
|
|
13
|
+
const mrApiUri = process.env.MR_API_URI;
|
|
14
|
+
const openAIKey = process.env.AI_API_KEY;
|
|
15
|
+
const openAIModel = process.env.AI_MODEL;
|
|
16
|
+
const backupConfig = process.env.BACKUP_CONFIG && JSON.parse(process.env.BACKUP_CONFIG);
|
|
17
|
+
const restoreConfig = process.env.RESTORE_CONFIG && JSON.parse(process.env.RESTORE_CONFIG);
|
|
18
|
+
const keyMap = {
|
|
19
|
+
components: 'components',
|
|
20
|
+
c: 'components',
|
|
21
|
+
project: 'project',
|
|
22
|
+
p: 'project',
|
|
23
|
+
instance: 'instance',
|
|
24
|
+
i: 'instance',
|
|
25
|
+
branch: 'branch',
|
|
26
|
+
b: 'branch',
|
|
27
|
+
repository: 'repository',
|
|
28
|
+
r: 'repository',
|
|
29
|
+
task: 'task',
|
|
30
|
+
t: 'task',
|
|
31
|
+
type: 'type',
|
|
32
|
+
ty: 'type',
|
|
33
|
+
description: 'description',
|
|
34
|
+
d: 'description',
|
|
35
|
+
mergeId: 'mergeId',
|
|
36
|
+
mId: 'mergeId',
|
|
37
|
+
help: 'help',
|
|
38
|
+
h: 'help',
|
|
39
|
+
source: 'source',
|
|
40
|
+
so: 'source',
|
|
41
|
+
target: 'target',
|
|
42
|
+
ta: 'target',
|
|
43
|
+
};
|
|
44
|
+
const projectMap = {
|
|
45
|
+
portal: 'medica-portal',
|
|
46
|
+
gateway: 'gateway-app',
|
|
47
|
+
phr: 'phr',
|
|
48
|
+
configService: 'config-service',
|
|
49
|
+
healthRecords: 'health-records',
|
|
50
|
+
centralAuth: 'central-auth',
|
|
51
|
+
mpi: 'mpi',
|
|
52
|
+
phrAdminBackend: 'phr-admin-backend',
|
|
53
|
+
phrAdminClient: 'phr-admin-client',
|
|
54
|
+
terminologyService: 'terminology-service',
|
|
55
|
+
};
|
|
56
|
+
const buildBranchMap = {
|
|
57
|
+
dev: 'dev-qa-testing',
|
|
58
|
+
qa: 'qa-testing',
|
|
59
|
+
pilot: 'pilot-release',
|
|
60
|
+
};
|
|
61
|
+
const deploymentBranchMap = {
|
|
62
|
+
dev: 'dev-qa-testing',
|
|
63
|
+
qa: 'qa-testing',
|
|
64
|
+
pilot: 'development',
|
|
65
|
+
};
|
|
66
|
+
const imageTagMap = {
|
|
67
|
+
qa: 'qa',
|
|
68
|
+
pilot: 'demo',
|
|
69
|
+
};
|
|
70
|
+
const projectIdMap = {
|
|
71
|
+
portalClient: '162',
|
|
72
|
+
portalBackend: '163',
|
|
73
|
+
portalDeployment: '164',
|
|
74
|
+
portalAutomation: '229',
|
|
75
|
+
gatewayBackend: '305',
|
|
76
|
+
gatewayClient: '306',
|
|
77
|
+
gatewayDeployment: '304',
|
|
78
|
+
phrClient: '100',
|
|
79
|
+
phrBackend: '117',
|
|
80
|
+
phrDeployment: '64',
|
|
81
|
+
configService: '227',
|
|
82
|
+
healthRecords: '115',
|
|
83
|
+
centralAuth: '134',
|
|
84
|
+
mpi: '10',
|
|
85
|
+
phrAdminBackend: '126',
|
|
86
|
+
phrAdminClient: '130',
|
|
87
|
+
terminologyService: '203',
|
|
88
|
+
};
|
|
89
|
+
const backendComps = ['administration', 'provider', 'rest-api', 'ctn'];
|
|
90
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
91
|
+
const buildHeaders = (url) => ({
|
|
92
|
+
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
|
|
93
|
+
Accept: 'application/json, text/plain, */*',
|
|
94
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
95
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
96
|
+
Referer: `${url}/new`,
|
|
97
|
+
'X-CSRF-Token': csrfToken,
|
|
98
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
Origin,
|
|
101
|
+
Connection: 'keep-alive',
|
|
102
|
+
Cookie,
|
|
103
|
+
'Sec-Fetch-Dest': 'empty',
|
|
104
|
+
'Sec-Fetch-Mode': 'cors',
|
|
105
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
106
|
+
TE: 'trailers',
|
|
107
|
+
});
|
|
108
|
+
const makeConfig = (url, data, method = 'post') => ({
|
|
109
|
+
method,
|
|
110
|
+
maxBodyLength: Infinity,
|
|
111
|
+
url,
|
|
112
|
+
data: JSON.stringify(data),
|
|
113
|
+
headers: buildHeaders(url),
|
|
114
|
+
});
|
|
115
|
+
const removeEmpty = (obj) => {
|
|
116
|
+
Object.entries(obj).forEach(([key, val]) => {
|
|
117
|
+
if (val && typeof val === 'object') {
|
|
118
|
+
removeEmpty(val);
|
|
119
|
+
|
|
120
|
+
if (!(Object.keys(val).length || val instanceof Date)) {
|
|
121
|
+
delete obj[key];
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
if (typeof val === 'string') {
|
|
125
|
+
val = val.trim();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (val === null || val === undefined || val === '') {
|
|
129
|
+
delete obj[key];
|
|
130
|
+
} else {
|
|
131
|
+
obj[key] = val;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return obj;
|
|
137
|
+
};
|
|
138
|
+
const generateBuildConfigs = (values = {}) => {
|
|
139
|
+
const configs = {
|
|
140
|
+
client: {
|
|
141
|
+
config: null,
|
|
142
|
+
buildId: null,
|
|
143
|
+
},
|
|
144
|
+
backend: {
|
|
145
|
+
config: null,
|
|
146
|
+
buildId: null,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
if (!values.components) {
|
|
151
|
+
console.log('Invalid build parameters');
|
|
152
|
+
|
|
153
|
+
return { configs: removeEmpty(configs, true) };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const variables_attributes = [];
|
|
157
|
+
|
|
158
|
+
if (values.instance) {
|
|
159
|
+
variables_attributes.push({
|
|
160
|
+
variable_type: 'env_var',
|
|
161
|
+
key: 'TAG',
|
|
162
|
+
secret_value: values.instance,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (!values.branch) {
|
|
166
|
+
values.branch = buildBranchMap[values.instance];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const baseRef = values.branch
|
|
171
|
+
? `refs/heads/${buildBranchMap[values.branch] || values.branch}`
|
|
172
|
+
: `refs/heads/${buildBranchMap.dev}`;
|
|
173
|
+
const dataBase = {
|
|
174
|
+
ref: baseRef,
|
|
175
|
+
variables_attributes,
|
|
176
|
+
};
|
|
177
|
+
const project = projectMap[values.project] || projectMap.portal;
|
|
178
|
+
|
|
179
|
+
// Client config
|
|
180
|
+
if (values.components.includes('client')) {
|
|
181
|
+
configs.client.config = makeConfig(`${Origin}/cxd/${project}-client/-/pipelines`, {
|
|
182
|
+
...dataBase,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Backend config (admin, provider, rest-api)
|
|
187
|
+
if (backendComps.some((c) => values.components.includes(c))) {
|
|
188
|
+
const apps = [];
|
|
189
|
+
if (values.components.includes('administration')) apps.push('administration');
|
|
190
|
+
if (values.components.includes('provider')) apps.push('provider');
|
|
191
|
+
|
|
192
|
+
const backendData = {
|
|
193
|
+
...dataBase,
|
|
194
|
+
variables_attributes: [
|
|
195
|
+
...dataBase.variables_attributes,
|
|
196
|
+
...(apps.length
|
|
197
|
+
? [
|
|
198
|
+
{
|
|
199
|
+
variable_type: 'env_var',
|
|
200
|
+
key: 'APPS',
|
|
201
|
+
secret_value: apps.join(' '),
|
|
202
|
+
},
|
|
203
|
+
]
|
|
204
|
+
: []),
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
configs.backend.config = makeConfig(
|
|
208
|
+
`${Origin}/cxd/${project}-backend/-/pipelines`,
|
|
209
|
+
backendData,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { configs: removeEmpty(configs, true) };
|
|
214
|
+
};
|
|
215
|
+
const generateBuildStatusConfigs = (values = {}, configs) => {
|
|
216
|
+
const project = projectMap[values.project] || projectMap.portal;
|
|
217
|
+
|
|
218
|
+
if (values.components.includes('client') && configs.client.buildId) {
|
|
219
|
+
configs.client.statusConfig = makeConfig(
|
|
220
|
+
`${Origin}/cxd/${project}-client/-/pipelines/${configs.client.buildId}`,
|
|
221
|
+
null,
|
|
222
|
+
'get',
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (backendComps.some((c) => values.components.includes(c)) && configs.backend.buildId) {
|
|
227
|
+
configs.backend.statusConfig = makeConfig(
|
|
228
|
+
`${Origin}/cxd/${project}-backend/-/pipelines/${configs.backend.buildId}`,
|
|
229
|
+
null,
|
|
230
|
+
'get',
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return removeEmpty(configs, true);
|
|
235
|
+
};
|
|
236
|
+
const generateDeployConfigs = (values = {}) => {
|
|
237
|
+
const variables_attributes = [];
|
|
238
|
+
|
|
239
|
+
if (!values.instance) {
|
|
240
|
+
values.instance = 'dev';
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
values.branch = buildBranchMap[values.instance] || buildBranchMap.dev;
|
|
244
|
+
|
|
245
|
+
if (values.instance === 'qa') {
|
|
246
|
+
variables_attributes.push({
|
|
247
|
+
variable_type: 'env_var',
|
|
248
|
+
key: 'IMAGE_TAG',
|
|
249
|
+
secret_value: values.instance,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (values.instance !== 'dev') {
|
|
254
|
+
variables_attributes.push({
|
|
255
|
+
variable_type: 'env_var',
|
|
256
|
+
key: 'INSTANCE',
|
|
257
|
+
secret_value: imageTagMap[values.instance] || values.instance,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (values.instance === 'pilot') {
|
|
262
|
+
variables_attributes.push({
|
|
263
|
+
variable_type: 'env_var',
|
|
264
|
+
key: 'COMPONENT',
|
|
265
|
+
secret_value: 'client-pilot',
|
|
266
|
+
});
|
|
267
|
+
} else {
|
|
268
|
+
variables_attributes.push({
|
|
269
|
+
variable_type: 'env_var',
|
|
270
|
+
key: 'COMPONENT',
|
|
271
|
+
secret_value: values.components || 'client',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const project = projectMap[values.project] || projectMap.portal;
|
|
276
|
+
const configs = makeConfig(`${Origin}/cxd/${project}-deployment/-/pipelines`, {
|
|
277
|
+
ref: `refs/heads/${deploymentBranchMap[values.instance]}`,
|
|
278
|
+
variables_attributes,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return { configs: removeEmpty(configs, true) };
|
|
282
|
+
};
|
|
283
|
+
const convertParamsToMap = async (item, type) => {
|
|
284
|
+
const itemsToSkipCheck = [
|
|
285
|
+
ACTIONS.CREATE_BRANCH,
|
|
286
|
+
ACTIONS.HELP,
|
|
287
|
+
ACTIONS.VERSION,
|
|
288
|
+
ACTIONS.REFACTOR,
|
|
289
|
+
ACTIONS.BACKUP,
|
|
290
|
+
ACTIONS.MERGE,
|
|
291
|
+
];
|
|
292
|
+
const skipCheck = itemsToSkipCheck.includes(type);
|
|
293
|
+
let live = false;
|
|
294
|
+
|
|
295
|
+
if (!skipCheck) {
|
|
296
|
+
if (!(csrfToken || Cookie || Origin || gitlabToken)) {
|
|
297
|
+
console.log('Configurations are missing...!');
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
console.log(`Checking website status...`);
|
|
302
|
+
|
|
303
|
+
await axios
|
|
304
|
+
.get(Origin)
|
|
305
|
+
.then(() => {
|
|
306
|
+
live = true;
|
|
307
|
+
|
|
308
|
+
console.log(`Website is live.`);
|
|
309
|
+
})
|
|
310
|
+
.catch((err) => {
|
|
311
|
+
console.log(`Website is not reachable:`, err.message);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
if (!live) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return item?.split(' -')?.reduce((acc, item) => {
|
|
320
|
+
if (!item) {
|
|
321
|
+
return acc;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
let [key, ...itemValues] = item.split(' ');
|
|
325
|
+
let itemValue = itemValues.join(' ').trim();
|
|
326
|
+
|
|
327
|
+
if (key.charAt(0) === '-') {
|
|
328
|
+
key = key.substring(1);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
acc[keyMap[key]] = itemValue;
|
|
332
|
+
|
|
333
|
+
return acc;
|
|
334
|
+
}, {});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
module.exports = {
|
|
338
|
+
convertParamsToMap,
|
|
339
|
+
generateBuildConfigs,
|
|
340
|
+
generateDeployConfigs,
|
|
341
|
+
generateBuildStatusConfigs,
|
|
342
|
+
wait,
|
|
343
|
+
gitlabToken,
|
|
344
|
+
projectIdMap,
|
|
345
|
+
mrPrompt,
|
|
346
|
+
mrLang,
|
|
347
|
+
mrApiUri,
|
|
348
|
+
openAIKey,
|
|
349
|
+
openAIModel,
|
|
350
|
+
backupConfig,
|
|
351
|
+
restoreConfig,
|
|
352
|
+
};
|