autoforce 0.1.18 → 0.1.20
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/.autoforce.json +1 -1
- package/CHANGELOG.md +10 -0
- package/lib/auto.js +47 -61
- package/lib/helpers/class.d.ts +1 -0
- package/lib/helpers/class.js +65 -78
- package/lib/helpers/connect.js +199 -213
- package/lib/helpers/context.d.ts +1 -1
- package/lib/helpers/context.js +275 -220
- package/lib/helpers/github-graphql.js +90 -113
- package/lib/helpers/github-project-graphql.js +100 -132
- package/lib/helpers/gitlab-graphql.js +68 -104
- package/lib/helpers/lwc.js +33 -46
- package/lib/helpers/object.js +38 -53
- package/lib/helpers/openai.js +10 -22
- package/lib/helpers/taskFunctions.js +328 -384
- package/lib/helpers/tasks.d.ts +1 -1
- package/lib/helpers/tasks.js +99 -119
- package/lib/helpers/template.js +4 -0
- package/lib/helpers/util.d.ts +2 -3
- package/lib/helpers/util.js +109 -162
- package/package.json +15 -10
@@ -1,12 +1,3 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
import { execSync } from "child_process";
|
11
2
|
import context, { ListFilters } from "./context.js";
|
12
3
|
import { logError, logInfo } from "./color.js";
|
@@ -22,7 +13,7 @@ function generateTemplate(templateFolder, templateExtension, template, context)
|
|
22
13
|
const formulas = {
|
23
14
|
today: Date.now(),
|
24
15
|
};
|
25
|
-
const view =
|
16
|
+
const view = { ...formulas, ...context };
|
26
17
|
templateEngine.read(template);
|
27
18
|
templateEngine.render(view);
|
28
19
|
return templateEngine.rendered;
|
@@ -36,7 +27,7 @@ function createTemplate(templateFolder, templateExtension, template, filename, f
|
|
36
27
|
today: Date.now(),
|
37
28
|
filename
|
38
29
|
};
|
39
|
-
const view =
|
30
|
+
const view = { ...formulas, ...context };
|
40
31
|
templateEngine.read(template);
|
41
32
|
templateEngine.render(view);
|
42
33
|
templateEngine.save(filename, folder);
|
@@ -60,17 +51,15 @@ function convertArgsToString(args) {
|
|
60
51
|
}
|
61
52
|
return argsString;
|
62
53
|
}
|
63
|
-
export function executeCommand(step) {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
73
|
-
});
|
54
|
+
export async function executeCommand(step) {
|
55
|
+
try {
|
56
|
+
context.set('command', step.command + ' ' + convertArgsToString(step.arguments));
|
57
|
+
execSync(step.command + ' ' + convertArgsToString(step.arguments), { stdio: 'inherit' });
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
catch {
|
61
|
+
return false;
|
62
|
+
}
|
74
63
|
}
|
75
64
|
export function validateCommand(step) {
|
76
65
|
if (step.command && typeof step.command == 'string') {
|
@@ -121,32 +110,28 @@ function createArray(fields, record) {
|
|
121
110
|
}
|
122
111
|
return fieldArray;
|
123
112
|
}
|
124
|
-
function askForContinue(message) {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
return answer.continue;
|
135
|
-
});
|
113
|
+
async function askForContinue(message) {
|
114
|
+
const answer = await prompts([
|
115
|
+
{
|
116
|
+
type: "confirm",
|
117
|
+
name: "continue",
|
118
|
+
initial: true,
|
119
|
+
message
|
120
|
+
}
|
121
|
+
]);
|
122
|
+
return answer.continue;
|
136
123
|
}
|
137
|
-
function askForCommitMessage() {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
return answer.message;
|
149
|
-
});
|
124
|
+
async function askForCommitMessage() {
|
125
|
+
const answer = await prompts([
|
126
|
+
{
|
127
|
+
type: "text",
|
128
|
+
name: "message",
|
129
|
+
initial: "fix",
|
130
|
+
validate: value => value.length > 0 ? true : "El mensaje es requerido",
|
131
|
+
message: "Mensaje del commit"
|
132
|
+
}
|
133
|
+
]);
|
134
|
+
return answer.message;
|
150
135
|
}
|
151
136
|
export function getCurrentOrganization() {
|
152
137
|
const salidaConfig = executeShell('sf config get target-org --json');
|
@@ -157,7 +142,7 @@ export function getCurrentOrganization() {
|
|
157
142
|
for (const orgType in salidaOrgListJson.result) {
|
158
143
|
for (const orgObject of salidaOrgListJson.result[orgType]) {
|
159
144
|
if (orgObject.alias === targetOrg.value) {
|
160
|
-
if (
|
145
|
+
if (orgObject?.isExpired === true) {
|
161
146
|
throw new Error(`La scratch ${orgObject.alias} ha expirado!`);
|
162
147
|
}
|
163
148
|
return orgObject;
|
@@ -171,7 +156,7 @@ export function getOrganizationObject(alias, type = 'scratchOrgs') {
|
|
171
156
|
const salida = executeShell('sf org list --json');
|
172
157
|
const salidaJson = JSON.parse(salida);
|
173
158
|
const orgObject = salidaJson.result[type].filter(scratch => scratch.alias === alias)[0];
|
174
|
-
if (
|
159
|
+
if (orgObject?.isExpired === true) {
|
175
160
|
throw new Error(`La scratch ${orgObject.alias} ha expirado!`);
|
176
161
|
}
|
177
162
|
return orgObject;
|
@@ -190,28 +175,26 @@ export function getBranchName() {
|
|
190
175
|
}
|
191
176
|
return '';
|
192
177
|
}
|
193
|
-
export function executeFunction(step) {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if (typeof
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
returnValue = yield taskFunctions[functionName](...mergedArgs);
|
205
|
-
}
|
206
|
-
else {
|
207
|
-
returnValue = yield taskFunctions[functionName]();
|
208
|
-
}
|
178
|
+
export async function executeFunction(step) {
|
179
|
+
let returnValue = false;
|
180
|
+
const functionName = step.function;
|
181
|
+
if (typeof taskFunctions[functionName] === 'function') {
|
182
|
+
if (step.arguments && typeof step.arguments === 'object') {
|
183
|
+
let mergedArgs = context.mergeArgs(step.arguments);
|
184
|
+
if (!Array.isArray(mergedArgs)) {
|
185
|
+
const paramNames = getParams(taskFunctions[functionName]);
|
186
|
+
mergedArgs = createArray(paramNames, mergedArgs);
|
187
|
+
}
|
188
|
+
returnValue = await taskFunctions[functionName](...mergedArgs);
|
209
189
|
}
|
210
190
|
else {
|
211
|
-
|
191
|
+
returnValue = await taskFunctions[functionName]();
|
212
192
|
}
|
213
|
-
|
214
|
-
|
193
|
+
}
|
194
|
+
else {
|
195
|
+
throw new Error(`No se encontro la funcion ${functionName}`);
|
196
|
+
}
|
197
|
+
return returnValue;
|
215
198
|
}
|
216
199
|
export function executeShell(command) {
|
217
200
|
try {
|
@@ -219,7 +202,7 @@ export function executeShell(command) {
|
|
219
202
|
const salida = buffer.toString().trim();
|
220
203
|
return (salida.endsWith("\n") ? salida.slice(0, -1) : salida);
|
221
204
|
}
|
222
|
-
catch
|
205
|
+
catch {
|
223
206
|
return '';
|
224
207
|
}
|
225
208
|
}
|
@@ -240,86 +223,74 @@ export const taskFunctions = {
|
|
240
223
|
storeConfig({ [variable]: value });
|
241
224
|
return true;
|
242
225
|
},
|
243
|
-
docProcess() {
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
helper.execute(items, context.process, context.module);
|
256
|
-
}
|
226
|
+
async docProcess() {
|
227
|
+
if (!context.process) {
|
228
|
+
return false;
|
229
|
+
}
|
230
|
+
const files = getFilesChanged();
|
231
|
+
if (files.length > 0) {
|
232
|
+
for (const component in metadata) {
|
233
|
+
const helper = metadata[component];
|
234
|
+
const items = helper.getItems(files);
|
235
|
+
if (items.length > 0) {
|
236
|
+
context.addProcessMetadata(component, items);
|
237
|
+
helper.execute(items, context.process, context.module);
|
257
238
|
}
|
258
239
|
}
|
259
|
-
|
260
|
-
|
261
|
-
},
|
262
|
-
retrieveCode() {
|
263
|
-
return __awaiter(this, void 0, void 0, function* () {
|
264
|
-
const tryToRetrieve = yield askForContinue("Desea bajar los cambios?");
|
265
|
-
if (!tryToRetrieve) {
|
266
|
-
return false;
|
267
|
-
}
|
268
|
-
executeShell(`sf project retrieve start`);
|
269
|
-
return yield this.validateScratch();
|
270
|
-
});
|
240
|
+
}
|
241
|
+
return true;
|
271
242
|
},
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
});
|
243
|
+
async retrieveCode() {
|
244
|
+
const tryToRetrieve = await askForContinue("Desea bajar los cambios?");
|
245
|
+
if (!tryToRetrieve) {
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
executeShell(`sf project retrieve start`);
|
249
|
+
return await this.validateScratch();
|
280
250
|
},
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
const message = yield askForCommitMessage();
|
288
|
-
executeShell(`git add --all`);
|
289
|
-
executeShell(`git commit -m ${message}`);
|
290
|
-
return yield this.checkCommitPending();
|
291
|
-
});
|
251
|
+
async validateScratch() {
|
252
|
+
const salida = executeShell("sf project retrieve preview");
|
253
|
+
context.salida = salida;
|
254
|
+
const noHayCambios = salida.indexOf('No files will be deleted') !== -1 && salida.indexOf('No files will be retrieved') !== -1 && salida.indexOf('No conflicts found') !== -1;
|
255
|
+
// Probar de bajarlos // sf project retrieve start
|
256
|
+
return noHayCambios;
|
292
257
|
},
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
const branchName = context.branchName;
|
297
|
-
const salida = executeShell(`git push origin ${branchName}`);
|
298
|
-
return salida ? false : true;
|
299
|
-
}
|
300
|
-
catch (error) {
|
301
|
-
console.log(error);
|
302
|
-
}
|
303
|
-
// mergeBranch
|
258
|
+
async commitChanges() {
|
259
|
+
const tryToCommit = await askForContinue("Desea commitear los cambios?");
|
260
|
+
if (!tryToCommit) {
|
304
261
|
return false;
|
305
|
-
}
|
262
|
+
}
|
263
|
+
const message = await askForCommitMessage();
|
264
|
+
executeShell(`git add --all`);
|
265
|
+
executeShell(`git commit -m ${message}`);
|
266
|
+
return await this.checkCommitPending();
|
306
267
|
},
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
268
|
+
async publishBranch() {
|
269
|
+
try {
|
270
|
+
const branchName = context.branchName;
|
271
|
+
const salida = executeShell(`git push origin ${branchName}`);
|
272
|
+
return salida ? false : true;
|
273
|
+
}
|
274
|
+
catch (error) {
|
275
|
+
console.log(error);
|
276
|
+
}
|
277
|
+
// mergeBranch
|
278
|
+
return false;
|
279
|
+
},
|
280
|
+
async createPullRequest() {
|
281
|
+
if (context.gitApi === undefined || context.branchName === undefined || context.issueNumber === undefined) {
|
321
282
|
return false;
|
322
|
-
}
|
283
|
+
}
|
284
|
+
try {
|
285
|
+
context.issueFromBranch(context.branchName);
|
286
|
+
const result = await context.gitApi.createPullRequest(context.branchName, `resolves #${context.issueNumber} `, 'AI not implemented yet');
|
287
|
+
return result;
|
288
|
+
}
|
289
|
+
catch (error) {
|
290
|
+
console.log(error);
|
291
|
+
}
|
292
|
+
// mergeBranch
|
293
|
+
return false;
|
323
294
|
},
|
324
295
|
cancelIssue() {
|
325
296
|
console.log('Not implemented');
|
@@ -333,284 +304,257 @@ export const taskFunctions = {
|
|
333
304
|
console.log('Not implemented');
|
334
305
|
return false;
|
335
306
|
},
|
336
|
-
createIssue(title, label, body, milestone) {
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
type: 'text'
|
347
|
-
}
|
348
|
-
]);
|
349
|
-
if (answer.nombre !== undefined) {
|
350
|
-
const result = yield context.gitApi.createLabel(answer.nombre);
|
351
|
-
if (result === null || result === void 0 ? void 0 : result.id) {
|
352
|
-
label = result.id;
|
353
|
-
}
|
307
|
+
async createIssue(title, label, body, milestone) {
|
308
|
+
if (context.projectApi === undefined || context.gitApi === undefined) {
|
309
|
+
return false;
|
310
|
+
}
|
311
|
+
if (label === 'new') {
|
312
|
+
const answer = await prompts([
|
313
|
+
{
|
314
|
+
message: 'Nombre del Label',
|
315
|
+
name: 'nombre',
|
316
|
+
type: 'text'
|
354
317
|
}
|
355
|
-
|
356
|
-
|
318
|
+
]);
|
319
|
+
if (answer.nombre !== undefined) {
|
320
|
+
const result = await context.gitApi.createLabel(answer.nombre);
|
321
|
+
if (result?.id) {
|
322
|
+
label = result.id;
|
357
323
|
}
|
358
324
|
}
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
milestone = result === null || result === void 0 ? void 0 : result.id;
|
370
|
-
}
|
371
|
-
else {
|
372
|
-
milestone = '';
|
325
|
+
else {
|
326
|
+
label = '';
|
327
|
+
}
|
328
|
+
}
|
329
|
+
if (milestone === 'new') {
|
330
|
+
const answer = await prompts([
|
331
|
+
{
|
332
|
+
message: 'Nombre del Milestone',
|
333
|
+
name: 'nombre',
|
334
|
+
type: 'text'
|
373
335
|
}
|
336
|
+
]);
|
337
|
+
if (answer.nombre !== undefined) {
|
338
|
+
const result = await context.gitApi.createMilestone(answer.nombre);
|
339
|
+
milestone = result?.id;
|
374
340
|
}
|
375
|
-
|
376
|
-
|
377
|
-
console.log(`Se creo el issue ${issue.number}`);
|
378
|
-
console.log(`${issue.url}`);
|
379
|
-
// if ( issue.milestone) {
|
380
|
-
// console.log(`Milestone ${issue.milestone.title} expira en ${issue.milestone.dueOn} `);
|
381
|
-
// }
|
382
|
-
return true;
|
341
|
+
else {
|
342
|
+
milestone = '';
|
383
343
|
}
|
344
|
+
}
|
345
|
+
const issue = await context.projectApi.createIssue(title, context.backlogColumn, label, body, milestone);
|
346
|
+
if (issue) {
|
347
|
+
console.log(`Se creo el issue ${issue.number}`);
|
348
|
+
console.log(`${issue.url}`);
|
349
|
+
// if ( issue.milestone) {
|
350
|
+
// console.log(`Milestone ${issue.milestone.title} expira en ${issue.milestone.dueOn} `);
|
351
|
+
// }
|
352
|
+
return true;
|
353
|
+
}
|
354
|
+
return false;
|
355
|
+
},
|
356
|
+
async createTemplate(template, folder, name, identifier) {
|
357
|
+
const filename = name.toLocaleLowerCase().replaceAll(' ', '-') + '.md';
|
358
|
+
createTemplate('.', 'md', template, filename, folder, { name, identifier });
|
359
|
+
return true;
|
360
|
+
},
|
361
|
+
async validateIssue(issueNumber, states) {
|
362
|
+
if (context.projectApi === undefined) {
|
384
363
|
return false;
|
385
|
-
}
|
364
|
+
}
|
365
|
+
const issue = await context.projectApi.getIssue(issueNumber);
|
366
|
+
if (!issue.state) {
|
367
|
+
return false;
|
368
|
+
}
|
369
|
+
const arrayStates = states.toLocaleLowerCase().replace(' ', '').split(',');
|
370
|
+
return arrayStates.includes(issue.state.toLocaleLowerCase().replace(' ', ''));
|
386
371
|
},
|
387
|
-
|
388
|
-
return
|
389
|
-
const filename = name.toLocaleLowerCase().replaceAll(' ', '-') + '.md';
|
390
|
-
createTemplate('.', 'md', template, filename, folder, { name, identifier });
|
391
|
-
return true;
|
392
|
-
});
|
372
|
+
async validaNoseaBranchActual(newBranchName) {
|
373
|
+
return getBranchName() !== newBranchName;
|
393
374
|
},
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
return arrayStates.includes(issue.state.toLocaleLowerCase().replace(' ', ''));
|
405
|
-
});
|
375
|
+
async checkCommitPending() {
|
376
|
+
try {
|
377
|
+
const cambios = executeShell("git status --porcelain=v1");
|
378
|
+
context.salida = cambios;
|
379
|
+
return cambios == '';
|
380
|
+
}
|
381
|
+
catch (error) {
|
382
|
+
console.log(error);
|
383
|
+
}
|
384
|
+
return false;
|
406
385
|
},
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
386
|
+
async createBranch() {
|
387
|
+
try {
|
388
|
+
const newBranchName = context.newBranchName;
|
389
|
+
executeShell(`git checkout -b ${newBranchName} origin/main`);
|
390
|
+
context.set('branchName', getBranchName());
|
391
|
+
return true;
|
392
|
+
}
|
393
|
+
catch (error) {
|
394
|
+
console.log(error);
|
395
|
+
}
|
396
|
+
// mergeBranch
|
397
|
+
return false;
|
411
398
|
},
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
return false;
|
423
|
-
});
|
399
|
+
async mergeBranch() {
|
400
|
+
try {
|
401
|
+
executeShell(`git fetch`);
|
402
|
+
executeShell(`git merge origin/main`);
|
403
|
+
return true;
|
404
|
+
}
|
405
|
+
catch (error) {
|
406
|
+
console.log(error);
|
407
|
+
}
|
408
|
+
return false;
|
424
409
|
},
|
425
|
-
|
426
|
-
|
427
|
-
try {
|
428
|
-
const newBranchName = context.newBranchName;
|
429
|
-
executeShell(`git checkout -b ${newBranchName} origin/main`);
|
430
|
-
context.set('branchName', getBranchName());
|
431
|
-
return true;
|
432
|
-
}
|
433
|
-
catch (error) {
|
434
|
-
console.log(error);
|
435
|
-
}
|
436
|
-
// mergeBranch
|
410
|
+
async moveIssue(issueNumber, state) {
|
411
|
+
if (context.projectApi === undefined) {
|
437
412
|
return false;
|
438
|
-
}
|
413
|
+
}
|
414
|
+
const result = await context.projectApi.moveIssue(issueNumber, state);
|
415
|
+
return result;
|
439
416
|
},
|
440
|
-
|
441
|
-
|
442
|
-
try {
|
443
|
-
executeShell(`git fetch`);
|
444
|
-
executeShell(`git merge origin/main`);
|
445
|
-
return true;
|
446
|
-
}
|
447
|
-
catch (error) {
|
448
|
-
console.log(error);
|
449
|
-
}
|
417
|
+
async assignBranchToIssue(issueNumber, newBranchName) {
|
418
|
+
if (context.gitApi === undefined) {
|
450
419
|
return false;
|
451
|
-
}
|
452
|
-
|
453
|
-
|
454
|
-
return
|
455
|
-
if (context.projectApi === undefined) {
|
456
|
-
return false;
|
457
|
-
}
|
458
|
-
const result = yield context.projectApi.moveIssue(issueNumber, state);
|
459
|
-
return result;
|
460
|
-
});
|
461
|
-
},
|
462
|
-
assignBranchToIssue(issueNumber, newBranchName) {
|
463
|
-
return __awaiter(this, void 0, void 0, function* () {
|
464
|
-
if (context.gitApi === undefined) {
|
465
|
-
return false;
|
466
|
-
}
|
467
|
-
const commitSha = executeShell(`git rev-parse --verify main`);
|
468
|
-
const result = yield context.gitApi.assignBranchToIssue(issueNumber, newBranchName, commitSha);
|
469
|
-
return result;
|
470
|
-
});
|
420
|
+
}
|
421
|
+
const commitSha = executeShell(`git rev-parse --verify main`);
|
422
|
+
const result = await context.gitApi.assignBranchToIssue(issueNumber, newBranchName, commitSha);
|
423
|
+
return result;
|
471
424
|
},
|
472
|
-
assignIssueToMe(issueNumber) {
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
return result;
|
479
|
-
});
|
425
|
+
async assignIssueToMe(issueNumber) {
|
426
|
+
if (!context.projectApi) {
|
427
|
+
return false;
|
428
|
+
}
|
429
|
+
const result = await context.projectApi.assignIssueToMe(issueNumber);
|
430
|
+
return result;
|
480
431
|
},
|
481
|
-
viewIssue(
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
return true;
|
490
|
-
});
|
432
|
+
async viewIssue(issueNumber, template = 'viewIssue') {
|
433
|
+
if (!context.projectApi) {
|
434
|
+
return false;
|
435
|
+
}
|
436
|
+
const result = await context.projectApi.getIssue(issueNumber);
|
437
|
+
const rendered = generateTemplate(getModelFolders('templates'), 'bash', template, { issue: result, ...context });
|
438
|
+
console.log(rendered);
|
439
|
+
return true;
|
491
440
|
},
|
492
|
-
listIssues(listFilter, listTemplate) {
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
441
|
+
async listIssues(listFilter, listTemplate) {
|
442
|
+
let filter = '{states: OPEN}';
|
443
|
+
const extension = '*';
|
444
|
+
if (!listFilter) {
|
445
|
+
listFilter = context.options.filter || context.listFilter;
|
446
|
+
}
|
447
|
+
if (!listTemplate) {
|
448
|
+
listTemplate = context.options.template || context.listTemplate;
|
449
|
+
}
|
450
|
+
if (!context.projectApi || !context.gitApi) {
|
451
|
+
return false;
|
452
|
+
}
|
453
|
+
if (!listFilter) {
|
454
|
+
const answer = await prompts([
|
455
|
+
{
|
456
|
+
message: 'Elija un filtro, o bien lo puede dejar fijo en autoforce como listFilter',
|
457
|
+
name: 'filter',
|
458
|
+
type: 'select',
|
459
|
+
initial: 0,
|
460
|
+
choices: context.listFilters
|
461
|
+
}
|
462
|
+
]);
|
463
|
+
listFilter = answer.filter;
|
464
|
+
}
|
465
|
+
if (listFilter === ListFilters.PorMilestone) {
|
466
|
+
if (context.options.milestone) {
|
467
|
+
const milestoneFilter = (await context.gitApi.getMilestones()).filter(milestone => milestone.title == context.options.milestone);
|
468
|
+
if (milestoneFilter.length === 0) {
|
469
|
+
return false;
|
470
|
+
}
|
471
|
+
filter = `{ milestoneNumber: "${milestoneFilter[0].number}"}`;
|
504
472
|
}
|
505
|
-
|
506
|
-
const
|
473
|
+
else {
|
474
|
+
const choices = (await context.gitApi.getMilestones()).map(milestone => { return { value: milestone.number, title: milestone.title }; });
|
475
|
+
choices.push({ value: '', title: 'Issues sin Milestone' });
|
476
|
+
choices.push({ value: '*', title: 'Issues con Milestone' });
|
477
|
+
const answer = await prompts([
|
507
478
|
{
|
508
|
-
message: 'Elija un
|
509
|
-
name: '
|
479
|
+
message: 'Elija un milestone',
|
480
|
+
name: 'filterValue',
|
510
481
|
type: 'select',
|
511
482
|
initial: 0,
|
512
|
-
choices
|
483
|
+
choices
|
513
484
|
}
|
514
485
|
]);
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
if (context.options.milestone) {
|
519
|
-
const milestoneFilter = (yield context.gitApi.getMilestones()).filter(milestone => milestone.title == context.options.milestone);
|
520
|
-
if (milestoneFilter.length === 0) {
|
521
|
-
return false;
|
522
|
-
}
|
523
|
-
filter = `{ milestoneNumber: "${milestoneFilter[0].number}"}`;
|
524
|
-
}
|
525
|
-
else {
|
526
|
-
const choices = (yield context.gitApi.getMilestones()).map(milestone => { return { value: milestone.number, title: milestone.title }; });
|
527
|
-
choices.push({ value: '', title: 'Issues sin Milestone' });
|
528
|
-
choices.push({ value: '*', title: 'Issues con Milestone' });
|
529
|
-
const answer = yield prompts([
|
530
|
-
{
|
531
|
-
message: 'Elija un milestone',
|
532
|
-
name: 'filterValue',
|
533
|
-
type: 'select',
|
534
|
-
initial: 0,
|
535
|
-
choices
|
536
|
-
}
|
537
|
-
]);
|
538
|
-
filter = `{ milestoneNumber: "${answer.filterValue}"}`;
|
539
|
-
if (answer.filterValue === undefined)
|
540
|
-
return false;
|
541
|
-
}
|
486
|
+
filter = `{ milestoneNumber: "${answer.filterValue}"}`;
|
487
|
+
if (answer.filterValue === undefined)
|
488
|
+
return false;
|
542
489
|
}
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
}
|
547
|
-
else {
|
548
|
-
const labels = (yield context.gitApi.getLabels()).map(label => label.name);
|
549
|
-
const choices = valuesToChoices(labels);
|
550
|
-
const answer = yield prompts([
|
551
|
-
{
|
552
|
-
message: 'Elija un label',
|
553
|
-
name: 'filterValue',
|
554
|
-
type: 'select',
|
555
|
-
initial: 0,
|
556
|
-
choices
|
557
|
-
}
|
558
|
-
]);
|
559
|
-
if (answer.filterValue === undefined)
|
560
|
-
return false;
|
561
|
-
filter = `{labels: "${answer.filterValue}"}`;
|
562
|
-
}
|
490
|
+
}
|
491
|
+
if (listFilter === ListFilters.PorLabel) {
|
492
|
+
if (context.options.label) {
|
493
|
+
filter = `{labels: "${context.options.label}"}`;
|
563
494
|
}
|
564
|
-
|
565
|
-
const
|
566
|
-
const
|
567
|
-
const answer =
|
495
|
+
else {
|
496
|
+
const labels = (await context.gitApi.getLabels()).map(label => label.name);
|
497
|
+
const choices = valuesToChoices(labels);
|
498
|
+
const answer = await prompts([
|
568
499
|
{
|
569
|
-
message: 'Elija un
|
570
|
-
name: '
|
500
|
+
message: 'Elija un label',
|
501
|
+
name: 'filterValue',
|
571
502
|
type: 'select',
|
572
503
|
initial: 0,
|
573
|
-
choices
|
504
|
+
choices
|
574
505
|
}
|
575
506
|
]);
|
576
|
-
|
577
|
-
if (listTemplate === undefined)
|
507
|
+
if (answer.filterValue === undefined)
|
578
508
|
return false;
|
509
|
+
filter = `{labels: "${answer.filterValue}"}`;
|
579
510
|
}
|
580
|
-
|
581
|
-
|
582
|
-
const
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
511
|
+
}
|
512
|
+
if (!listTemplate) {
|
513
|
+
const files = getFilesInFolders(getModelFolders('templates'), filterBash).map(filename => filename.split(".")[0]);
|
514
|
+
const templates = valuesToChoices(files);
|
515
|
+
const answer = await prompts([
|
516
|
+
{
|
517
|
+
message: 'Elija un template, o bien lo puede dejar en autoforce como listTemplate',
|
518
|
+
name: 'template',
|
519
|
+
type: 'select',
|
520
|
+
initial: 0,
|
521
|
+
choices: templates
|
522
|
+
}
|
523
|
+
]);
|
524
|
+
listTemplate = answer.template;
|
525
|
+
if (listTemplate === undefined)
|
591
526
|
return false;
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
527
|
+
}
|
528
|
+
const result = await context.projectApi.getIssuesWithFilter(filter);
|
529
|
+
console.log(context.version);
|
530
|
+
const rendered = generateTemplate(getModelFolders('templates'), extension, listTemplate, { issues: result, context });
|
531
|
+
console.log(rendered);
|
532
|
+
return true;
|
533
|
+
},
|
534
|
+
async checkIssueType(issueNumber) {
|
535
|
+
if (!context.projectApi) {
|
536
|
+
return false;
|
537
|
+
}
|
538
|
+
const issue = await context.projectApi.getIssue(issueNumber);
|
539
|
+
// Setea el issueType segun el issue
|
540
|
+
try {
|
541
|
+
let newIssueType = 'feature';
|
542
|
+
if (issue.labels && issue.labels?.length > 0) {
|
543
|
+
if (issue.labels.includes('documentation')) {
|
544
|
+
newIssueType = 'doc';
|
545
|
+
}
|
546
|
+
else if (issue.labels.includes('automation')) {
|
547
|
+
newIssueType = 'automation';
|
548
|
+
}
|
549
|
+
else if (issue.labels.includes('bug')) {
|
550
|
+
newIssueType = 'fix';
|
607
551
|
}
|
608
|
-
context.newIssueType = newIssueType;
|
609
|
-
}
|
610
|
-
catch (error) {
|
611
|
-
console.log(error);
|
612
552
|
}
|
613
|
-
|
614
|
-
}
|
553
|
+
context.newIssueType = newIssueType;
|
554
|
+
}
|
555
|
+
catch (error) {
|
556
|
+
console.log(error);
|
557
|
+
}
|
558
|
+
return true;
|
615
559
|
}
|
616
560
|
};
|