bdy 1.18.24-dev-pipeline → 1.18.26-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 (34) hide show
  1. package/distTs/package.json +1 -2
  2. package/distTs/src/api/client.js +2 -9
  3. package/distTs/src/command/login.js +56 -19
  4. package/distTs/src/command/pipeline/run.js +125 -7
  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/create.js +3 -2
  9. package/distTs/src/command/sandbox/get/yaml.js +30 -0
  10. package/distTs/src/command/vt/scrape.js +193 -0
  11. package/distTs/src/input.js +10 -6
  12. package/distTs/src/output.js +32 -82
  13. package/distTs/src/texts.js +39 -29
  14. package/distTs/src/tunnel/api/buddy.js +9 -15
  15. package/package.json +1 -2
  16. package/distTs/src/command/crawl/validation.js +0 -151
  17. package/distTs/src/command/crawl.js +0 -144
  18. package/distTs/src/command/pipeline/run/start.js +0 -101
  19. package/distTs/src/command/pipeline/run/status.js +0 -34
  20. package/distTs/src/command/tests/capture/validation.js +0 -59
  21. package/distTs/src/command/tests/capture.js +0 -100
  22. package/distTs/src/command/tests/unit/upload.js +0 -86
  23. package/distTs/src/command/tests/unit.js +0 -11
  24. package/distTs/src/command/tests/visual/session/close.js +0 -27
  25. package/distTs/src/command/tests/visual/session/create.js +0 -82
  26. package/distTs/src/command/tests/visual/session.js +0 -13
  27. package/distTs/src/command/tests/visual/setup.js +0 -20
  28. package/distTs/src/command/tests/visual/shared/validation.js +0 -118
  29. package/distTs/src/command/tests/visual/upload.js +0 -138
  30. package/distTs/src/command/tests/visual.js +0 -15
  31. package/distTs/src/command/tests.js +0 -15
  32. package/distTs/src/output/pipeline.js +0 -915
  33. package/distTs/src/types/crawl.js +0 -2
  34. package/distTs/src/types/pipeline.js +0 -424
@@ -1,915 +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
- class OutputPipeline {
12
- static async runStatus(client, workspace, project, pipelineId, runId, noWait) {
13
- if (output_1.default.isTTY() && !noWait) {
14
- return await this._runStatusInteractive(client, workspace, project, pipelineId, runId);
15
- }
16
- return await this._runStatusNonInteractive(client, workspace, project, pipelineId, runId, noWait);
17
- }
18
- static _fillString(str, length) {
19
- if (str.length >= length - 1)
20
- return str.substring(0, length - 1) + ' ';
21
- for (let i = str.length; i < length; i += 1)
22
- str += ' ';
23
- return str;
24
- }
25
- static _formatDate(date) {
26
- let str = `${date.getFullYear()}-`;
27
- const m = date.getMonth() + 1;
28
- if (m < 10)
29
- str += '0';
30
- str += `${m}-`;
31
- const d = date.getDate();
32
- if (d < 10)
33
- str += '0';
34
- str += `${d} `;
35
- const h = date.getHours();
36
- if (h < 10)
37
- str += '0';
38
- str += `${h}:`;
39
- const mm = date.getMinutes();
40
- if (mm < 10)
41
- str += '0';
42
- str += `${mm}:`;
43
- const s = date.getSeconds();
44
- if (s < 10)
45
- str += '0';
46
- str += s;
47
- return str;
48
- }
49
- static _formatTimespan(start, end) {
50
- if (!end)
51
- end = new Date();
52
- let ts = Math.abs(end.getTime() - start.getTime());
53
- if (!ts)
54
- return '';
55
- const hours = Math.floor(ts / 1000 / 60 / 60);
56
- ts -= hours * 60 * 60 * 1000;
57
- const minutes = Math.floor(ts / 1000 / 60);
58
- ts -= minutes * 60 * 1000;
59
- const seconds = Math.ceil(ts / 1000);
60
- let str = '';
61
- if (hours > 0)
62
- str += `${hours}h `;
63
- if (minutes > 0 || hours > 0)
64
- str += `${minutes}m `;
65
- if (seconds < 10 && (hours > 0 || minutes > 0))
66
- str += '0';
67
- str += `${seconds}s`;
68
- return str;
69
- }
70
- static _runDetailsHeader() {
71
- return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('DETAILS')}`;
72
- }
73
- static _runLogsHeader() {
74
- return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('LOGS')}`;
75
- }
76
- static _runDetailsStarted(status, started, delayed = null, tabs = 25) {
77
- if (delayed && status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
78
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Scheduled', tabs))}`;
79
- str += output_1.default.getTermKitMutedColor(this._formatDate(delayed || new Date()));
80
- return str;
81
- }
82
- if ([
83
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
84
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATING,
85
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
86
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
87
- pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS,
88
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
89
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
90
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
91
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
92
- ].includes(status)) {
93
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Started', tabs))}`;
94
- str += output_1.default.getTermKitMutedColor(this._formatDate(started || new Date()));
95
- return str;
96
- }
97
- return null;
98
- }
99
- static _runActionsHeader(tabs = 25) {
100
- return `${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor(this._fillString('ACTIONS', tabs + 40))} ${output_1.default.getTermKitLabelColor('ID')}`;
101
- }
102
- static _actionLogs(action, limit = 0) {
103
- const str = [];
104
- if (action.logs && action.logs.length > 0) {
105
- let start = action.logs.length - limit;
106
- if (start < 0)
107
- start = 0;
108
- let end = start + limit;
109
- if (end > action.logs.length)
110
- end = action.logs.length;
111
- for (let i = start; i < end; i += 1) {
112
- str.push(` ${output_1.default.getTermKitDimColor(action.logs[i])}`);
113
- }
114
- }
115
- else {
116
- str.push(` ${output_1.default.getTermKitDimColor('Waiting...')}`);
117
- }
118
- return str;
119
- }
120
- static _runActions(run, onlyChanged = false, limit = 0, selected = -1, tabs = 25) {
121
- const str = [];
122
- if (!run)
123
- return str;
124
- if (!onlyChanged) {
125
- str.push(this._runActionsHeader(tabs));
126
- }
127
- let count = 0;
128
- let start = 0;
129
- if (selected >= limit / 2) {
130
- start = selected - limit / 2;
131
- if (start + limit >= run.actions.length) {
132
- start = run.actions.length - limit;
133
- }
134
- }
135
- for (let i = start; i < run.actions.length; i += 1) {
136
- const a = run.actions[i];
137
- if (!a || (onlyChanged && !a.changed))
138
- continue;
139
- let s = '';
140
- const highlight = i === selected;
141
- if (highlight) {
142
- s += output_1.default.getTermKitCyanColor('❯ ');
143
- s += output_1.default.getTermKitCyanColor(this._fillString(a.type, tabs));
144
- }
145
- else {
146
- s += ' ';
147
- s += output_1.default.getTermKitDimColor(this._fillString(a.type, tabs));
148
- }
149
- const name = this._fillString(a.name || '', 41);
150
- if (highlight) {
151
- s += output_1.default.getTermKitCyanColor(name);
152
- }
153
- else if ([
154
- pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS,
155
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATING,
156
- ].includes(a.status)) {
157
- s += output_1.default.getTermKitBlueColor(name);
158
- }
159
- else if ([
160
- pipeline_1.PIPELINE_RUN_STATUS.INITIAL,
161
- pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED,
162
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
163
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
164
- ].includes(a.status)) {
165
- s += output_1.default.getTermKitDimColor(name);
166
- }
167
- else {
168
- s += output_1.default.getTermKitMutedColor(name);
169
- }
170
- if (![
171
- pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED,
172
- pipeline_1.PIPELINE_RUN_STATUS.INITIAL,
173
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
174
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
175
- ].includes(a.status)) {
176
- if (highlight) {
177
- s += output_1.default.getTermKitCyanColor(this._fillString(a.id, 25));
178
- }
179
- else {
180
- s += output_1.default.getTermKitDimColor(this._fillString(a.id, 25));
181
- }
182
- }
183
- else {
184
- s += this._fillString('', 25);
185
- }
186
- let ts = false;
187
- if (a.status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
188
- if (onlyChanged) {
189
- s += output_1.default.getTermKitBlueColor(pipeline_1.PIPELINE_STATUS_ICONS.INPROGRESS);
190
- }
191
- else {
192
- s += output_1.default.getTermKitBlueColor(this._statusAnimationString());
193
- }
194
- ts = true;
195
- }
196
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
197
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.ENQUEUED);
198
- s += ` ${output_1.default.getTermKitDimColor('Enqueued')}`;
199
- }
200
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
201
- s += output_1.default.getTermKitRedColor(pipeline_1.PIPELINE_STATUS_ICONS.TERMINATED);
202
- ts = true;
203
- }
204
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
205
- s += output_1.default.getTermKitGreenColor(pipeline_1.PIPELINE_STATUS_ICONS.SUCCESSFUL);
206
- ts = true;
207
- }
208
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
209
- s += output_1.default.getTermKitRedColor(pipeline_1.PIPELINE_STATUS_ICONS.FAILED);
210
- ts = true;
211
- }
212
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
213
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.INITIAL);
214
- s += ` ${output_1.default.getTermKitDimColor('Created')}`;
215
- }
216
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
217
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.NOT_EXECUTED);
218
- s += ` ${output_1.default.getTermKitDimColor('Created')}`;
219
- }
220
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
221
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.SKIPPED);
222
- s += ` ${output_1.default.getTermKitDimColor('Skipped')}`;
223
- }
224
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
225
- if (onlyChanged) {
226
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.TERMINATING);
227
- }
228
- else {
229
- s += output_1.default.getTermKitBlueColor(this._statusAnimationString());
230
- }
231
- ts = true;
232
- }
233
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY) {
234
- s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_APPLY);
235
- s += ` ${output_1.default.getTermKitPurpleColor('Waiting')}`;
236
- }
237
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES) {
238
- s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_VARIABLES);
239
- s += ` ${output_1.default.getTermKitPurpleColor('Waiting')}`;
240
- }
241
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES) {
242
- s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_SETTABLE_VARIABLES);
243
- s += ` ${output_1.default.getTermKitPurpleColor('Waiting')}`;
244
- }
245
- else if (a.status === pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION) {
246
- s += output_1.default.getTermKitPurpleColor(pipeline_1.PIPELINE_STATUS_ICONS.WAITING_FOR_VT_SESSION);
247
- s += ` ${output_1.default.getTermKitPurpleColor('Waiting')}`;
248
- }
249
- else {
250
- s += output_1.default.getTermKitDimColor(pipeline_1.PIPELINE_STATUS_ICONS.SKIPPED);
251
- s += ` ${output_1.default.getTermKitDimColor(a.status)}`;
252
- }
253
- if (ts && a.started) {
254
- s += ` ${output_1.default.getTermKitMutedColor(this._formatTimespan(a.started, a.finished))}`;
255
- }
256
- str.push(s);
257
- count += 1;
258
- if (limit && count >= limit)
259
- break;
260
- }
261
- return str;
262
- }
263
- static _runContext(run, tabs = 25) {
264
- const str = [];
265
- if (run?.context) {
266
- str.push(`${output_1.default.getTermKitBlueColor('/')} ${output_1.default.getTermKitLabelColor('CONTEXT')}`);
267
- const ctx = run.context;
268
- Object.keys(ctx).forEach((name) => {
269
- str.push(` ${output_1.default.getTermKitDimColor(this._fillString(name, tabs))}${output_1.default.getTermKitMutedColor(ctx[name])}`);
270
- });
271
- }
272
- return str;
273
- }
274
- static _runDetailsFinished(status, finished, tabs = 25) {
275
- if (finished &&
276
- [
277
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
278
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
279
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
280
- ].includes(status)) {
281
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Finished', tabs))}`;
282
- str += output_1.default.getTermKitMutedColor(this._formatDate(finished));
283
- return str;
284
- }
285
- return null;
286
- }
287
- static _runDetailsTriggerer(run, tabs = 25) {
288
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Triggerer', tabs))}`;
289
- str += output_1.default.getTermKitMutedColor(run?.creator || 'Unknown');
290
- return str;
291
- }
292
- static _runDetailsDescription(run, tabs = 25) {
293
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Description', tabs))}`;
294
- str += output_1.default.getTermKitMutedColor(run?.description || '');
295
- return str;
296
- }
297
- static _statusAnimationIndex = 0;
298
- static _statusAnimationTs;
299
- static _statusAnimationString() {
300
- const opts = pipeline_1.PIPELINE_STATUS_PROGRESS_ANIMATION;
301
- if (!this._statusAnimationTs) {
302
- this._statusAnimationTs = setInterval(() => {
303
- this._statusAnimationIndex += 1;
304
- if (this._statusAnimationIndex > opts.length - 1)
305
- this._statusAnimationIndex = 0;
306
- }, 100);
307
- }
308
- return opts[this._statusAnimationIndex];
309
- }
310
- static _runDetailsTrigger(run, tabs = 25) {
311
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Trigger', tabs))}`;
312
- if (!run || run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.CLICK) {
313
- str += output_1.default.getTermKitMutedColor('Manual');
314
- }
315
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.SCHEDULE) {
316
- str += output_1.default.getTermKitMutedColor('Schedule');
317
- }
318
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EVENT) {
319
- str += output_1.default.getTermKitMutedColor('Event');
320
- }
321
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.PIPELINE) {
322
- str += output_1.default.getTermKitMutedColor('Pipeline');
323
- }
324
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.WEBHOOK) {
325
- str += output_1.default.getTermKitMutedColor('Webhook');
326
- }
327
- else if (run.trigger === pipeline_1.PIPELINE_RUN_TRIGGER.EMAIL) {
328
- str += output_1.default.getTermKitMutedColor('Email');
329
- }
330
- else {
331
- str += run.trigger;
332
- }
333
- if (run?.priority === pipeline_1.PIPELINE_PRIORITY.HIGH) {
334
- str += output_1.default.getTermKitMutedColor(', high');
335
- }
336
- else if (run?.priority === pipeline_1.PIPELINE_PRIORITY.LOW) {
337
- str += output_1.default.getTermKitMutedColor(', low');
338
- }
339
- if (run?.refresh) {
340
- str += output_1.default.getTermKitMutedColor(', from scratch');
341
- }
342
- if (run?.clearCache) {
343
- str += output_1.default.getTermKitMutedColor(', clear cache');
344
- }
345
- return str;
346
- }
347
- static _runDetailsStatus(status, started, finished, tabs = 25) {
348
- let str = ` ${output_1.default.getTermKitDimColor(this._fillString('Status', tabs))}`;
349
- let ts = false;
350
- if (status === pipeline_1.PIPELINE_RUN_STATUS.INITIAL) {
351
- str += output_1.default.getTermKitMutedColor('Created');
352
- }
353
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS) {
354
- str += output_1.default.getTermKitBlueColor('Running');
355
- ts = true;
356
- }
357
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED) {
358
- str += output_1.default.getTermKitMutedColor('Queued');
359
- }
360
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED) {
361
- str += output_1.default.getTermKitRedColor('Canceled');
362
- ts = true;
363
- }
364
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL) {
365
- str += output_1.default.getTermKitGreenColor('Passed');
366
- ts = true;
367
- }
368
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.FAILED) {
369
- str += output_1.default.getTermKitRedColor('Failed');
370
- ts = true;
371
- }
372
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED) {
373
- str += output_1.default.getTermKitMutedColor('Created');
374
- }
375
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.SKIPPED) {
376
- str += output_1.default.getTermKitMutedColor('Skipped');
377
- }
378
- else if (status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATING) {
379
- str += output_1.default.getTermKitBlueColor('Canceling');
380
- ts = true;
381
- }
382
- else if ([
383
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION,
384
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES,
385
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES,
386
- pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY,
387
- ].includes(status)) {
388
- str += output_1.default.getTermKitPurpleColor('Awaiting');
389
- }
390
- else {
391
- str += output_1.default.getTermKitMutedColor(status);
392
- }
393
- if (ts && started) {
394
- str += ` ${output_1.default.getTermKitDimColor(this._formatTimespan(started, finished))}`;
395
- }
396
- return str;
397
- }
398
- static _runInteractiveHelp() {
399
- let help = output_1.default.getTermKitLabelColor('↑↓');
400
- help += output_1.default.getTermKitDimColor(' navigate •');
401
- help += output_1.default.getTermKitLabelColor(' ⏎');
402
- help += output_1.default.getTermKitDimColor(' view logs •');
403
- help += output_1.default.getTermKitLabelColor(' esc');
404
- help += output_1.default.getTermKitDimColor(' exit');
405
- return help;
406
- }
407
- static _actionInteractiveHelp() {
408
- let help = output_1.default.getTermKitLabelColor(' esc');
409
- help += output_1.default.getTermKitDimColor(' exit');
410
- return help;
411
- }
412
- static _drawInteractiveAction(action, viewPort) {
413
- viewPort.fill({
414
- char: ' ',
415
- });
416
- if (action) {
417
- let y = 1;
418
- viewPort.put({
419
- x: 1,
420
- y,
421
- markup: true,
422
- }, this._runDetailsHeader());
423
- y += 1;
424
- viewPort.put({
425
- x: 1,
426
- y,
427
- markup: true,
428
- }, this._runDetailsStatus(action.status, action.started, action.finished));
429
- const started = this._runDetailsStarted(action.status, action.started);
430
- if (started) {
431
- y += 1;
432
- viewPort.put({
433
- x: 1,
434
- y,
435
- markup: true,
436
- }, started);
437
- }
438
- const finished = this._runDetailsFinished(action.status, action.finished);
439
- if (finished) {
440
- y += 1;
441
- viewPort.put({
442
- x: 1,
443
- y,
444
- markup: true,
445
- }, finished);
446
- }
447
- y += 2;
448
- viewPort.put({
449
- x: 1,
450
- y,
451
- markup: true,
452
- }, this._runLogsHeader());
453
- let logsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 5;
454
- if (logsLimit < 2)
455
- logsLimit = 2;
456
- const logs = this._actionLogs(action, logsLimit);
457
- logs.forEach((str) => {
458
- y += 1;
459
- viewPort.put({
460
- x: 1,
461
- y,
462
- markup: true,
463
- }, str);
464
- });
465
- y += 2;
466
- viewPort.put({
467
- x: 1,
468
- y,
469
- markup: true,
470
- }, this._actionInteractiveHelp());
471
- }
472
- viewPort.draw();
473
- }
474
- static _drawInteractiveRun(run, viewPort, opts) {
475
- viewPort.fill({
476
- char: ' ',
477
- });
478
- if (run) {
479
- let y = 1;
480
- viewPort.put({
481
- x: 1,
482
- y,
483
- markup: true,
484
- }, this._runDetailsHeader());
485
- y += 1;
486
- viewPort.put({
487
- x: 1,
488
- y,
489
- markup: true,
490
- }, this._runDetailsStatus(run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL, run.started, run.finished));
491
- y += 1;
492
- viewPort.put({
493
- x: 1,
494
- y,
495
- markup: true,
496
- }, this._runDetailsTrigger(run));
497
- y += 1;
498
- viewPort.put({
499
- x: 1,
500
- y,
501
- markup: true,
502
- }, this._runDetailsTriggerer(run));
503
- if (run.description) {
504
- y += 1;
505
- viewPort.put({
506
- x: 1,
507
- y,
508
- markup: true,
509
- }, this._runDetailsDescription(run));
510
- }
511
- const started = this._runDetailsStarted(run.status, run.started, run.delayed);
512
- if (started) {
513
- y += 1;
514
- viewPort.put({
515
- x: 1,
516
- y,
517
- markup: true,
518
- }, started);
519
- }
520
- const finished = this._runDetailsFinished(run.status, run.finished);
521
- if (finished) {
522
- y += 1;
523
- viewPort.put({
524
- x: 1,
525
- y,
526
- markup: true,
527
- }, finished);
528
- }
529
- const context = this._runContext(run);
530
- if (context.length > 0) {
531
- y += 1;
532
- context.forEach((str) => {
533
- y += 1;
534
- viewPort.put({
535
- x: 1,
536
- y,
537
- markup: true,
538
- }, str);
539
- });
540
- }
541
- let actionsLimit = termkit_no_lazy_require_1.default.terminal.height - y - 5;
542
- if (actionsLimit < 2)
543
- actionsLimit = 2;
544
- if (opts.selectedActionIndex >= (run?.actions.length || actionsLimit)) {
545
- opts.selectedActionIndex = run.actions.length - 1;
546
- }
547
- const actions = this._runActions(run, false, actionsLimit, opts.selectedActionIndex);
548
- if (actions.length > 0) {
549
- y += 1;
550
- actions.forEach((str) => {
551
- y += 1;
552
- viewPort.put({
553
- x: 1,
554
- y,
555
- markup: true,
556
- }, str);
557
- });
558
- }
559
- y += 2;
560
- viewPort.put({
561
- x: 1,
562
- y,
563
- markup: true,
564
- }, this._runInteractiveHelp());
565
- }
566
- viewPort.draw();
567
- }
568
- static async _runStatusInteractive(client, workspace, project, pipelineId, runId) {
569
- const MODE_RUN = 'run';
570
- const MODE_ACTION = 'action';
571
- let mode = MODE_RUN;
572
- let run = null;
573
- let action = null;
574
- let cancelActionFetch = () => { };
575
- let selectedActionId = null;
576
- const opts = {
577
- selectedActionIndex: -1,
578
- };
579
- const viewPort = new termkit_no_lazy_require_1.default.ScreenBuffer({
580
- dst: termkit_no_lazy_require_1.default.terminal,
581
- width: Math.min(termkit_no_lazy_require_1.default.terminal.width),
582
- height: Math.min(termkit_no_lazy_require_1.default.terminal.height),
583
- x: 1,
584
- y: 1,
585
- });
586
- const draw = () => {
587
- if (mode === MODE_RUN) {
588
- this._drawInteractiveRun(run, viewPort, opts);
589
- }
590
- else {
591
- this._drawInteractiveAction(action, viewPort);
592
- }
593
- };
594
- const exit = () => {
595
- termkit_no_lazy_require_1.default.terminal.fullscreen(false);
596
- termkit_no_lazy_require_1.default.terminal.hideCursor(false);
597
- termkit_no_lazy_require_1.default.terminal.grabInput(false);
598
- process.exit();
599
- };
600
- termkit_no_lazy_require_1.default.terminal.grabInput();
601
- termkit_no_lazy_require_1.default.terminal.hideCursor();
602
- termkit_no_lazy_require_1.default.terminal.fullscreen(true);
603
- termkit_no_lazy_require_1.default.terminal.on('key', (name) => {
604
- if (name === 'CTRL_C') {
605
- exit();
606
- }
607
- else if (name === 'ESCAPE') {
608
- if (mode === MODE_RUN) {
609
- exit();
610
- }
611
- else {
612
- selectedActionId = null;
613
- action = null;
614
- cancelActionFetch();
615
- mode = MODE_RUN;
616
- draw();
617
- }
618
- }
619
- else if (name === 'DOWN') {
620
- if (mode === MODE_RUN) {
621
- opts.selectedActionIndex += 1;
622
- draw();
623
- }
624
- }
625
- else if (name === 'UP') {
626
- if (mode === MODE_RUN) {
627
- opts.selectedActionIndex -= 1;
628
- if (opts.selectedActionIndex < 0)
629
- opts.selectedActionIndex = -1;
630
- draw();
631
- }
632
- }
633
- else if (name === 'ENTER') {
634
- if (mode === MODE_RUN && run && run.actions[opts.selectedActionIndex]) {
635
- selectedActionId = run.actions[opts.selectedActionIndex].id;
636
- mode = MODE_ACTION;
637
- this._actionStatusLoop(client, workspace, project, pipelineId, runId, selectedActionId, (a, cancel) => {
638
- if (cancel)
639
- cancelActionFetch = cancel;
640
- if (a && selectedActionId === a.id)
641
- action = a;
642
- draw();
643
- });
644
- draw();
645
- }
646
- }
647
- });
648
- termkit_no_lazy_require_1.default.terminal.on('resize', () => {
649
- opts.selectedActionIndex = -1;
650
- viewPort.resize({
651
- width: Math.min(termkit_no_lazy_require_1.default.terminal.width),
652
- height: Math.min(termkit_no_lazy_require_1.default.terminal.height),
653
- x: 1,
654
- y: 1,
655
- });
656
- draw();
657
- });
658
- setInterval(() => draw(), 100);
659
- draw();
660
- await this._runStatusLoop(client, workspace, project, pipelineId, runId, (r) => {
661
- run = r;
662
- draw();
663
- });
664
- }
665
- static async _runStatusNonInteractive(client, workspace, project, pipelineId, runId, noWait) {
666
- let run = null;
667
- let totalFetchesCount = 0;
668
- const draw = (r) => {
669
- if (!run) {
670
- output_1.default.normal(this._runDetailsHeader());
671
- output_1.default.normal(this._runDetailsStatus(r.status, r.started, r.finished));
672
- output_1.default.normal(this._runDetailsTrigger(r));
673
- output_1.default.normal(this._runDetailsTriggerer(r));
674
- if (r?.description)
675
- output_1.default.normal(this._runDetailsDescription(r));
676
- const started = this._runDetailsStarted(r.status, r.started, r.delayed);
677
- if (started)
678
- output_1.default.normal(started);
679
- const finished = this._runDetailsFinished(r.status, r.finished);
680
- if (finished)
681
- output_1.default.normal(finished);
682
- output_1.default.normal('');
683
- const context = this._runContext(r);
684
- if (context) {
685
- context.forEach((str) => {
686
- output_1.default.normal(str);
687
- });
688
- }
689
- output_1.default.normal('');
690
- output_1.default.normal(this._runActionsHeader());
691
- }
692
- const actions = this._runActions(r, true);
693
- actions.forEach((str) => {
694
- output_1.default.normal(str);
695
- });
696
- run = r;
697
- };
698
- run = await this._runStatusLoop(client, workspace, project, pipelineId, runId, (run) => {
699
- totalFetchesCount += 1;
700
- draw(run);
701
- if (noWait) {
702
- output_1.default.exitNormal();
703
- }
704
- });
705
- if (totalFetchesCount > 1) {
706
- output_1.default.normal('');
707
- output_1.default.normal(this._runDetailsHeader());
708
- output_1.default.normal(this._runDetailsStatus(run.status, run.started, run.finished));
709
- const started = this._runDetailsStarted(run.status, run.started, run.delayed);
710
- if (started)
711
- output_1.default.normal(started);
712
- const finished = this._runDetailsFinished(run.status, run.finished);
713
- if (finished)
714
- output_1.default.normal(finished);
715
- }
716
- output_1.default.exitNormal();
717
- }
718
- static async _actionStatusLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange) {
719
- let lastAction = null;
720
- const fetchAction = async () => {
721
- return await client.getPipelineRunActionExecution(workspace, project, pipelineId, runId, actionExecutionId);
722
- };
723
- let type;
724
- let name;
725
- let status;
726
- let oldStatus = null;
727
- let started;
728
- let finished;
729
- let logs = [];
730
- let changed;
731
- let shouldCancel = false;
732
- const cancel = () => {
733
- shouldCancel = true;
734
- };
735
- onChange(null, cancel);
736
- for (;;) {
737
- if (shouldCancel)
738
- return lastAction;
739
- const a = await fetchAction();
740
- started = null;
741
- if (a.start_date)
742
- started = new Date(a.start_date);
743
- finished = null;
744
- if (a.finish_date)
745
- finished = new Date(a.finish_date);
746
- status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
747
- name = a.action?.name || '';
748
- const originalType = a.action?.type || pipeline_1.PIPELINE_ACTION_TYPE.BUILD;
749
- type = originalType;
750
- if (pipeline_1.PIPELINE_ACTION_NAME[originalType]) {
751
- type = pipeline_1.PIPELINE_ACTION_NAME[originalType];
752
- }
753
- if (a.log)
754
- logs = a.log;
755
- changed = !oldStatus || status !== oldStatus;
756
- lastAction = {
757
- id: actionExecutionId,
758
- status,
759
- started,
760
- finished,
761
- name,
762
- type,
763
- changed,
764
- logs,
765
- };
766
- onChange(lastAction, null);
767
- oldStatus = status;
768
- if ([
769
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
770
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
771
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
772
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
773
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
774
- ].includes(status)) {
775
- break;
776
- }
777
- await (0, utils_1.sleep)(3000);
778
- }
779
- return lastAction;
780
- }
781
- static async _runStatusLoop(client, workspace, project, pipelineId, runId, onChange) {
782
- let lastRun;
783
- const fetchRun = async () => {
784
- return await client.getPipelineRun(workspace, project, pipelineId, runId);
785
- };
786
- let status;
787
- let started;
788
- let finished = null;
789
- let delayed = null;
790
- let trigger;
791
- let creator = 'Unknown';
792
- let description = '';
793
- let refresh = false;
794
- let clearCache = false;
795
- let priority = pipeline_1.PIPELINE_PRIORITY.NORMAL;
796
- let context = null;
797
- let actions = [];
798
- for (;;) {
799
- const run = await fetchRun();
800
- started = new Date(run.start_date || new Date());
801
- trigger = run.triggered_on || pipeline_1.PIPELINE_RUN_TRIGGER.CLICK;
802
- status = run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
803
- if (run.creator) {
804
- if (run.creator.name)
805
- creator = run.creator.name;
806
- else if (run.creator.email)
807
- creator = run.creator.email;
808
- }
809
- if (run.finish_date)
810
- finished = new Date(run.finish_date);
811
- if (run.comment)
812
- description = run.comment;
813
- if (run.priority)
814
- priority = run.priority;
815
- if (run.delay_until)
816
- delayed = new Date(run.delay_until);
817
- if (run.refresh)
818
- refresh = true;
819
- if (run.clear_cache)
820
- clearCache = true;
821
- if (run.branch) {
822
- if (!context)
823
- context = {};
824
- context['Branch'] = run.branch.name;
825
- }
826
- if (run.tag) {
827
- if (!context)
828
- context = {};
829
- context['Tag'] = run.tag.name;
830
- }
831
- if (run.pull_request) {
832
- if (!context)
833
- context = {};
834
- context['Pull request'] = run.pull_request.name;
835
- }
836
- if (run.to_revision) {
837
- if (!context)
838
- context = {};
839
- context['Revision'] = `#${run.to_revision.revision.substring(0, 7)}`;
840
- if (run.to_revision.message)
841
- context['Revision'] += `: ${run.to_revision.message}`;
842
- }
843
- if (run.environment) {
844
- if (!context)
845
- context = {};
846
- context['Environment'] = run.environment.identifier;
847
- }
848
- if (run.package && run.package_version) {
849
- if (!context)
850
- context = {};
851
- context['Package'] =
852
- `${run.package.identifier}:${run.package_version.version}`;
853
- }
854
- if (run.action_executions) {
855
- const old = actions;
856
- actions = (run.action_executions || []).map((a) => {
857
- const originalType = a.action?.type ||
858
- pipeline_1.PIPELINE_ACTION_TYPE.BUILD;
859
- let type = originalType;
860
- if (pipeline_1.PIPELINE_ACTION_NAME[originalType]) {
861
- type = pipeline_1.PIPELINE_ACTION_NAME[originalType];
862
- }
863
- const name = a.action?.name || '';
864
- const id = a.action_execution_id;
865
- const status = a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
866
- let started = null;
867
- if (a.start_date)
868
- started = new Date(a.start_date);
869
- let finished = null;
870
- if (a.finish_date)
871
- finished = new Date(a.finish_date);
872
- const oldAction = old.find((o) => o.id === id);
873
- const changed = !oldAction || oldAction.status !== status;
874
- const action = {
875
- type,
876
- name,
877
- id,
878
- status,
879
- started,
880
- finished,
881
- changed,
882
- };
883
- return action;
884
- });
885
- }
886
- lastRun = {
887
- creator,
888
- description,
889
- started,
890
- status,
891
- trigger,
892
- finished,
893
- clearCache,
894
- refresh,
895
- priority,
896
- delayed,
897
- context,
898
- actions,
899
- };
900
- onChange(lastRun);
901
- if ([
902
- pipeline_1.PIPELINE_RUN_STATUS.FAILED,
903
- pipeline_1.PIPELINE_RUN_STATUS.SKIPPED,
904
- pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED,
905
- pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL,
906
- pipeline_1.PIPELINE_RUN_STATUS.TERMINATED,
907
- ].includes(status)) {
908
- break;
909
- }
910
- await (0, utils_1.sleep)(3000);
911
- }
912
- return lastRun;
913
- }
914
- }
915
- exports.default = OutputPipeline;