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