bdy 1.19.3-dev-pipeline → 1.19.3-dev

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 (52) hide show
  1. package/distTs/package.json +2 -2
  2. package/distTs/src/api/client.js +2 -103
  3. package/distTs/src/command/pipeline/run.js +125 -22
  4. package/distTs/src/command/pipeline.js +0 -23
  5. package/distTs/src/command/project/get.js +18 -0
  6. package/distTs/src/command/project/link.js +11 -11
  7. package/distTs/src/command/project/set.js +31 -0
  8. package/distTs/src/command/sandbox/get/yaml.js +30 -0
  9. package/distTs/src/command/vt/scrape.js +193 -0
  10. package/distTs/src/input.js +31 -14
  11. package/distTs/src/output.js +31 -149
  12. package/distTs/src/texts.js +35 -85
  13. package/distTs/src/tunnel/http.js +51 -14
  14. package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
  15. package/distTs/src/tunnel/tcp.js +7 -0
  16. package/package.json +2 -2
  17. package/distTs/src/command/crawl/link.js +0 -61
  18. package/distTs/src/command/crawl/run.js +0 -147
  19. package/distTs/src/command/crawl/validation.js +0 -154
  20. package/distTs/src/command/crawl.js +0 -13
  21. package/distTs/src/command/pipeline/create.js +0 -45
  22. package/distTs/src/command/pipeline/get.js +0 -42
  23. package/distTs/src/command/pipeline/list.js +0 -43
  24. package/distTs/src/command/pipeline/run/apply.js +0 -62
  25. package/distTs/src/command/pipeline/run/approve.js +0 -62
  26. package/distTs/src/command/pipeline/run/cancel.js +0 -36
  27. package/distTs/src/command/pipeline/run/list.js +0 -52
  28. package/distTs/src/command/pipeline/run/logs.js +0 -37
  29. package/distTs/src/command/pipeline/run/retry.js +0 -36
  30. package/distTs/src/command/pipeline/run/start.js +0 -96
  31. package/distTs/src/command/pipeline/run/status.js +0 -35
  32. package/distTs/src/command/pipeline/update.js +0 -41
  33. package/distTs/src/command/pipeline/yaml.js +0 -38
  34. package/distTs/src/command/tests/capture/validation.js +0 -46
  35. package/distTs/src/command/tests/capture.js +0 -103
  36. package/distTs/src/command/tests/unit/link.js +0 -61
  37. package/distTs/src/command/tests/unit/upload.js +0 -91
  38. package/distTs/src/command/tests/unit.js +0 -13
  39. package/distTs/src/command/tests/visual/link.js +0 -61
  40. package/distTs/src/command/tests/visual/session/close.js +0 -32
  41. package/distTs/src/command/tests/visual/session/create.js +0 -86
  42. package/distTs/src/command/tests/visual/session.js +0 -13
  43. package/distTs/src/command/tests/visual/setup.js +0 -20
  44. package/distTs/src/command/tests/visual/shared/validation.js +0 -145
  45. package/distTs/src/command/tests/visual/upload.js +0 -141
  46. package/distTs/src/command/tests/visual.js +0 -17
  47. package/distTs/src/command/tests.js +0 -15
  48. package/distTs/src/crawl/requests.js +0 -141
  49. package/distTs/src/output/pipeline.js +0 -1547
  50. package/distTs/src/types/crawl.js +0 -2
  51. package/distTs/src/types/pipeline.js +0 -424
  52. package/distTs/src/unitTest/context.js +0 -26
@@ -1,1547 +0,0 @@
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, 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, 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 _runDetailsFinished(status, finished, tabs) {
464
- if (finished &&
465
- [
466
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
467
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
468
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
469
- ].includes(status)) {
470
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Finished', tabs))}`;
471
- str += output_1.default.getTermKitMutedColor(this._formatDate(finished));
472
- return str;
473
- }
474
- return null;
475
- }
476
- static _runDetailsTriggerer(run, tabs) {
477
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Trigger', tabs))}`;
478
- if (run?.creator) {
479
- str += `${output_1.default.getTermKitBlueColor(run.creator)} - `;
480
- }
481
- if (!run || run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.CLICK) {
482
- str += output_1.default.getTermKitMutedColor('Manual');
483
- }
484
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.SCHEDULE) {
485
- str += output_1.default.getTermKitMutedColor('Schedule');
486
- }
487
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EVENT) {
488
- str += output_1.default.getTermKitMutedColor('Event');
489
- }
490
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.PIPELINE) {
491
- str += output_1.default.getTermKitMutedColor('Pipeline');
492
- }
493
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.WEBHOOK) {
494
- str += output_1.default.getTermKitMutedColor('Webhook');
495
- }
496
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EMAIL) {
497
- str += output_1.default.getTermKitMutedColor('Email');
498
- }
499
- else {
500
- str += run.trigger;
501
- }
502
- if (run?.priority === pipeline_1.PIPELINE_PRIORITY.HIGH) {
503
- str += output_1.default.getTermKitMutedColor(', High');
504
- }
505
- else if (run?.priority === pipeline_1.PIPELINE_PRIORITY.LOW) {
506
- str += output_1.default.getTermKitMutedColor(', Low');
507
- }
508
- if (run?.refresh) {
509
- str += output_1.default.getTermKitMutedColor(', From scratch');
510
- }
511
- if (run?.clearCache) {
512
- str += output_1.default.getTermKitMutedColor(', Clear cache');
513
- }
514
- return str;
515
- }
516
- static _runDetailsDescription(run, tabs) {
517
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Description', tabs))}`;
518
- str += output_1.default.getTermKitMutedColor(run?.description || '');
519
- return str;
520
- }
521
- static _statusAnimationIndex = 0;
522
- static _statusAnimationTs;
523
- static _statusAnimationString() {
524
- const opts = pipeline_1.PIPELINE_STATUS_PROGRESS_ANIMATION;
525
- if (!this._statusAnimationTs) {
526
- this._statusAnimationTs = setInterval(() => {
527
- this._statusAnimationIndex += 1;
528
- if (this._statusAnimationIndex > opts.length - 1)
529
- this._statusAnimationIndex = 0;
530
- }, 100);
531
- }
532
- return opts[this._statusAnimationIndex];
533
- }
534
- static _runHtmlUrl(htmlUrl, tabs) {
535
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('URL', tabs))}`;
536
- str += output_1.default.getTermKitMutedColor(htmlUrl);
537
- return str;
538
- }
539
- static _runDetailsId(id, tabs) {
540
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('ID', tabs))}`;
541
- str += output_1.default.getTermKitMutedColor(String(id));
542
- return str;
543
- }
544
- static runStatusText(status) {
545
- if (status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
546
- return 'Created';
547
- }
548
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
549
- return 'Running';
550
- }
551
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
552
- return 'Queued';
553
- }
554
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
555
- return 'Canceled';
556
- }
557
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
558
- return 'Passed';
559
- }
560
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
561
- return 'Failed';
562
- }
563
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
564
- return 'Created';
565
- }
566
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
567
- return 'Skipped';
568
- }
569
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
570
- return 'Canceling';
571
- }
572
- else if ([
573
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
574
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
575
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
576
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
577
- ].includes(status)) {
578
- return 'Awaiting';
579
- }
580
- else {
581
- return status;
582
- }
583
- }
584
- static _runDetailsStatus(status, started, finished, tabs) {
585
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Status', tabs))}`;
586
- let ts = false;
587
- const txt = this.runStatusText(status);
588
- if (status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
589
- str += output_1.default.getTermKitDimColor(txt);
590
- }
591
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
592
- str += output_1.default.getTermKitBlueColor(txt);
593
- ts = true;
594
- }
595
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
596
- str += output_1.default.getTermKitDimColor(txt);
597
- }
598
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
599
- str += output_1.default.getTermKitRedColor(txt);
600
- ts = true;
601
- }
602
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
603
- str += output_1.default.getTermKitGreenColor(txt);
604
- ts = true;
605
- }
606
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
607
- str += output_1.default.getTermKitRedColor(txt);
608
- ts = true;
609
- }
610
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
611
- str += output_1.default.getTermKitDimColor(txt);
612
- }
613
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
614
- str += output_1.default.getTermKitDimColor(txt);
615
- }
616
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
617
- str += output_1.default.getTermKitBlueColor(txt);
618
- ts = true;
619
- }
620
- else if ([
621
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
622
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
623
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
624
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
625
- ].includes(status)) {
626
- str += output_1.default.getTermKitPurpleColor(txt);
627
- }
628
- else {
629
- str += output_1.default.getTermKitMutedColor(status);
630
- }
631
- if (ts && started) {
632
- str += ` ${output_1.default.getTermKitDimColor(this._formatTimespan(started, finished))}`;
633
- }
634
- return str;
635
- }
636
- static _runInteractiveHelp(run) {
637
- let help = output_1.default.getTermKitLabelColor('↑↓');
638
- help += output_1.default.getTermKitDimColor(' navigate •');
639
- help += output_1.default.getTermKitLabelColor(' ⏎');
640
- help += output_1.default.getTermKitDimColor(' view logs •');
641
- if (this._canCancel(run.status)) {
642
- help += output_1.default.getTermKitLabelColor(' c');
643
- help += output_1.default.getTermKitDimColor(' cancel •');
644
- }
645
- if (this._canRetry(run.status)) {
646
- help += output_1.default.getTermKitLabelColor(' r');
647
- help += output_1.default.getTermKitDimColor(' retry •');
648
- }
649
- if (this._canApprove(run.status)) {
650
- help += output_1.default.getTermKitLabelColor(' a');
651
- help += output_1.default.getTermKitDimColor(' approve •');
652
- }
653
- help += output_1.default.getTermKitLabelColor(' esc');
654
- help += output_1.default.getTermKitDimColor(' exit');
655
- return help;
656
- }
657
- static _actionInteractiveHelp(action) {
658
- let help = output_1.default.getTermKitLabelColor('↑↓|⇞⇟|↖↘');
659
- help += output_1.default.getTermKitDimColor(' navigate •');
660
- if (this._canCancel(action.status)) {
661
- help += output_1.default.getTermKitLabelColor(' c');
662
- help += output_1.default.getTermKitDimColor(' cancel •');
663
- }
664
- if (this._canRetry(action.status)) {
665
- help += output_1.default.getTermKitLabelColor(' r');
666
- help += output_1.default.getTermKitDimColor(' retry •');
667
- }
668
- if (this._canApprove(action.status)) {
669
- help += output_1.default.getTermKitLabelColor(' a');
670
- help += output_1.default.getTermKitDimColor(' approve •');
671
- }
672
- help += output_1.default.getTermKitLabelColor(' esc');
673
- help += output_1.default.getTermKitDimColor(' exit');
674
- return help;
675
- }
676
- static _drawInteractiveAction(action, actionLogs, put, blank, opts) {
677
- const fullActionLogs = [...actionLogs.map((str) => ` ${str}`)];
678
- if (action?.outputtedVariables.length) {
679
- if (actionLogs.length > 0)
680
- fullActionLogs.push('');
681
- fullActionLogs.push(this._runOutputHeader());
682
- action.outputtedVariables.forEach((v, i) => {
683
- let line = ' ';
684
- if (i <= 0)
685
- line += 'Variables ';
686
- else
687
- line += ' ';
688
- line += output_1.default.getTermKitMutedColor(v.key);
689
- line += ' = "';
690
- line += output_1.default.getTermKitBlueColor(v.value);
691
- line += '"';
692
- fullActionLogs.push(line);
693
- });
694
- }
695
- const tabs = 25;
696
- if (action) {
697
- put(this._runDetailsHeader());
698
- put(this._runDetailsId(action.id, tabs));
699
- put(this._runHtmlUrl(action.url, tabs));
700
- put(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
701
- const target = this._runActionTarget(action, tabs);
702
- if (target) {
703
- put(target);
704
- }
705
- const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
706
- if (loop) {
707
- put(loop);
708
- }
709
- const started = this._runDetailsStarted(action.status, action.started, null, tabs);
710
- if (started) {
711
- put(started);
712
- }
713
- const finished = this._runDetailsFinished(action.status, action.finished, tabs);
714
- if (finished) {
715
- put(finished);
716
- }
717
- blank();
718
- const y = put(this._runLogsHeader());
719
- let logsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 3;
720
- if (logsLimit < 2)
721
- logsLimit = 2;
722
- if (opts.actionLogsScroll > fullActionLogs.length - logsLimit) {
723
- opts.actionLogsScroll = fullActionLogs.length - logsLimit;
724
- }
725
- if (opts.actionLogsScroll < 0) {
726
- opts.actionLogsScroll = 0;
727
- }
728
- const logs = this._actionLogs(fullActionLogs, opts.actionLogsScroll, logsLimit);
729
- logs.forEach((str) => {
730
- put(str);
731
- });
732
- blank();
733
- put(this._actionInteractiveHelp(action));
734
- }
735
- }
736
- static _drawInteractiveRun(run, put, blank, getY, opts) {
737
- const tabs = 40;
738
- if (run) {
739
- put(this._runDetailsHeader());
740
- put(this._runDetailsId(run.id, tabs));
741
- put(this._runHtmlUrl(run.url, tabs));
742
- put(this._runDetailsStatus(run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL, run.started, run.finished, tabs));
743
- put(this._runDetailsTriggerer(run, tabs));
744
- if (run.description) {
745
- put(this._runDetailsDescription(run, tabs));
746
- }
747
- const started = this._runDetailsStarted(run.status, run.started, run.delayed, tabs);
748
- if (started) {
749
- put(started);
750
- }
751
- const finished = this._runDetailsFinished(run.status, run.finished, tabs);
752
- if (finished) {
753
- put(finished);
754
- }
755
- const context = this._runContext(run, tabs);
756
- if (context.length > 0) {
757
- blank();
758
- context.forEach((str) => {
759
- put(str);
760
- });
761
- }
762
- const y = getY();
763
- let actionsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 5;
764
- if (actionsLimit < 2)
765
- actionsLimit = 2;
766
- if (opts.selectedActionIndex >= (run?.actions.length || actionsLimit)) {
767
- opts.selectedActionIndex = run.actions.length - 1;
768
- }
769
- const actions = this._runActions(run, false, actionsLimit, opts.selectedActionIndex, tabs);
770
- if (actions.length > 0) {
771
- blank();
772
- actions.forEach((str) => {
773
- put(str);
774
- });
775
- }
776
- blank();
777
- put(this._runInteractiveHelp(run));
778
- }
779
- }
780
- static async _approveRun(client, workspace, project, pipelineId, runId, action, forceFetch) {
781
- await client.pipelineRunApply(workspace, project, pipelineId, runId, {
782
- operation: 'APPLY',
783
- approve_action_id: action.id,
784
- });
785
- if (forceFetch)
786
- setTimeout(forceFetch, 100);
787
- }
788
- static async _retryRun(client, workspace, project, pipelineId, runId, forceFetch) {
789
- try {
790
- await client.pipelineRunRetry(workspace, project, pipelineId, runId);
791
- if (forceFetch)
792
- setTimeout(forceFetch, 100);
793
- }
794
- catch (err) {
795
- if (err.message !== 'Unable to update/delete pipeline in progress') {
796
- throw err;
797
- }
798
- }
799
- }
800
- static async _cancelRun(client, workspace, project, pipelineId, runId, forceFetch) {
801
- try {
802
- await client.pipelineRunCancel(workspace, project, pipelineId, runId);
803
- if (forceFetch)
804
- setTimeout(forceFetch, 100);
805
- }
806
- catch (err) {
807
- if (err.message !== 'Unable to cancel pipeline execution') {
808
- throw err;
809
- }
810
- }
811
- }
812
- static async _runLogsInteractive(client, workspace, project, pipelineId, runId, runActionId) {
813
- let action = null;
814
- let forceFetchAction = () => { };
815
- let actionLogs = [];
816
- const opts = {
817
- actionLogsScroll: 0,
818
- };
819
- let draw = () => { };
820
- const { put, apply, reset, blank } = output_1.default.createScreenBuffer((name) => {
821
- let logsPage = termkit_no_lazy_require_1.default.terminal.height - 15;
822
- if (logsPage <= 0)
823
- logsPage = 1;
824
- if (name === 'CTRL_C') {
825
- return true;
826
- }
827
- else if (name === 'ESCAPE') {
828
- return true;
829
- }
830
- else if (name === 'DOWN') {
831
- opts.actionLogsScroll -= 1;
832
- if (opts.actionLogsScroll < 0)
833
- opts.actionLogsScroll = 0;
834
- draw();
835
- }
836
- else if (name === 'UP') {
837
- opts.actionLogsScroll += 1;
838
- draw();
839
- }
840
- else if (name === 'PAGE_UP') {
841
- opts.actionLogsScroll += logsPage;
842
- draw();
843
- }
844
- else if (name === 'PAGE_DOWN') {
845
- opts.actionLogsScroll -= logsPage;
846
- if (opts.actionLogsScroll < 0)
847
- opts.actionLogsScroll = 0;
848
- draw();
849
- }
850
- else if (name === 'HOME') {
851
- opts.actionLogsScroll = actionLogs.length;
852
- draw();
853
- }
854
- else if (name === 'END') {
855
- opts.actionLogsScroll = 0;
856
- draw();
857
- }
858
- else if (action &&
859
- name.toLowerCase() === 'c' &&
860
- this._canCancel(action.status)) {
861
- this._cancelRun(client, workspace, project, pipelineId, runId, forceFetchAction)
862
- .then()
863
- .catch((err) => output_1.default.exitError(err));
864
- }
865
- else if (action &&
866
- name.toLowerCase() === 'r' &&
867
- this._canRetry(action.status)) {
868
- this._retryRun(client, workspace, project, pipelineId, runId, forceFetchAction)
869
- .then()
870
- .catch((err) => output_1.default.exitError(err));
871
- }
872
- else if (action &&
873
- name.toLowerCase() === 'a' &&
874
- this._canApprove(action.status)) {
875
- this._approveRun(client, workspace, project, pipelineId, runId, action, forceFetchAction)
876
- .then()
877
- .catch((err) => output_1.default.exitError(err));
878
- }
879
- return false;
880
- }, () => {
881
- draw();
882
- });
883
- draw = () => {
884
- reset();
885
- this._drawInteractiveAction(action, actionLogs, put, blank, opts);
886
- apply();
887
- };
888
- setInterval(() => draw(), 100);
889
- draw();
890
- this._actionLogsLoop(client, workspace, project, pipelineId, runId, runActionId, (logs) => {
891
- actionLogs = logs;
892
- draw();
893
- })
894
- .then()
895
- .catch((err) => output_1.default.exitError(err));
896
- await this._actionStatusLoop(client, workspace, project, pipelineId, runId, runActionId, (a, _, ffa) => {
897
- action = a;
898
- forceFetchAction = ffa;
899
- draw();
900
- }, true);
901
- }
902
- static async _runStatusInteractive(client, workspace, project, pipelineId, runId) {
903
- let mode = MODE.RUN;
904
- let run = null;
905
- let forceFetchRun = null;
906
- let action = null;
907
- let actionLogs = [];
908
- let cancelActionFetch = () => { };
909
- let forceActionFetch = () => { };
910
- let cancelActionLogs = () => { };
911
- let selectedActionId = null;
912
- const opts = {
913
- selectedActionIndex: -1,
914
- actionLogsScroll: 0,
915
- };
916
- let draw = () => { };
917
- const { put, apply, reset, blank, getY } = output_1.default.createScreenBuffer((name) => {
918
- let logsPage = termkit_no_lazy_require_1.default.terminal.height - 15;
919
- if (logsPage <= 0)
920
- logsPage = 1;
921
- if (name === 'CTRL_C') {
922
- return true;
923
- }
924
- else if (name === 'ESCAPE') {
925
- if (mode === MODE.RUN) {
926
- return true;
927
- }
928
- else {
929
- selectedActionId = null;
930
- action = null;
931
- actionLogs = [];
932
- opts.actionLogsScroll = 0;
933
- cancelActionFetch();
934
- cancelActionLogs();
935
- forceActionFetch = () => { };
936
- cancelActionFetch = () => { };
937
- cancelActionLogs = () => { };
938
- mode = MODE.RUN;
939
- draw();
940
- }
941
- }
942
- else if (name === 'DOWN') {
943
- if (mode === MODE.RUN) {
944
- opts.selectedActionIndex += 1;
945
- draw();
946
- }
947
- else {
948
- opts.actionLogsScroll -= 1;
949
- if (opts.actionLogsScroll < 0)
950
- opts.actionLogsScroll = 0;
951
- draw();
952
- }
953
- }
954
- else if (name === 'UP') {
955
- if (mode === MODE.RUN) {
956
- opts.selectedActionIndex -= 1;
957
- if (opts.selectedActionIndex < 0)
958
- opts.selectedActionIndex = -1;
959
- draw();
960
- }
961
- else {
962
- opts.actionLogsScroll += 1;
963
- draw();
964
- }
965
- }
966
- else if (name === 'PAGE_UP') {
967
- if (mode === MODE.ACTION) {
968
- opts.actionLogsScroll += logsPage;
969
- draw();
970
- }
971
- }
972
- else if (name === 'PAGE_DOWN') {
973
- if (mode === MODE.ACTION) {
974
- opts.actionLogsScroll -= logsPage;
975
- if (opts.actionLogsScroll < 0)
976
- opts.actionLogsScroll = 0;
977
- draw();
978
- }
979
- }
980
- else if (name === 'HOME') {
981
- if (mode === MODE.ACTION) {
982
- opts.actionLogsScroll = actionLogs.length;
983
- draw();
984
- }
985
- }
986
- else if (name === 'END') {
987
- if (mode === MODE.ACTION) {
988
- opts.actionLogsScroll = 0;
989
- draw();
990
- }
991
- }
992
- else if (name === 'ENTER') {
993
- if (mode === MODE.RUN &&
994
- run &&
995
- run.actions[opts.selectedActionIndex]) {
996
- selectedActionId = run.actions[opts.selectedActionIndex].id;
997
- mode = MODE.ACTION;
998
- this._actionLogsLoop(client, workspace, project, pipelineId, runId, selectedActionId, (logs, cancel) => {
999
- cancelActionLogs = cancel;
1000
- actionLogs = logs;
1001
- draw();
1002
- });
1003
- this._actionStatusLoop(client, workspace, project, pipelineId, runId, selectedActionId, (a, cancel, ffa) => {
1004
- if (cancel)
1005
- cancelActionFetch = cancel;
1006
- if (a && selectedActionId === a.id)
1007
- action = a;
1008
- if (ffa)
1009
- forceActionFetch = ffa;
1010
- draw();
1011
- }, true);
1012
- draw();
1013
- }
1014
- }
1015
- else if (run &&
1016
- name.toLowerCase() === 'c' &&
1017
- this._canCancel(run.status)) {
1018
- this._cancelRun(client, workspace, project, pipelineId, runId, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1019
- .then()
1020
- .catch((err) => output_1.default.exitError(err));
1021
- }
1022
- else if (run &&
1023
- name.toLowerCase() === 'r' &&
1024
- this._canRetry(run.status)) {
1025
- this._retryRun(client, workspace, project, pipelineId, runId, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1026
- .then()
1027
- .catch((err) => output_1.default.exitError(err));
1028
- }
1029
- else if (run &&
1030
- name.toLowerCase() === 'a' &&
1031
- this._canApprove(run.status)) {
1032
- let a = null;
1033
- if (mode === MODE.ACTION) {
1034
- a = action;
1035
- }
1036
- else if (mode === MODE.RUN) {
1037
- if (run.actions[opts.selectedActionIndex]) {
1038
- a = run.actions[opts.selectedActionIndex];
1039
- }
1040
- if (!a || !this._canApprove(a.status)) {
1041
- a = run.actions.find((a) => this._canApprove(a.status));
1042
- }
1043
- }
1044
- if (a && this._canApprove(a.status)) {
1045
- this._approveRun(client, workspace, project, pipelineId, runId, a, mode === MODE.RUN ? forceFetchRun : forceActionFetch)
1046
- .then()
1047
- .catch((err) => output_1.default.exitError(err));
1048
- }
1049
- }
1050
- return false;
1051
- }, () => {
1052
- draw();
1053
- });
1054
- draw = () => {
1055
- reset();
1056
- if (mode === MODE.RUN) {
1057
- this._drawInteractiveRun(run, put, blank, getY, opts);
1058
- }
1059
- else {
1060
- this._drawInteractiveAction(action, actionLogs, put, blank, opts);
1061
- }
1062
- apply();
1063
- };
1064
- setInterval(() => draw(), 100);
1065
- draw();
1066
- await this._runStatusLoop(client, workspace, project, pipelineId, runId, (r, ffr) => {
1067
- run = r;
1068
- forceFetchRun = ffr;
1069
- draw();
1070
- }, true);
1071
- }
1072
- static async _runLogsNonInteractive(client, workspace, project, pipelineId, runId, runActionId, noWait) {
1073
- let action = null;
1074
- let actionLogsStart = 0;
1075
- let lastActionLogsStart = -1;
1076
- let drawnStart = false;
1077
- let logsEnd = false;
1078
- let totalFetchesCount = 0;
1079
- const tabs = 40;
1080
- const draw = (logs) => {
1081
- if (!drawnStart && action) {
1082
- output_1.default.normal(this._runDetailsHeader());
1083
- output_1.default.normal(this._runDetailsId(action.id, tabs));
1084
- output_1.default.normal(this._runHtmlUrl(action.url, tabs));
1085
- output_1.default.normal(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
1086
- const target = this._runActionTarget(action, tabs);
1087
- if (target) {
1088
- output_1.default.normal(target);
1089
- }
1090
- const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
1091
- if (loop) {
1092
- output_1.default.normal(loop);
1093
- }
1094
- const started = this._runDetailsStarted(action.status, action.started, null, tabs);
1095
- if (started) {
1096
- output_1.default.normal(started);
1097
- }
1098
- const finished = this._runDetailsFinished(action.status, action.finished, tabs);
1099
- if (finished) {
1100
- output_1.default.normal(finished);
1101
- }
1102
- output_1.default.normal('');
1103
- output_1.default.normal(this._runLogsHeader());
1104
- drawnStart = true;
1105
- }
1106
- if (drawnStart && logs && !logsEnd) {
1107
- for (; actionLogsStart < logs.length; actionLogsStart += 1) {
1108
- output_1.default.normal(output_1.default.getTermKitDimColor(` ${logs[actionLogsStart]}`));
1109
- }
1110
- if (action &&
1111
- [
1112
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1113
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1114
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1115
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1116
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1117
- ].includes(action.status) &&
1118
- (actionLogsStart === lastActionLogsStart || logs.length < LOGS_LIMIT)) {
1119
- logsEnd = true;
1120
- }
1121
- lastActionLogsStart = actionLogsStart;
1122
- }
1123
- if (logsEnd || (drawnStart && noWait && logs)) {
1124
- if (logsEnd && action?.outputtedVariables.length) {
1125
- output_1.default.normal('');
1126
- output_1.default.normal(this._runOutputHeader());
1127
- output_1.default.normal(output_1.default.getTermKitDimColor(' Variables '), false);
1128
- action.outputtedVariables.forEach((v, i) => {
1129
- let line = '';
1130
- if (i > 0)
1131
- line += ' ';
1132
- line += output_1.default.getTermKitMutedColor(v.key);
1133
- line += output_1.default.getTermKitDimColor(` = "`);
1134
- line += output_1.default.getTermKitBlueColor(v.value);
1135
- line += output_1.default.getTermKitDimColor('"');
1136
- output_1.default.normal(line);
1137
- });
1138
- }
1139
- if (logsEnd && action && totalFetchesCount > 1) {
1140
- output_1.default.normal('');
1141
- output_1.default.normal(this._runDetailsHeader());
1142
- output_1.default.normal(this._runDetailsStatus(action.status, action.started, action.finished, tabs));
1143
- const target = this._runActionTarget(action, tabs);
1144
- if (target) {
1145
- output_1.default.normal(target);
1146
- }
1147
- const loop = this._runLoopVariables(action.loop, action.loopValues, tabs);
1148
- if (loop) {
1149
- output_1.default.normal(loop);
1150
- }
1151
- const started = this._runDetailsStarted(action.status, action.started, null, tabs);
1152
- if (started) {
1153
- output_1.default.normal(started);
1154
- }
1155
- const finished = this._runDetailsFinished(action.status, action.finished, tabs);
1156
- if (finished) {
1157
- output_1.default.normal(finished);
1158
- }
1159
- }
1160
- output_1.default.exitNormal();
1161
- }
1162
- };
1163
- this._actionLogsLoop(client, workspace, project, pipelineId, runId, runActionId, draw)
1164
- .then()
1165
- .catch((err) => output_1.default.exitError(err));
1166
- await this._actionStatusLoop(client, workspace, project, pipelineId, runId, runActionId, (a) => {
1167
- if (a) {
1168
- action = a;
1169
- totalFetchesCount += 1;
1170
- draw();
1171
- }
1172
- });
1173
- }
1174
- static async _runStatusNonInteractive(client, workspace, project, pipelineId, runId, noWait) {
1175
- let run = null;
1176
- let totalFetchesCount = 0;
1177
- const tabs = 40;
1178
- const draw = (r) => {
1179
- if (!run) {
1180
- output_1.default.normal(this._runDetailsHeader());
1181
- output_1.default.normal(this._runDetailsId(r.id, tabs));
1182
- output_1.default.normal(this._runHtmlUrl(r.url, tabs));
1183
- output_1.default.normal(this._runDetailsStatus(r.status, r.started, r.finished, tabs));
1184
- output_1.default.normal(this._runDetailsTriggerer(r, tabs));
1185
- if (r?.description)
1186
- output_1.default.normal(this._runDetailsDescription(r, tabs));
1187
- const started = this._runDetailsStarted(r.status, r.started, r.delayed, tabs);
1188
- if (started)
1189
- output_1.default.normal(started);
1190
- const finished = this._runDetailsFinished(r.status, r.finished, tabs);
1191
- if (finished)
1192
- output_1.default.normal(finished);
1193
- const context = this._runContext(r, tabs);
1194
- if (context.length > 0) {
1195
- output_1.default.normal('');
1196
- context.forEach((str) => {
1197
- output_1.default.normal(str);
1198
- });
1199
- output_1.default.normal('');
1200
- }
1201
- output_1.default.normal(this._runActionsHeader(tabs));
1202
- }
1203
- const actions = this._runActions(r, true, 0, -1, tabs);
1204
- actions.forEach((str) => {
1205
- output_1.default.normal(str);
1206
- });
1207
- run = r;
1208
- };
1209
- run = await this._runStatusLoop(client, workspace, project, pipelineId, runId, (run) => {
1210
- totalFetchesCount += 1;
1211
- draw(run);
1212
- if (noWait) {
1213
- output_1.default.exitNormal();
1214
- }
1215
- });
1216
- if (totalFetchesCount > 1) {
1217
- output_1.default.normal('');
1218
- output_1.default.normal(this._runDetailsHeader());
1219
- output_1.default.normal(this._runDetailsStatus(run.status, run.started, run.finished, tabs));
1220
- const started = this._runDetailsStarted(run.status, run.started, run.delayed, tabs);
1221
- if (started)
1222
- output_1.default.normal(started);
1223
- const finished = this._runDetailsFinished(run.status, run.finished, tabs);
1224
- if (finished)
1225
- output_1.default.normal(finished);
1226
- }
1227
- output_1.default.exitNormal();
1228
- }
1229
- static async _actionLogsLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange) {
1230
- let logs = [];
1231
- let offset = 0;
1232
- let shouldCancel = false;
1233
- const cancel = () => {
1234
- shouldCancel = true;
1235
- };
1236
- onChange(logs, cancel);
1237
- const fetchLogs = async () => {
1238
- return await client.getPipelineRunActionLogs(workspace, project, pipelineId, runId, actionExecutionId, offset, LOGS_LIMIT);
1239
- };
1240
- for (;;) {
1241
- let o = await fetchLogs();
1242
- if (o.total_element_count < offset) {
1243
- logs = [];
1244
- offset = 0;
1245
- o = await fetchLogs();
1246
- }
1247
- offset = o.offset + o.element_count;
1248
- logs.push(...o.logs);
1249
- if (shouldCancel)
1250
- return;
1251
- onChange(logs, cancel);
1252
- if (o.logs.length > 0)
1253
- continue;
1254
- await (0, utils_1.sleep)(3000);
1255
- }
1256
- }
1257
- static async _actionStatusLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange, dontExit = false) {
1258
- const fetchAction = async () => {
1259
- return await client.getPipelineRunActionExecution(workspace, project, pipelineId, runId, actionExecutionId);
1260
- };
1261
- let status = pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1262
- let oldStatus = null;
1263
- let shouldCancel = false;
1264
- const cancel = () => {
1265
- shouldCancel = true;
1266
- };
1267
- const forceFetchAction = async () => {
1268
- const a = await fetchAction();
1269
- let started = null;
1270
- if (a.start_date)
1271
- started = new Date(a.start_date);
1272
- let finished = null;
1273
- if (a.finish_date)
1274
- finished = new Date(a.finish_date);
1275
- status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1276
- const name = a.action?.name || '';
1277
- const actionId = a.action?.id || -1;
1278
- const url = a.html_url || '';
1279
- const originalType = a.action?.type || 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
- let target = null;
1285
- if (a.target)
1286
- target = a.target;
1287
- let outputtedVariables = [];
1288
- if (a.outputted_variables) {
1289
- outputtedVariables = [];
1290
- a.outputted_variables.forEach((v) => {
1291
- outputtedVariables.push({
1292
- key: String(v.key),
1293
- value: String(v.value),
1294
- });
1295
- });
1296
- }
1297
- let loop = LOOP_STATUS.DISABLED;
1298
- let loopValues = [];
1299
- if (a.loop_details) {
1300
- loop = a.loop_details.status;
1301
- if (a.loop_details.resolved_variables) {
1302
- loopValues = [];
1303
- a.loop_details.resolved_variables.forEach((v) => {
1304
- if (v.value)
1305
- loopValues.push({
1306
- key: String(v.key),
1307
- value: String(v.value),
1308
- });
1309
- });
1310
- }
1311
- }
1312
- const changed = !oldStatus || status !== oldStatus;
1313
- const action = {
1314
- id: actionExecutionId,
1315
- actionId,
1316
- url,
1317
- status,
1318
- target,
1319
- loop,
1320
- loopValues,
1321
- outputtedVariables,
1322
- started,
1323
- finished,
1324
- name,
1325
- type,
1326
- changed,
1327
- };
1328
- onChange(action, cancel, forceFetchAction);
1329
- return action;
1330
- };
1331
- await forceFetchAction();
1332
- for (;;) {
1333
- await (0, utils_1.sleep)(3000);
1334
- if (shouldCancel)
1335
- return;
1336
- await forceFetchAction();
1337
- oldStatus = status;
1338
- if (!dontExit &&
1339
- [
1340
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1341
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1342
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1343
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1344
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1345
- ].includes(status)) {
1346
- cancel();
1347
- }
1348
- if (shouldCancel)
1349
- return;
1350
- }
1351
- }
1352
- static async _runStatusLoop(client, workspace, project, pipelineId, runId, onChange, dontExit = false) {
1353
- let lastRun;
1354
- const fetchRun = async () => {
1355
- return await client.getPipelineRun(workspace, project, pipelineId, runId);
1356
- };
1357
- const id = runId;
1358
- let url;
1359
- let status;
1360
- let started;
1361
- let finished = null;
1362
- let delayed = null;
1363
- let trigger;
1364
- let creator = 'Unknown';
1365
- let description = '';
1366
- let refresh = false;
1367
- let clearCache = false;
1368
- let priority = pipeline_1.PIPELINE_PRIORITY.NORMAL;
1369
- let context = null;
1370
- let actions = [];
1371
- const forceFetchRun = async () => {
1372
- const run = await fetchRun();
1373
- started = new Date(run.start_date || new Date());
1374
- trigger = run.triggered_on || pipeline_1.PIPELINE_RUN_TRIGGER.CLICK;
1375
- status = run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1376
- url = run.html_url;
1377
- if (run.creator) {
1378
- if (run.creator.name)
1379
- creator = run.creator.name;
1380
- else if (run.creator.email)
1381
- creator = run.creator.email;
1382
- }
1383
- if (run.finish_date)
1384
- finished = new Date(run.finish_date);
1385
- if (run.comment)
1386
- description = run.comment;
1387
- if (run.priority)
1388
- priority = run.priority;
1389
- if (run.delay_until)
1390
- delayed = new Date(run.delay_until);
1391
- if (run.refresh)
1392
- refresh = true;
1393
- if (run.clear_cache)
1394
- clearCache = true;
1395
- if (run.branch) {
1396
- if (!context)
1397
- context = {};
1398
- context['Branch'] = run.branch.name;
1399
- }
1400
- if (run.tag) {
1401
- if (!context)
1402
- context = {};
1403
- context['Tag'] = run.tag.name;
1404
- }
1405
- if (run.pull_request) {
1406
- if (!context)
1407
- context = {};
1408
- context['Pull request'] = run.pull_request.name;
1409
- }
1410
- if (run.to_revision) {
1411
- if (!context)
1412
- context = {};
1413
- context['Revision'] = `#${run.to_revision.revision.substring(0, 7)}`;
1414
- if (run.to_revision.message)
1415
- context['Revision'] += `: ${run.to_revision.message}`;
1416
- }
1417
- if (run.environment) {
1418
- if (!context)
1419
- context = {};
1420
- context['Environment'] = run.environment.identifier;
1421
- }
1422
- if (run.package && run.package_version) {
1423
- if (!context)
1424
- context = {};
1425
- context['Package'] =
1426
- `${run.package.identifier}:${run.package_version.version}`;
1427
- }
1428
- if (run.loop_details) {
1429
- if (!context)
1430
- context = {};
1431
- context['Loop'] = this._runLoopText(run.loop_details.status, run.loop_details.resolved_variables || []);
1432
- }
1433
- if (run.action_executions) {
1434
- const old = actions;
1435
- actions = (run.action_executions || []).map((a) => {
1436
- const originalType = a.action?.type ||
1437
- pipeline_1.PIPELINE_ACTION_TYPE.BUILD;
1438
- let type = originalType;
1439
- if (pipeline_1.PIPELINE_ACTION_NAME[originalType]) {
1440
- type = pipeline_1.PIPELINE_ACTION_NAME[originalType];
1441
- }
1442
- const name = a.action?.name || '';
1443
- const id = a.action_execution_id;
1444
- const url = a.html_url;
1445
- const actionId = a.action?.id || -1;
1446
- const status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
1447
- let target = null;
1448
- let loop = LOOP_STATUS.DISABLED;
1449
- const loopValues = [];
1450
- const outputtedVariables = [];
1451
- if (a.target)
1452
- target = a.target;
1453
- if (a.outputted_variables) {
1454
- a.outputted_variables.forEach((v) => {
1455
- outputtedVariables.push({
1456
- key: String(v.key),
1457
- value: String(v.value),
1458
- });
1459
- });
1460
- }
1461
- if (a.loop_details) {
1462
- loop = a.loop_details.status;
1463
- if (a.loop_details.resolved_variables) {
1464
- a.loop_details.resolved_variables.forEach((v) => {
1465
- if (v.value)
1466
- loopValues.push({
1467
- key: String(v.key),
1468
- value: String(v.value),
1469
- });
1470
- });
1471
- }
1472
- }
1473
- let started = null;
1474
- if (a.start_date)
1475
- started = new Date(a.start_date);
1476
- let finished = null;
1477
- if (a.finish_date)
1478
- finished = new Date(a.finish_date);
1479
- const oldAction = old.find((o) => o.id === id);
1480
- const changed = !oldAction || oldAction.status !== status;
1481
- const action = {
1482
- type,
1483
- name,
1484
- url,
1485
- loop,
1486
- loopValues,
1487
- outputtedVariables,
1488
- target,
1489
- actionId,
1490
- id,
1491
- status,
1492
- started,
1493
- finished,
1494
- changed,
1495
- };
1496
- return action;
1497
- });
1498
- actions = actions.filter((a) => {
1499
- if (a.target)
1500
- return true;
1501
- return !actions.find((a2) => {
1502
- if (a2.id === a.id)
1503
- return false;
1504
- if (a2.actionId !== a.actionId)
1505
- return false;
1506
- return !!a2.target;
1507
- });
1508
- });
1509
- }
1510
- const r = {
1511
- id,
1512
- creator,
1513
- description,
1514
- started,
1515
- url,
1516
- status,
1517
- trigger,
1518
- finished,
1519
- clearCache,
1520
- refresh,
1521
- priority,
1522
- delayed,
1523
- context,
1524
- actions,
1525
- };
1526
- onChange(r, forceFetchRun);
1527
- return r;
1528
- };
1529
- lastRun = await forceFetchRun();
1530
- for (;;) {
1531
- if (!dontExit &&
1532
- [
1533
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
1534
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
1535
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
1536
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
1537
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
1538
- ].includes(lastRun.status)) {
1539
- break;
1540
- }
1541
- await (0, utils_1.sleep)(3000);
1542
- lastRun = await forceFetchRun();
1543
- }
1544
- return lastRun;
1545
- }
1546
- }
1547
- exports.default = OutputPipeline;