bdy 1.20.0-dev → 1.20.0-dev-pipeline

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 (51) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +110 -2
  3. package/distTs/src/command/crawl/link.js +61 -0
  4. package/distTs/src/command/crawl/run.js +147 -0
  5. package/distTs/src/command/crawl/validation.js +154 -0
  6. package/distTs/src/command/crawl.js +13 -0
  7. package/distTs/src/command/pipeline/create.js +45 -0
  8. package/distTs/src/command/pipeline/delete.js +41 -0
  9. package/distTs/src/command/pipeline/get.js +42 -0
  10. package/distTs/src/command/pipeline/list.js +43 -0
  11. package/distTs/src/command/pipeline/run/apply.js +62 -0
  12. package/distTs/src/command/pipeline/run/approve.js +62 -0
  13. package/distTs/src/command/pipeline/run/cancel.js +36 -0
  14. package/distTs/src/command/pipeline/run/list.js +52 -0
  15. package/distTs/src/command/pipeline/run/logs.js +37 -0
  16. package/distTs/src/command/pipeline/run/retry.js +36 -0
  17. package/distTs/src/command/pipeline/run/start.js +96 -0
  18. package/distTs/src/command/pipeline/run/status.js +35 -0
  19. package/distTs/src/command/pipeline/run.js +22 -125
  20. package/distTs/src/command/pipeline/update.js +41 -0
  21. package/distTs/src/command/pipeline/yaml.js +38 -0
  22. package/distTs/src/command/pipeline.js +26 -0
  23. package/distTs/src/command/project/link.js +11 -11
  24. package/distTs/src/command/tests/capture/validation.js +46 -0
  25. package/distTs/src/command/tests/capture.js +103 -0
  26. package/distTs/src/command/tests/unit/link.js +61 -0
  27. package/distTs/src/command/tests/unit/upload.js +91 -0
  28. package/distTs/src/command/tests/unit.js +13 -0
  29. package/distTs/src/command/tests/visual/link.js +61 -0
  30. package/distTs/src/command/tests/visual/session/close.js +32 -0
  31. package/distTs/src/command/tests/visual/session/create.js +86 -0
  32. package/distTs/src/command/tests/visual/session.js +13 -0
  33. package/distTs/src/command/tests/visual/setup.js +20 -0
  34. package/distTs/src/command/tests/visual/shared/validation.js +145 -0
  35. package/distTs/src/command/tests/visual/upload.js +141 -0
  36. package/distTs/src/command/tests/visual.js +17 -0
  37. package/distTs/src/command/tests.js +15 -0
  38. package/distTs/src/crawl/requests.js +141 -0
  39. package/distTs/src/input.js +11 -10
  40. package/distTs/src/output/pipeline.js +1565 -0
  41. package/distTs/src/output.js +149 -31
  42. package/distTs/src/texts.js +93 -34
  43. package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
  44. package/distTs/src/types/crawl.js +2 -0
  45. package/distTs/src/types/pipeline.js +424 -0
  46. package/distTs/src/unitTest/context.js +26 -0
  47. package/package.json +1 -1
  48. package/distTs/src/command/project/get.js +0 -18
  49. package/distTs/src/command/project/set.js +0 -31
  50. package/distTs/src/command/sandbox/get/yaml.js +0 -30
  51. package/distTs/src/command/vt/scrape.js +0 -193
@@ -0,0 +1,1565 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const output_1 = __importDefault(require("../output"));
7
+ const pipeline_1 = require("../types/pipeline");
8
+ const utils_1 = require("../utils");
9
+ // @ts-ignore
10
+ const termkit_no_lazy_require_1 = __importDefault(require("terminal-kit/lib/termkit-no-lazy-require"));
11
+ var LOOP_STATUS;
12
+ (function (LOOP_STATUS) {
13
+ LOOP_STATUS["DISABLED"] = "DISABLED";
14
+ LOOP_STATUS["RESOLVED"] = "RESOLVED";
15
+ LOOP_STATUS["NO_LOOP"] = "NO_LOOP";
16
+ LOOP_STATUS["LIMIT_REACHED"] = "LIMIT_REACHED";
17
+ LOOP_STATUS["ERROR"] = "ERROR";
18
+ LOOP_STATUS["DYNAMIC"] = "DYNAMIC";
19
+ })(LOOP_STATUS || (LOOP_STATUS = {}));
20
+ var MODE;
21
+ (function (MODE) {
22
+ MODE["RUN"] = "RUN";
23
+ MODE["ACTION"] = "ACTION";
24
+ })(MODE || (MODE = {}));
25
+ const LOGS_LIMIT = 1000;
26
+ class OutputPipeline {
27
+ static async runLogs(client, workspace, project, pipelineId, runId, runActionId, noWait) {
28
+ if (output_1.default.isTTY() && !noWait) {
29
+ return await this._runLogsInteractive(client, workspace, project, pipelineId, runId, runActionId);
30
+ }
31
+ return await this._runLogsNonInteractive(client, workspace, project, pipelineId, runId, runActionId, noWait);
32
+ }
33
+ static async runStatus(client, workspace, project, identifier, pipelineId, runId, noWait) {
34
+ if (output_1.default.isTTY() && !noWait) {
35
+ return await this._runStatusInteractive(client, workspace, project, pipelineId, runId);
36
+ }
37
+ return await this._runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait);
38
+ }
39
+ static _canCancel(status) {
40
+ return ![
41
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
42
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
43
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATING,
44
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
45
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
46
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
47
+ ].includes(status);
48
+ }
49
+ static _canRetry(status) {
50
+ return [
51
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
52
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
53
+ ].includes(status);
54
+ }
55
+ static _canApprove(status) {
56
+ return [pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY].includes(status);
57
+ }
58
+ static _fillString(str, length) {
59
+ if (str.length >= length - 1)
60
+ return str.substring(0, length - 1) + ' ';
61
+ for (let i = str.length; i < length; i += 1)
62
+ str += ' ';
63
+ return str;
64
+ }
65
+ static _makeSpaces(length) {
66
+ let str = '';
67
+ for (let i = 0; i < length; i += 1)
68
+ str += ' ';
69
+ return str;
70
+ }
71
+ static _formatDate(date) {
72
+ let str = `${date.getFullYear()}-`;
73
+ const m = date.getMonth() + 1;
74
+ if (m < 10)
75
+ str += '0';
76
+ str += `${m}-`;
77
+ const d = date.getDate();
78
+ if (d < 10)
79
+ str += '0';
80
+ str += `${d} `;
81
+ const h = date.getHours();
82
+ if (h < 10)
83
+ str += '0';
84
+ str += `${h}:`;
85
+ const mm = date.getMinutes();
86
+ if (mm < 10)
87
+ str += '0';
88
+ str += `${mm}:`;
89
+ const s = date.getSeconds();
90
+ if (s < 10)
91
+ str += '0';
92
+ str += s;
93
+ return str;
94
+ }
95
+ static _formatTimespan(start, end) {
96
+ if (!end)
97
+ end = new Date();
98
+ let ts = Math.abs(end.getTime() - start.getTime());
99
+ if (!ts)
100
+ return '';
101
+ const hours = Math.floor(ts / 1000 / 60 / 60);
102
+ ts -= hours * 60 * 60 * 1000;
103
+ const minutes = Math.floor(ts / 1000 / 60);
104
+ ts -= minutes * 60 * 1000;
105
+ const seconds = Math.ceil(ts / 1000);
106
+ let str = '';
107
+ if (hours > 0)
108
+ str += `${hours}h `;
109
+ if (minutes > 0 || hours > 0)
110
+ str += `${minutes}m `;
111
+ if (seconds < 10 && (hours > 0 || minutes > 0))
112
+ str += '0';
113
+ str += `${seconds}s`;
114
+ return str;
115
+ }
116
+ static _runDetailsHeader() {
117
+ return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('DETAILS')}`;
118
+ }
119
+ static _runLogsHeader() {
120
+ return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('LOGS')}`;
121
+ }
122
+ static _runOutputHeader() {
123
+ return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('OUTPUT')}`;
124
+ }
125
+ static _runDetailsStarted(status, started, delayed, tabs) {
126
+ if (delayed && status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
127
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Scheduled', tabs))}`;
128
+ str += output_1.default.getTermKitMutedColor(this._formatDate(delayed || new Date()));
129
+ return str;
130
+ }
131
+ if ([
132
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
133
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATING,
134
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
135
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
136
+ pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS,
137
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
138
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
139
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
140
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
141
+ ].includes(status)) {
142
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Started', tabs))}`;
143
+ str += output_1.default.getTermKitMutedColor(this._formatDate(started || new Date()));
144
+ return str;
145
+ }
146
+ return null;
147
+ }
148
+ static _runActionsHeader(tabs) {
149
+ return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor(this._fillString('ACTIONS', 3 * tabs))} ${output_1.default.getTermKitLabelColor('ID')}`;
150
+ }
151
+ static _actionLogs(logs, scroll, limit = 0) {
152
+ const str = [];
153
+ if (logs.length > 0) {
154
+ let start = logs.length - scroll - limit;
155
+ if (start < 0)
156
+ start = 0;
157
+ let end = start + limit;
158
+ if (end > logs.length)
159
+ end = logs.length;
160
+ for (let i = start; i < end; i += 1) {
161
+ str.push(`${output_1.default.getTermKitDimColor(logs[i])}`);
162
+ }
163
+ }
164
+ else {
165
+ str.push(` ${output_1.default.getTermKitDimColor('Waiting...')}`);
166
+ }
167
+ return str;
168
+ }
169
+ static _getActionLoop(action, highlight, tabs) {
170
+ let outer = '[';
171
+ let dim = false;
172
+ let red = false;
173
+ if (action.loop === LOOP_STATUS.DYNAMIC) {
174
+ outer += 'Loop';
175
+ dim = true;
176
+ }
177
+ else if (action.loop === LOOP_STATUS.RESOLVED) {
178
+ outer += 'Loop';
179
+ }
180
+ else if (action.loop !== LOOP_STATUS.DISABLED) {
181
+ red = true;
182
+ outer += 'Loop';
183
+ }
184
+ if (action.target) {
185
+ if (action.loop !== LOOP_STATUS.DISABLED)
186
+ outer += ', ';
187
+ outer += action.target;
188
+ }
189
+ if (outer.length + 2 >= tabs) {
190
+ outer = outer.substring(0, tabs - 2);
191
+ }
192
+ outer += ']';
193
+ outer = this._fillString(outer, tabs);
194
+ if (highlight) {
195
+ return output_1.default.getTermKitCyanColor(outer);
196
+ }
197
+ if (red) {
198
+ return output_1.default.getTermKitRedColor(outer);
199
+ }
200
+ if (dim) {
201
+ return output_1.default.getTermKitDimColor(outer);
202
+ }
203
+ return output_1.default.getTermKitArgColor(outer);
204
+ }
205
+ static _getActionName(action, highlight, tabs) {
206
+ let s = '';
207
+ let name = action.name || '';
208
+ if (name.length + 1 >= tabs)
209
+ name = name.substring(0, tabs - 1);
210
+ if (highlight) {
211
+ s += output_1.default.getTermKitCyanColor(name);
212
+ }
213
+ else if ([
214
+ pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS,
215
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATING,
216
+ ].includes(action.status)) {
217
+ s += output_1.default.getTermKitBlueColor(name);
218
+ }
219
+ else if ([
220
+ pipeline_1.PIPELINE_RUN_STATUS.INITIAL,
221
+ pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED,
222
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
223
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
224
+ ].includes(action.status)) {
225
+ s += output_1.default.getTermKitDimColor(name);
226
+ }
227
+ else {
228
+ s += output_1.default.getTermKitMutedColor(name);
229
+ }
230
+ const loopLength = tabs - name.length;
231
+ if (action.loopValues.length > 0 && loopLength >= 5) {
232
+ let loop = ' [';
233
+ action.loopValues.forEach((v, i) => {
234
+ if (i > 0)
235
+ loop += ', ';
236
+ loop += `${v.value}`;
237
+ });
238
+ if (loop.length > loopLength - 2) {
239
+ loop = loop.substring(0, loopLength - 2);
240
+ }
241
+ loop += ']';
242
+ if (highlight) {
243
+ s += output_1.default.getTermKitCyanColor(loop);
244
+ }
245
+ else {
246
+ s += output_1.default.getTermKitArgColor(loop);
247
+ }
248
+ s += this._fillString('', loopLength - loop.length + 1);
249
+ }
250
+ else if (loopLength > 0) {
251
+ s += this._fillString('', loopLength + 1);
252
+ }
253
+ return s;
254
+ }
255
+ static _getActionType(action, highlight, tabs) {
256
+ let s = '';
257
+ let l = action.type.length;
258
+ if (highlight) {
259
+ s += output_1.default.getTermKitCyanColor('❯ ');
260
+ s += output_1.default.getTermKitCyanColor(action.type);
261
+ }
262
+ else {
263
+ s += ' ';
264
+ s += output_1.default.getTermKitDimColor(action.type);
265
+ }
266
+ if (tabs - l > 6 &&
267
+ (action.target || action.loop !== LOOP_STATUS.DISABLED)) {
268
+ l += 1;
269
+ s += ' ';
270
+ s += this._getActionLoop(action, highlight, tabs - l);
271
+ }
272
+ else {
273
+ s += this._makeSpaces(tabs - l);
274
+ }
275
+ return s;
276
+ }
277
+ static _runActions(run, onlyChanged = false, limit, selected, tabs) {
278
+ const str = [];
279
+ if (!run)
280
+ return str;
281
+ if (!onlyChanged) {
282
+ str.push(this._runActionsHeader(tabs));
283
+ }
284
+ let count = 0;
285
+ let start = 0;
286
+ if (selected >= limit / 2) {
287
+ start = selected - Math.floor(limit / 2);
288
+ if (start + limit >= run.actions.length) {
289
+ start = run.actions.length - limit;
290
+ }
291
+ }
292
+ for (let i = start; i < run.actions.length; i += 1) {
293
+ const a = run.actions[i];
294
+ if (!a || (onlyChanged && !a.changed))
295
+ continue;
296
+ let s = '';
297
+ const highlight = i === selected;
298
+ s += this._getActionType(a, highlight, tabs);
299
+ s += this._getActionName(a, highlight, 2 * tabs);
300
+ if (![
301
+ pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED,
302
+ pipeline_1.PIPELINE_RUN_STATUS.INITIAL,
303
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
304
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
305
+ ].includes(a.status)) {
306
+ if (highlight) {
307
+ s += output_1.default.getTermKitCyanColor(this._fillString(a.id, 25));
308
+ }
309
+ else {
310
+ s += output_1.default.getTermKitDimColor(this._fillString(a.id, 25));
311
+ }
312
+ }
313
+ else {
314
+ s += this._fillString('', 25);
315
+ }
316
+ let ts = false;
317
+ const txt = this.runStatusText(a.status);
318
+ if (a.status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
319
+ if (onlyChanged) {
320
+ s += output_1.default.getTermKitBlueColor(pipeline_1.PIPELINE_STATUS_ICONS.INPROGRESS);
321
+ }
322
+ else {
323
+ s += output_1.default.getTermKitBlueColor(this._statusAnimationString());
324
+ }
325
+ ts = true;
326
+ }
327
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
328
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.ENQUEUED);
329
+ s += ` ${output_1.default.getTermKitDimColor(txt)}`;
330
+ }
331
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
332
+ s += output_1.default.getTermKitRedColor(pipeline_1.PIPELINE_STATUS_ICONS.TERMINATED);
333
+ ts = true;
334
+ }
335
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
336
+ s += output_1.default.getTermKitGreenColor(pipeline_1.PIPELINE_STATUS_ICONS.SUCCESSFUL);
337
+ ts = true;
338
+ }
339
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
340
+ s += output_1.default.getTermKitRedColor(pipeline_1.PIPELINE_STATUS_ICONS.FAILED);
341
+ ts = true;
342
+ }
343
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
344
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.INITIAL);
345
+ s += ` ${output_1.default.getTermKitDimColor(txt)}`;
346
+ }
347
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
348
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.NOT_EXECUTED);
349
+ s += ` ${output_1.default.getTermKitDimColor(txt)}`;
350
+ }
351
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
352
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.SKIPPED);
353
+ s += ` ${output_1.default.getTermKitDimColor(txt)}`;
354
+ }
355
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
356
+ if (onlyChanged) {
357
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.TERMINATING);
358
+ }
359
+ else {
360
+ s += output_1.default.getTermKitBlueColor(this._statusAnimationString());
361
+ }
362
+ ts = true;
363
+ }
364
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY) {
365
+ s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_APPLY);
366
+ s += ` ${output_1.default.getTermKitPurpleColor(txt)}`;
367
+ }
368
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES) {
369
+ s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_VARIABLES);
370
+ s += ` ${output_1.default.getTermKitPurpleColor(txt)}`;
371
+ }
372
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES) {
373
+ s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_SETTABLE_VARIABLES);
374
+ s += ` ${output_1.default.getTermKitPurpleColor(txt)}`;
375
+ }
376
+ else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION) {
377
+ s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_VT_SESSION);
378
+ s += ` ${output_1.default.getTermKitPurpleColor(txt)}`;
379
+ }
380
+ else {
381
+ s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.SKIPPED);
382
+ s += ` ${output_1.default.getTermKitDimColor(a.status)}`;
383
+ }
384
+ if (ts && a.started) {
385
+ s += ` ${output_1.default.getTermKitMutedColor(this._formatTimespan(a.started, a.finished))}`;
386
+ }
387
+ str.push(s);
388
+ count += 1;
389
+ if (limit && count >= limit)
390
+ break;
391
+ }
392
+ return str;
393
+ }
394
+ static _runContext(run, tabs) {
395
+ const str = [];
396
+ if (run?.context) {
397
+ str.push(`${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('CONTEXT')}`);
398
+ const ctx = run.context;
399
+ Object.keys(ctx).forEach((name) => {
400
+ str.push(` ${output_1.default.getTermKitDimColor(this._fillString(name, tabs))}${output_1.default.getTermKitMutedColor(ctx[name])}`);
401
+ });
402
+ }
403
+ return str;
404
+ }
405
+ static _runActionTarget(action, tabs) {
406
+ if (!action.target)
407
+ return null;
408
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Target', tabs))}`;
409
+ str += output_1.default.getTermKitMutedColor(action.target);
410
+ return str;
411
+ }
412
+ static _runLoopText(loop, variables) {
413
+ if (loop === LOOP_STATUS.NO_LOOP) {
414
+ return 'Not found';
415
+ }
416
+ else if (loop === LOOP_STATUS.LIMIT_REACHED) {
417
+ return 'Limit reached';
418
+ }
419
+ else if (loop === LOOP_STATUS.ERROR) {
420
+ return 'Something went wrong';
421
+ }
422
+ else if (loop === LOOP_STATUS.DYNAMIC) {
423
+ return 'Not calculated yet';
424
+ }
425
+ else if (!variables.length) {
426
+ return 'No variables resolved';
427
+ }
428
+ else {
429
+ let vars = '';
430
+ variables.forEach((v, i) => {
431
+ if (i > 0)
432
+ vars += ', ';
433
+ vars += `${v.key}:${v.value}`;
434
+ });
435
+ return vars;
436
+ }
437
+ }
438
+ static _runLoopVariables(loop, variables, tabs) {
439
+ if (loop === LOOP_STATUS.DISABLED)
440
+ return null;
441
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Loop', tabs))}`;
442
+ const txt = this._runLoopText(loop, variables);
443
+ if (loop === LOOP_STATUS.NO_LOOP) {
444
+ str += output_1.default.getTermKitRedColor(txt);
445
+ }
446
+ else if (loop === LOOP_STATUS.LIMIT_REACHED) {
447
+ str += output_1.default.getTermKitRedColor(txt);
448
+ }
449
+ else if (loop === LOOP_STATUS.ERROR) {
450
+ str += output_1.default.getTermKitRedColor(txt);
451
+ }
452
+ else if (loop === LOOP_STATUS.DYNAMIC) {
453
+ str += output_1.default.getTermKitDimColor(txt);
454
+ }
455
+ else if (!variables.length) {
456
+ str += output_1.default.getTermKitMutedColor(txt);
457
+ }
458
+ else {
459
+ str += output_1.default.getTermKitMutedColor(txt);
460
+ }
461
+ return str;
462
+ }
463
+ static _dimLine() {
464
+ const termWidth = termkit_no_lazy_require_1.default.terminal.width;
465
+ const width = Number.isFinite(termWidth) && termWidth > 2 ? termWidth - 2 : 25;
466
+ return output_1.default.getTermKitDimColor(` ${'—'.repeat(width)}`);
467
+ }
468
+ static _runActionsLogsHelp(identifier, runId) {
469
+ return `${output_1.default.getTermKitDimColor(' To view action logs run: ')}${output_1.default.getTermKitMutedColor(`bdy pip run logs ${identifier} ${runId} <run-action-id>`)}`;
470
+ }
471
+ static _runDetailsFinished(status, finished, tabs) {
472
+ if (finished &&
473
+ [
474
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
475
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
476
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
477
+ ].includes(status)) {
478
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Finished', tabs))}`;
479
+ str += output_1.default.getTermKitMutedColor(this._formatDate(finished));
480
+ return str;
481
+ }
482
+ return null;
483
+ }
484
+ static _runDetailsTriggerer(run, tabs) {
485
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Trigger', tabs))}`;
486
+ if (run?.creator) {
487
+ str += `${output_1.default.getTermKitBlueColor(run.creator)} - `;
488
+ }
489
+ if (!run || run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.CLICK) {
490
+ str += output_1.default.getTermKitMutedColor('Manual');
491
+ }
492
+ else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.SCHEDULE) {
493
+ str += output_1.default.getTermKitMutedColor('Schedule');
494
+ }
495
+ else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EVENT) {
496
+ str += output_1.default.getTermKitMutedColor('Event');
497
+ }
498
+ else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.PIPELINE) {
499
+ str += output_1.default.getTermKitMutedColor('Pipeline');
500
+ }
501
+ else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.WEBHOOK) {
502
+ str += output_1.default.getTermKitMutedColor('Webhook');
503
+ }
504
+ else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EMAIL) {
505
+ str += output_1.default.getTermKitMutedColor('Email');
506
+ }
507
+ else {
508
+ str += run.trigger;
509
+ }
510
+ if (run?.priority === pipeline_1.PIPELINE_PRIORITY.HIGH) {
511
+ str += output_1.default.getTermKitMutedColor(', High');
512
+ }
513
+ else if (run?.priority === pipeline_1.PIPELINE_PRIORITY.LOW) {
514
+ str += output_1.default.getTermKitMutedColor(', Low');
515
+ }
516
+ if (run?.refresh) {
517
+ str += output_1.default.getTermKitMutedColor(', From scratch');
518
+ }
519
+ if (run?.clearCache) {
520
+ str += output_1.default.getTermKitMutedColor(', Clear cache');
521
+ }
522
+ return str;
523
+ }
524
+ static _runDetailsDescription(run, tabs) {
525
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Description', tabs))}`;
526
+ str += output_1.default.getTermKitMutedColor(run?.description || '');
527
+ return str;
528
+ }
529
+ static _statusAnimationIndex = 0;
530
+ static _statusAnimationTs;
531
+ static _statusAnimationString() {
532
+ const opts = pipeline_1.PIPELINE_STATUS_PROGRESS_ANIMATION;
533
+ if (!this._statusAnimationTs) {
534
+ this._statusAnimationTs = setInterval(() => {
535
+ this._statusAnimationIndex += 1;
536
+ if (this._statusAnimationIndex > opts.length - 1)
537
+ this._statusAnimationIndex = 0;
538
+ }, 100);
539
+ }
540
+ return opts[this._statusAnimationIndex];
541
+ }
542
+ static _runHtmlUrl(htmlUrl, tabs) {
543
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('URL', tabs))}`;
544
+ str += output_1.default.getTermKitMutedColor(htmlUrl);
545
+ return str;
546
+ }
547
+ static _runDetailsId(id, tabs) {
548
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('ID', tabs))}`;
549
+ str += output_1.default.getTermKitMutedColor(String(id));
550
+ return str;
551
+ }
552
+ static runStatusText(status) {
553
+ if (status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
554
+ return 'Created';
555
+ }
556
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
557
+ return 'Running';
558
+ }
559
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
560
+ return 'Queued';
561
+ }
562
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
563
+ return 'Canceled';
564
+ }
565
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
566
+ return 'Passed';
567
+ }
568
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
569
+ return 'Failed';
570
+ }
571
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
572
+ return 'Created';
573
+ }
574
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
575
+ return 'Skipped';
576
+ }
577
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
578
+ return 'Canceling';
579
+ }
580
+ else if ([
581
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
582
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
583
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
584
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
585
+ ].includes(status)) {
586
+ return 'Awaiting';
587
+ }
588
+ else {
589
+ return status;
590
+ }
591
+ }
592
+ static _runDetailsStatus(status, started, finished, tabs) {
593
+ let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Status', tabs))}`;
594
+ let ts = false;
595
+ const txt = this.runStatusText(status);
596
+ if (status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
597
+ str += output_1.default.getTermKitDimColor(txt);
598
+ }
599
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
600
+ str += output_1.default.getTermKitBlueColor(txt);
601
+ ts = true;
602
+ }
603
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
604
+ str += output_1.default.getTermKitDimColor(txt);
605
+ }
606
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
607
+ str += output_1.default.getTermKitRedColor(txt);
608
+ ts = true;
609
+ }
610
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
611
+ str += output_1.default.getTermKitGreenColor(txt);
612
+ ts = true;
613
+ }
614
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
615
+ str += output_1.default.getTermKitRedColor(txt);
616
+ ts = true;
617
+ }
618
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
619
+ str += output_1.default.getTermKitDimColor(txt);
620
+ }
621
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
622
+ str += output_1.default.getTermKitDimColor(txt);
623
+ }
624
+ else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
625
+ str += output_1.default.getTermKitBlueColor(txt);
626
+ ts = true;
627
+ }
628
+ else if ([
629
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
630
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
631
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
632
+ pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
633
+ ].includes(status)) {
634
+ str += output_1.default.getTermKitPurpleColor(txt);
635
+ }
636
+ else {
637
+ str += output_1.default.getTermKitMutedColor(status);
638
+ }
639
+ if (ts && started) {
640
+ str += ` ${output_1.default.getTermKitDimColor(this._formatTimespan(started, finished))}`;
641
+ }
642
+ return str;
643
+ }
644
+ static _runInteractiveHelp(run) {
645
+ let help = output_1.default.getTermKitLabelColor('↑↓');
646
+ help += output_1.default.getTermKitDimColor(' navigate •');
647
+ help += output_1.default.getTermKitLabelColor(' ⏎');
648
+ help += output_1.default.getTermKitDimColor(' view logs •');
649
+ if (this._canCancel(run.status)) {
650
+ help += output_1.default.getTermKitLabelColor(' c');
651
+ help += output_1.default.getTermKitDimColor(' cancel •');
652
+ }
653
+ if (this._canRetry(run.status)) {
654
+ help += output_1.default.getTermKitLabelColor(' r');
655
+ help += output_1.default.getTermKitDimColor(' retry •');
656
+ }
657
+ if (this._canApprove(run.status)) {
658
+ help += output_1.default.getTermKitLabelColor(' a');
659
+ help += output_1.default.getTermKitDimColor(' approve •');
660
+ }
661
+ help += output_1.default.getTermKitLabelColor(' esc');
662
+ help += output_1.default.getTermKitDimColor(' exit');
663
+ return help;
664
+ }
665
+ static _actionInteractiveHelp(action) {
666
+ let help = output_1.default.getTermKitLabelColor('↑↓|⇞⇟|↖↘');
667
+ help += output_1.default.getTermKitDimColor(' navigate •');
668
+ if (this._canCancel(action.status)) {
669
+ help += output_1.default.getTermKitLabelColor(' c');
670
+ help += output_1.default.getTermKitDimColor(' cancel •');
671
+ }
672
+ if (this._canRetry(action.status)) {
673
+ help += output_1.default.getTermKitLabelColor(' r');
674
+ help += output_1.default.getTermKitDimColor(' retry •');
675
+ }
676
+ if (this._canApprove(action.status)) {
677
+ help += output_1.default.getTermKitLabelColor(' a');
678
+ help += output_1.default.getTermKitDimColor(' approve •');
679
+ }
680
+ help += output_1.default.getTermKitLabelColor(' esc');
681
+ help += output_1.default.getTermKitDimColor(' exit');
682
+ return help;
683
+ }
684
+ static _drawInteractiveAction(action, actionLogs, put, blank, opts) {
685
+ const fullActionLogs = [...actionLogs.map((str) => ` ${str}`)];
686
+ if (action?.outputtedVariables.length) {
687
+ if (actionLogs.length > 0)
688
+ fullActionLogs.push('');
689
+ fullActionLogs.push(this._runOutputHeader());
690
+ action.outputtedVariables.forEach((v, i) => {
691
+ let line = ' ';
692
+ if (i <= 0)
693
+ line += 'Variables ';
694
+ else
695
+ line += ' ';
696
+ line += output_1.default.getTermKitMutedColor(v.key);
697
+ line += ' = "';
698
+ line += output_1.default.getTermKitBlueColor(v.value);
699
+ line += '"';
700
+ fullActionLogs.push(line);
701
+ });
702
+ }
703
+ const tabs = 25;
704
+ if (action) {
705
+ put(this._runDetailsHeader());
706
+ put(this._runDetailsId(action.id, tabs));
707
+ put(this._runHtmlUrl(action.url, tabs));
708
+ put(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
709
+ const target = this._runActionTarget(action, tabs);
710
+ if (target) {
711
+ put(target);
712
+ }
713
+ const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
714
+ if (loop) {
715
+ put(loop);
716
+ }
717
+ const started = this._runDetailsStarted(action.status, action.started, null, tabs);
718
+ if (started) {
719
+ put(started);
720
+ }
721
+ const finished = this._runDetailsFinished(action.status, action.finished, tabs);
722
+ if (finished) {
723
+ put(finished);
724
+ }
725
+ blank();
726
+ const y = put(this._runLogsHeader());
727
+ let logsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 3;
728
+ if (logsLimit < 2)
729
+ logsLimit = 2;
730
+ if (opts.actionLogsScroll > fullActionLogs.length - logsLimit) {
731
+ opts.actionLogsScroll = fullActionLogs.length - logsLimit;
732
+ }
733
+ if (opts.actionLogsScroll < 0) {
734
+ opts.actionLogsScroll = 0;
735
+ }
736
+ const logs = this._actionLogs(fullActionLogs, opts.actionLogsScroll, logsLimit);
737
+ logs.forEach((str) => {
738
+ put(str);
739
+ });
740
+ blank();
741
+ put(this._actionInteractiveHelp(action));
742
+ }
743
+ }
744
+ static _drawInteractiveRun(run, put, blank, getY, opts) {
745
+ const tabs = 40;
746
+ if (run) {
747
+ put(this._runDetailsHeader());
748
+ put(this._runDetailsId(run.id, tabs));
749
+ put(this._runHtmlUrl(run.url, tabs));
750
+ put(this._runDetailsStatus(run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL, run.started, run.finished, tabs));
751
+ put(this._runDetailsTriggerer(run, tabs));
752
+ if (run.description) {
753
+ put(this._runDetailsDescription(run, tabs));
754
+ }
755
+ const started = this._runDetailsStarted(run.status, run.started, run.delayed, tabs);
756
+ if (started) {
757
+ put(started);
758
+ }
759
+ const finished = this._runDetailsFinished(run.status, run.finished, tabs);
760
+ if (finished) {
761
+ put(finished);
762
+ }
763
+ const context = this._runContext(run, tabs);
764
+ if (context.length > 0) {
765
+ blank();
766
+ context.forEach((str) => {
767
+ put(str);
768
+ });
769
+ }
770
+ const y = getY();
771
+ let actionsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 5;
772
+ if (actionsLimit < 2)
773
+ actionsLimit = 2;
774
+ if (opts.selectedActionIndex >= (run?.actions.length || actionsLimit)) {
775
+ opts.selectedActionIndex = run.actions.length - 1;
776
+ }
777
+ const actions = this._runActions(run, false, actionsLimit, opts.selectedActionIndex, tabs);
778
+ if (actions.length > 0) {
779
+ blank();
780
+ actions.forEach((str) => {
781
+ put(str);
782
+ });
783
+ }
784
+ blank();
785
+ put(this._runInteractiveHelp(run));
786
+ }
787
+ }
788
+ static async _approveRun(client, workspace, project, pipelineId, runId, action, forceFetch) {
789
+ await client.pipelineRunApply(workspace, project, pipelineId, runId, {
790
+ operation: 'APPLY',
791
+ approve_action_id: action.id,
792
+ });
793
+ if (forceFetch)
794
+ setTimeout(forceFetch, 100);
795
+ }
796
+ static async _retryRun(client, workspace, project, pipelineId, runId, forceFetch) {
797
+ try {
798
+ await client.pipelineRunRetry(workspace, project, pipelineId, runId);
799
+ if (forceFetch)
800
+ setTimeout(forceFetch, 100);
801
+ }
802
+ catch (err) {
803
+ if (err.message !== 'Unable to update/delete pipeline in progress') {
804
+ throw err;
805
+ }
806
+ }
807
+ }
808
+ static async _cancelRun(client, workspace, project, pipelineId, runId, forceFetch) {
809
+ try {
810
+ await client.pipelineRunCancel(workspace, project, pipelineId, runId);
811
+ if (forceFetch)
812
+ setTimeout(forceFetch, 100);
813
+ }
814
+ catch (err) {
815
+ if (err.message !== 'Unable to cancel pipeline execution') {
816
+ throw err;
817
+ }
818
+ }
819
+ }
820
+ static async _runLogsInteractive(client, workspace, project, pipelineId, runId, runActionId) {
821
+ let action = null;
822
+ let forceFetchAction = () => { };
823
+ let actionLogs = [];
824
+ const opts = {
825
+ actionLogsScroll: 0,
826
+ };
827
+ let draw = () => { };
828
+ const { put, apply, reset, blank } = output_1.default.createScreenBuffer((name) => {
829
+ let logsPage = termkit_no_lazy_require_1.default.terminal.height - 15;
830
+ if (logsPage <= 0)
831
+ logsPage = 1;
832
+ if (name === 'CTRL_C') {
833
+ return true;
834
+ }
835
+ else if (name === 'ESCAPE') {
836
+ return true;
837
+ }
838
+ else if (name === 'DOWN') {
839
+ opts.actionLogsScroll -= 1;
840
+ if (opts.actionLogsScroll < 0)
841
+ opts.actionLogsScroll = 0;
842
+ draw();
843
+ }
844
+ else if (name === 'UP') {
845
+ opts.actionLogsScroll += 1;
846
+ draw();
847
+ }
848
+ else if (name === 'PAGE_UP') {
849
+ opts.actionLogsScroll += logsPage;
850
+ draw();
851
+ }
852
+ else if (name === 'PAGE_DOWN') {
853
+ opts.actionLogsScroll -= logsPage;
854
+ if (opts.actionLogsScroll < 0)
855
+ opts.actionLogsScroll = 0;
856
+ draw();
857
+ }
858
+ else if (name === 'HOME') {
859
+ opts.actionLogsScroll = actionLogs.length;
860
+ draw();
861
+ }
862
+ else if (name === 'END') {
863
+ opts.actionLogsScroll = 0;
864
+ draw();
865
+ }
866
+ else if (action &&
867
+ name.toLowerCase() === 'c' &&
868
+ this._canCancel(action.status)) {
869
+ this._cancelRun(client, workspace, project, pipelineId, runId, forceFetchAction)
870
+ .then()
871
+ .catch((err) => output_1.default.exitError(err));
872
+ }
873
+ else if (action &&
874
+ name.toLowerCase() === 'r' &&
875
+ this._canRetry(action.status)) {
876
+ this._retryRun(client, workspace, project, pipelineId, runId, forceFetchAction)
877
+ .then()
878
+ .catch((err) => output_1.default.exitError(err));
879
+ }
880
+ else if (action &&
881
+ name.toLowerCase() === 'a' &&
882
+ this._canApprove(action.status)) {
883
+ this._approveRun(client, workspace, project, pipelineId, runId, action, forceFetchAction)
884
+ .then()
885
+ .catch((err) => output_1.default.exitError(err));
886
+ }
887
+ return false;
888
+ }, () => {
889
+ draw();
890
+ });
891
+ draw = () => {
892
+ reset();
893
+ this._drawInteractiveAction(action, actionLogs, put, blank, opts);
894
+ apply();
895
+ };
896
+ setInterval(() => draw(), 100);
897
+ draw();
898
+ this._actionLogsLoop(client, workspace, project, pipelineId, runId, runActionId, (logs) => {
899
+ actionLogs = logs;
900
+ draw();
901
+ })
902
+ .then()
903
+ .catch((err) => output_1.default.exitError(err));
904
+ await this._actionStatusLoop(client, workspace, project, pipelineId, runId, runActionId, (a, _, ffa) => {
905
+ action = a;
906
+ forceFetchAction = ffa;
907
+ draw();
908
+ }, true);
909
+ }
910
+ static async _runStatusInteractive(client, workspace, project, pipelineId, runId) {
911
+ let mode = MODE.RUN;
912
+ let run = null;
913
+ let forceFetchRun = null;
914
+ let action = null;
915
+ let actionLogs = [];
916
+ let cancelActionFetch = () => { };
917
+ let forceActionFetch = () => { };
918
+ let cancelActionLogs = () => { };
919
+ let selectedActionId = null;
920
+ const opts = {
921
+ selectedActionIndex: -1,
922
+ actionLogsScroll: 0,
923
+ };
924
+ let draw = () => { };
925
+ const { put, apply, reset, blank, getY } = output_1.default.createScreenBuffer((name) => {
926
+ let logsPage = termkit_no_lazy_require_1.default.terminal.height - 15;
927
+ if (logsPage <= 0)
928
+ logsPage = 1;
929
+ if (name === 'CTRL_C') {
930
+ return true;
931
+ }
932
+ else if (name === 'ESCAPE') {
933
+ if (mode === MODE.RUN) {
934
+ return true;
935
+ }
936
+ else {
937
+ selectedActionId = null;
938
+ action = null;
939
+ actionLogs = [];
940
+ opts.actionLogsScroll = 0;
941
+ cancelActionFetch();
942
+ cancelActionLogs();
943
+ forceActionFetch = () => { };
944
+ cancelActionFetch = () => { };
945
+ cancelActionLogs = () => { };
946
+ mode = MODE.RUN;
947
+ draw();
948
+ }
949
+ }
950
+ else if (name === 'DOWN') {
951
+ if (mode === MODE.RUN) {
952
+ opts.selectedActionIndex += 1;
953
+ draw();
954
+ }
955
+ else {
956
+ opts.actionLogsScroll -= 1;
957
+ if (opts.actionLogsScroll < 0)
958
+ opts.actionLogsScroll = 0;
959
+ draw();
960
+ }
961
+ }
962
+ else if (name === 'UP') {
963
+ if (mode === MODE.RUN) {
964
+ opts.selectedActionIndex -= 1;
965
+ if (opts.selectedActionIndex < 0)
966
+ opts.selectedActionIndex = -1;
967
+ draw();
968
+ }
969
+ else {
970
+ opts.actionLogsScroll += 1;
971
+ draw();
972
+ }
973
+ }
974
+ else if (name === 'PAGE_UP') {
975
+ if (mode === MODE.ACTION) {
976
+ opts.actionLogsScroll += logsPage;
977
+ draw();
978
+ }
979
+ }
980
+ else if (name === 'PAGE_DOWN') {
981
+ if (mode === MODE.ACTION) {
982
+ opts.actionLogsScroll -= logsPage;
983
+ if (opts.actionLogsScroll < 0)
984
+ opts.actionLogsScroll = 0;
985
+ draw();
986
+ }
987
+ }
988
+ else if (name === 'HOME') {
989
+ if (mode === MODE.ACTION) {
990
+ opts.actionLogsScroll = actionLogs.length;
991
+ draw();
992
+ }
993
+ }
994
+ else if (name === 'END') {
995
+ if (mode === MODE.ACTION) {
996
+ opts.actionLogsScroll = 0;
997
+ draw();
998
+ }
999
+ }
1000
+ else if (name === 'ENTER') {
1001
+ if (mode === MODE.RUN &&
1002
+ run &&
1003
+ run.actions[opts.selectedActionIndex]) {
1004
+ selectedActionId = run.actions[opts.selectedActionIndex].id;
1005
+ mode = MODE.ACTION;
1006
+ this._actionLogsLoop(client, workspace, project, pipelineId, runId, selectedActionId, (logs, cancel) => {
1007
+ cancelActionLogs = cancel;
1008
+ actionLogs = logs;
1009
+ draw();
1010
+ });
1011
+ this._actionStatusLoop(client, workspace, project, pipelineId, runId, selectedActionId, (a, cancel, ffa) => {
1012
+ if (cancel)
1013
+ cancelActionFetch = cancel;
1014
+ if (a && selectedActionId === a.id)
1015
+ action = a;
1016
+ if (ffa)
1017
+ forceActionFetch = ffa;
1018
+ draw();
1019
+ }, true);
1020
+ draw();
1021
+ }
1022
+ }
1023
+ else if (run &&
1024
+ name.toLowerCase() === 'c' &&
1025
+ this._canCancel(run.status)) {
1026
+ this._cancelRun(client, workspace, project, pipelineId, runId, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1027
+ .then()
1028
+ .catch((err) => output_1.default.exitError(err));
1029
+ }
1030
+ else if (run &&
1031
+ name.toLowerCase() === 'r' &&
1032
+ this._canRetry(run.status)) {
1033
+ this._retryRun(client, workspace, project, pipelineId, runId, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1034
+ .then()
1035
+ .catch((err) => output_1.default.exitError(err));
1036
+ }
1037
+ else if (run &&
1038
+ name.toLowerCase() === 'a' &&
1039
+ this._canApprove(run.status)) {
1040
+ let a = null;
1041
+ if (mode === MODE.ACTION) {
1042
+ a = action;
1043
+ }
1044
+ else if (mode === MODE.RUN) {
1045
+ if (run.actions[opts.selectedActionIndex]) {
1046
+ a = run.actions[opts.selectedActionIndex];
1047
+ }
1048
+ if (!a || !this._canApprove(a.status)) {
1049
+ a = run.actions.find((a) => this._canApprove(a.status));
1050
+ }
1051
+ }
1052
+ if (a && this._canApprove(a.status)) {
1053
+ this._approveRun(client, workspace, project, pipelineId, runId, a, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1054
+ .then()
1055
+ .catch((err) => output_1.default.exitError(err));
1056
+ }
1057
+ }
1058
+ return false;
1059
+ }, () => {
1060
+ draw();
1061
+ });
1062
+ draw = () => {
1063
+ reset();
1064
+ if (mode === MODE.RUN) {
1065
+ this._drawInteractiveRun(run, put, blank, getY, opts);
1066
+ }
1067
+ else {
1068
+ this._drawInteractiveAction(action, actionLogs, put, blank, opts);
1069
+ }
1070
+ apply();
1071
+ };
1072
+ setInterval(() => draw(), 100);
1073
+ draw();
1074
+ await this._runStatusLoop(client, workspace, project, pipelineId, runId, (r, ffr) => {
1075
+ run = r;
1076
+ forceFetchRun = ffr;
1077
+ draw();
1078
+ }, true);
1079
+ }
1080
+ static _exitByStatus(status) {
1081
+ if (status && [pipeline_1.PIPELINE_RUN_STATUS.FAILED, pipeline_1.PIPELINE_RUN_STATUS.TERMINATED].includes(status)) {
1082
+ process.exit(1);
1083
+ }
1084
+ else {
1085
+ process.exit(0);
1086
+ }
1087
+ }
1088
+ static async _runLogsNonInteractive(client, workspace, project, pipelineId, runId, runActionId, noWait) {
1089
+ let action = null;
1090
+ let actionLogsStart = 0;
1091
+ let lastActionLogsStart = -1;
1092
+ let drawnStart = false;
1093
+ let logsEnd = false;
1094
+ let totalFetchesCount = 0;
1095
+ const tabs = 40;
1096
+ const draw = (logs) => {
1097
+ if (!drawnStart && action) {
1098
+ output_1.default.normal(this._runDetailsHeader());
1099
+ output_1.default.normal(this._runDetailsId(action.id, tabs));
1100
+ output_1.default.normal(this._runHtmlUrl(action.url, tabs));
1101
+ output_1.default.normal(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
1102
+ const target = this._runActionTarget(action, tabs);
1103
+ if (target) {
1104
+ output_1.default.normal(target);
1105
+ }
1106
+ const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
1107
+ if (loop) {
1108
+ output_1.default.normal(loop);
1109
+ }
1110
+ const started = this._runDetailsStarted(action.status, action.started, null, tabs);
1111
+ if (started) {
1112
+ output_1.default.normal(started);
1113
+ }
1114
+ const finished = this._runDetailsFinished(action.status, action.finished, tabs);
1115
+ if (finished) {
1116
+ output_1.default.normal(finished);
1117
+ }
1118
+ output_1.default.normal('');
1119
+ output_1.default.normal(this._runLogsHeader());
1120
+ drawnStart = true;
1121
+ }
1122
+ if (drawnStart && logs && !logsEnd) {
1123
+ for (; actionLogsStart < logs.length; actionLogsStart += 1) {
1124
+ output_1.default.normal(output_1.default.getTermKitDimColor(` ${logs[actionLogsStart]}`));
1125
+ }
1126
+ if (action &&
1127
+ [
1128
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1129
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1130
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1131
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1132
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1133
+ ].includes(action.status) &&
1134
+ (actionLogsStart === lastActionLogsStart || logs.length < LOGS_LIMIT)) {
1135
+ logsEnd = true;
1136
+ }
1137
+ lastActionLogsStart = actionLogsStart;
1138
+ }
1139
+ if (logsEnd || (drawnStart && noWait && logs)) {
1140
+ if (logsEnd && action?.outputtedVariables.length) {
1141
+ output_1.default.normal('');
1142
+ output_1.default.normal(this._runOutputHeader());
1143
+ output_1.default.normal(output_1.default.getTermKitDimColor(' Variables '), false);
1144
+ action.outputtedVariables.forEach((v, i) => {
1145
+ let line = '';
1146
+ if (i > 0)
1147
+ line += ' ';
1148
+ line += output_1.default.getTermKitMutedColor(v.key);
1149
+ line += output_1.default.getTermKitDimColor(` = "`);
1150
+ line += output_1.default.getTermKitBlueColor(v.value);
1151
+ line += output_1.default.getTermKitDimColor('"');
1152
+ output_1.default.normal(line);
1153
+ });
1154
+ }
1155
+ if (logsEnd && action && totalFetchesCount > 1) {
1156
+ output_1.default.normal('');
1157
+ output_1.default.normal(this._runDetailsHeader());
1158
+ output_1.default.normal(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
1159
+ const target = this._runActionTarget(action, tabs);
1160
+ if (target) {
1161
+ output_1.default.normal(target);
1162
+ }
1163
+ const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
1164
+ if (loop) {
1165
+ output_1.default.normal(loop);
1166
+ }
1167
+ const started = this._runDetailsStarted(action.status, action.started, null, tabs);
1168
+ if (started) {
1169
+ output_1.default.normal(started);
1170
+ }
1171
+ const finished = this._runDetailsFinished(action.status, action.finished, tabs);
1172
+ if (finished) {
1173
+ output_1.default.normal(finished);
1174
+ }
1175
+ }
1176
+ this._exitByStatus(action?.status);
1177
+ }
1178
+ };
1179
+ this._actionLogsLoop(client, workspace, project, pipelineId, runId, runActionId, draw)
1180
+ .then()
1181
+ .catch((err) => output_1.default.exitError(err));
1182
+ await this._actionStatusLoop(client, workspace, project, pipelineId, runId, runActionId, (a) => {
1183
+ if (a) {
1184
+ action = a;
1185
+ totalFetchesCount += 1;
1186
+ draw();
1187
+ }
1188
+ });
1189
+ }
1190
+ static async _runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait) {
1191
+ let run = null;
1192
+ let totalFetchesCount = 0;
1193
+ const tabs = 40;
1194
+ const draw = (r) => {
1195
+ if (!run) {
1196
+ output_1.default.normal(this._runDetailsHeader());
1197
+ output_1.default.normal(this._runDetailsId(r.id, tabs));
1198
+ output_1.default.normal(this._runHtmlUrl(r.url, tabs));
1199
+ output_1.default.normal(this._runDetailsStatus(r.status, r.started, r.finished, tabs));
1200
+ output_1.default.normal(this._runDetailsTriggerer(r, tabs));
1201
+ if (r?.description)
1202
+ output_1.default.normal(this._runDetailsDescription(r, tabs));
1203
+ const started = this._runDetailsStarted(r.status, r.started, r.delayed, tabs);
1204
+ if (started)
1205
+ output_1.default.normal(started);
1206
+ const finished = this._runDetailsFinished(r.status, r.finished, tabs);
1207
+ if (finished)
1208
+ output_1.default.normal(finished);
1209
+ const context = this._runContext(r, tabs);
1210
+ if (context.length > 0) {
1211
+ output_1.default.normal('');
1212
+ context.forEach((str) => {
1213
+ output_1.default.normal(str);
1214
+ });
1215
+ }
1216
+ output_1.default.normal('');
1217
+ output_1.default.normal(this._runActionsHeader(tabs));
1218
+ }
1219
+ const actions = this._runActions(r, true, 0, -1, tabs);
1220
+ actions.forEach((str) => {
1221
+ output_1.default.normal(str);
1222
+ });
1223
+ run = r;
1224
+ };
1225
+ run = await this._runStatusLoop(client, workspace, project, pipelineId, runId, (run) => {
1226
+ totalFetchesCount += 1;
1227
+ draw(run);
1228
+ if (noWait) {
1229
+ this._exitByStatus(run.status);
1230
+ }
1231
+ });
1232
+ if (totalFetchesCount > 1) {
1233
+ output_1.default.normal('');
1234
+ output_1.default.normal(this._runDetailsHeader());
1235
+ output_1.default.normal(this._runDetailsStatus(run.status, run.started, run.finished, tabs));
1236
+ const started = this._runDetailsStarted(run.status, run.started, run.delayed, tabs);
1237
+ if (started)
1238
+ output_1.default.normal(started);
1239
+ const finished = this._runDetailsFinished(run.status, run.finished, tabs);
1240
+ if (finished)
1241
+ output_1.default.normal(finished);
1242
+ }
1243
+ output_1.default.normal(this._dimLine());
1244
+ output_1.default.normal(this._runActionsLogsHelp(identifier, runId));
1245
+ this._exitByStatus(run.status);
1246
+ }
1247
+ static async _actionLogsLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange) {
1248
+ let logs = [];
1249
+ let offset = 0;
1250
+ let shouldCancel = false;
1251
+ const cancel = () => {
1252
+ shouldCancel = true;
1253
+ };
1254
+ onChange(logs, cancel);
1255
+ const fetchLogs = async () => {
1256
+ return await client.getPipelineRunActionLogs(workspace, project, pipelineId, runId, actionExecutionId, offset, LOGS_LIMIT);
1257
+ };
1258
+ for (;;) {
1259
+ let o = await fetchLogs();
1260
+ if (o.total_element_count < offset) {
1261
+ logs = [];
1262
+ offset = 0;
1263
+ o = await fetchLogs();
1264
+ }
1265
+ offset = o.offset + o.element_count;
1266
+ logs.push(...o.logs);
1267
+ if (shouldCancel)
1268
+ return;
1269
+ onChange(logs, cancel);
1270
+ if (o.logs.length > 0)
1271
+ continue;
1272
+ await (0, utils_1.sleep)(3000);
1273
+ }
1274
+ }
1275
+ static async _actionStatusLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange, dontExit = false) {
1276
+ const fetchAction = async () => {
1277
+ return await client.getPipelineRunActionExecution(workspace, project, pipelineId, runId, actionExecutionId);
1278
+ };
1279
+ let status = pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1280
+ let oldStatus = null;
1281
+ let shouldCancel = false;
1282
+ const cancel = () => {
1283
+ shouldCancel = true;
1284
+ };
1285
+ const forceFetchAction = async () => {
1286
+ const a = await fetchAction();
1287
+ let started = null;
1288
+ if (a.start_date)
1289
+ started = new Date(a.start_date);
1290
+ let finished = null;
1291
+ if (a.finish_date)
1292
+ finished = new Date(a.finish_date);
1293
+ status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1294
+ const name = a.action?.name || '';
1295
+ const actionId = a.action?.id || -1;
1296
+ const url = a.html_url || '';
1297
+ const originalType = a.action?.type || pipeline_1.PIPELINE_ACTION_TYPE.BUILD;
1298
+ let type = originalType;
1299
+ if (pipeline_1.PIPELINE_ACTION_NAME[originalType]) {
1300
+ type = pipeline_1.PIPELINE_ACTION_NAME[originalType];
1301
+ }
1302
+ let target = null;
1303
+ if (a.target)
1304
+ target = a.target;
1305
+ let outputtedVariables = [];
1306
+ if (a.outputted_variables) {
1307
+ outputtedVariables = [];
1308
+ a.outputted_variables.forEach((v) => {
1309
+ outputtedVariables.push({
1310
+ key: String(v.key),
1311
+ value: String(v.value),
1312
+ });
1313
+ });
1314
+ }
1315
+ let loop = LOOP_STATUS.DISABLED;
1316
+ let loopValues = [];
1317
+ if (a.loop_details) {
1318
+ loop = a.loop_details.status;
1319
+ if (a.loop_details.resolved_variables) {
1320
+ loopValues = [];
1321
+ a.loop_details.resolved_variables.forEach((v) => {
1322
+ if (v.value)
1323
+ loopValues.push({
1324
+ key: String(v.key),
1325
+ value: String(v.value),
1326
+ });
1327
+ });
1328
+ }
1329
+ }
1330
+ const changed = !oldStatus || status !== oldStatus;
1331
+ const action = {
1332
+ id: actionExecutionId,
1333
+ actionId,
1334
+ url,
1335
+ status,
1336
+ target,
1337
+ loop,
1338
+ loopValues,
1339
+ outputtedVariables,
1340
+ started,
1341
+ finished,
1342
+ name,
1343
+ type,
1344
+ changed,
1345
+ };
1346
+ onChange(action, cancel, forceFetchAction);
1347
+ return action;
1348
+ };
1349
+ await forceFetchAction();
1350
+ for (;;) {
1351
+ await (0, utils_1.sleep)(3000);
1352
+ if (shouldCancel)
1353
+ return;
1354
+ await forceFetchAction();
1355
+ oldStatus = status;
1356
+ if (!dontExit &&
1357
+ [
1358
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1359
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1360
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1361
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1362
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1363
+ ].includes(status)) {
1364
+ cancel();
1365
+ }
1366
+ if (shouldCancel)
1367
+ return;
1368
+ }
1369
+ }
1370
+ static async _runStatusLoop(client, workspace, project, pipelineId, runId, onChange, dontExit = false) {
1371
+ let lastRun;
1372
+ const fetchRun = async () => {
1373
+ return await client.getPipelineRun(workspace, project, pipelineId, runId);
1374
+ };
1375
+ const id = runId;
1376
+ let url;
1377
+ let status;
1378
+ let started;
1379
+ let finished = null;
1380
+ let delayed = null;
1381
+ let trigger;
1382
+ let creator = 'Unknown';
1383
+ let description = '';
1384
+ let refresh = false;
1385
+ let clearCache = false;
1386
+ let priority = pipeline_1.PIPELINE_PRIORITY.NORMAL;
1387
+ let context = null;
1388
+ let actions = [];
1389
+ const forceFetchRun = async () => {
1390
+ const run = await fetchRun();
1391
+ started = new Date(run.start_date || new Date());
1392
+ trigger = run.triggered_on || pipeline_1.PIPELINE_RUN_TRIGGER.CLICK;
1393
+ status = run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1394
+ url = run.html_url;
1395
+ if (run.creator) {
1396
+ if (run.creator.name)
1397
+ creator = run.creator.name;
1398
+ else if (run.creator.email)
1399
+ creator = run.creator.email;
1400
+ }
1401
+ if (run.finish_date)
1402
+ finished = new Date(run.finish_date);
1403
+ if (run.comment)
1404
+ description = run.comment;
1405
+ if (run.priority)
1406
+ priority = run.priority;
1407
+ if (run.delay_until)
1408
+ delayed = new Date(run.delay_until);
1409
+ if (run.refresh)
1410
+ refresh = true;
1411
+ if (run.clear_cache)
1412
+ clearCache = true;
1413
+ if (run.branch) {
1414
+ if (!context)
1415
+ context = {};
1416
+ context['Branch'] = run.branch.name;
1417
+ }
1418
+ if (run.tag) {
1419
+ if (!context)
1420
+ context = {};
1421
+ context['Tag'] = run.tag.name;
1422
+ }
1423
+ if (run.pull_request) {
1424
+ if (!context)
1425
+ context = {};
1426
+ context['Pull request'] = run.pull_request.name;
1427
+ }
1428
+ if (run.to_revision) {
1429
+ if (!context)
1430
+ context = {};
1431
+ context['Revision'] = `#${run.to_revision.revision.substring(0, 7)}`;
1432
+ if (run.to_revision.message)
1433
+ context['Revision'] += `: ${run.to_revision.message}`;
1434
+ }
1435
+ if (run.environment) {
1436
+ if (!context)
1437
+ context = {};
1438
+ context['Environment'] = run.environment.identifier;
1439
+ }
1440
+ if (run.package && run.package_version) {
1441
+ if (!context)
1442
+ context = {};
1443
+ context['Package'] =
1444
+ `${run.package.identifier}:${run.package_version.version}`;
1445
+ }
1446
+ if (run.loop_details) {
1447
+ if (!context)
1448
+ context = {};
1449
+ context['Loop'] = this._runLoopText(run.loop_details.status, run.loop_details.resolved_variables || []);
1450
+ }
1451
+ if (run.action_executions) {
1452
+ const old = actions;
1453
+ actions = (run.action_executions || []).map((a) => {
1454
+ const originalType = a.action?.type ||
1455
+ pipeline_1.PIPELINE_ACTION_TYPE.BUILD;
1456
+ let type = originalType;
1457
+ if (pipeline_1.PIPELINE_ACTION_NAME[originalType]) {
1458
+ type = pipeline_1.PIPELINE_ACTION_NAME[originalType];
1459
+ }
1460
+ const name = a.action?.name || '';
1461
+ const id = a.action_execution_id;
1462
+ const url = a.html_url;
1463
+ const actionId = a.action?.id || -1;
1464
+ const status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1465
+ let target = null;
1466
+ let loop = LOOP_STATUS.DISABLED;
1467
+ const loopValues = [];
1468
+ const outputtedVariables = [];
1469
+ if (a.target)
1470
+ target = a.target;
1471
+ if (a.outputted_variables) {
1472
+ a.outputted_variables.forEach((v) => {
1473
+ outputtedVariables.push({
1474
+ key: String(v.key),
1475
+ value: String(v.value),
1476
+ });
1477
+ });
1478
+ }
1479
+ if (a.loop_details) {
1480
+ loop = a.loop_details.status;
1481
+ if (a.loop_details.resolved_variables) {
1482
+ a.loop_details.resolved_variables.forEach((v) => {
1483
+ if (v.value)
1484
+ loopValues.push({
1485
+ key: String(v.key),
1486
+ value: String(v.value),
1487
+ });
1488
+ });
1489
+ }
1490
+ }
1491
+ let started = null;
1492
+ if (a.start_date)
1493
+ started = new Date(a.start_date);
1494
+ let finished = null;
1495
+ if (a.finish_date)
1496
+ finished = new Date(a.finish_date);
1497
+ const oldAction = old.find((o) => o.id === id);
1498
+ const changed = !oldAction || oldAction.status !== status;
1499
+ const action = {
1500
+ type,
1501
+ name,
1502
+ url,
1503
+ loop,
1504
+ loopValues,
1505
+ outputtedVariables,
1506
+ target,
1507
+ actionId,
1508
+ id,
1509
+ status,
1510
+ started,
1511
+ finished,
1512
+ changed,
1513
+ };
1514
+ return action;
1515
+ });
1516
+ actions = actions.filter((a) => {
1517
+ if (a.target)
1518
+ return true;
1519
+ return !actions.find((a2) => {
1520
+ if (a2.id === a.id)
1521
+ return false;
1522
+ if (a2.actionId !== a.actionId)
1523
+ return false;
1524
+ return !!a2.target;
1525
+ });
1526
+ });
1527
+ }
1528
+ const r = {
1529
+ id,
1530
+ creator,
1531
+ description,
1532
+ started,
1533
+ url,
1534
+ status,
1535
+ trigger,
1536
+ finished,
1537
+ clearCache,
1538
+ refresh,
1539
+ priority,
1540
+ delayed,
1541
+ context,
1542
+ actions,
1543
+ };
1544
+ onChange(r, forceFetchRun);
1545
+ return r;
1546
+ };
1547
+ lastRun = await forceFetchRun();
1548
+ for (;;) {
1549
+ if (!dontExit &&
1550
+ [
1551
+ pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1552
+ pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1553
+ pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1554
+ pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1555
+ pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1556
+ ].includes(lastRun.status)) {
1557
+ break;
1558
+ }
1559
+ await (0, utils_1.sleep)(3000);
1560
+ lastRun = await forceFetchRun();
1561
+ }
1562
+ return lastRun;
1563
+ }
1564
+ }
1565
+ exports.default = OutputPipeline;