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