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