bdy 1.12.10-dev-pipeline-run → 1.12.10-stage

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 (44) hide show
  1. package/distTs/package.json +13 -12
  2. package/distTs/src/agent.js +302 -0
  3. package/distTs/src/api/agent.js +99 -0
  4. package/distTs/src/api/buddy.js +139 -0
  5. package/distTs/src/api/socket.js +159 -0
  6. package/distTs/src/cfg.js +234 -0
  7. package/distTs/src/command/config.js +17 -0
  8. package/distTs/src/command/http.js +30 -0
  9. package/distTs/src/command/start.js +28 -0
  10. package/distTs/src/command/tcp.js +30 -0
  11. package/distTs/src/command/tls.js +30 -0
  12. package/distTs/src/command/ut/upload.js +17 -7
  13. package/distTs/src/command/vt/compare.js +2 -2
  14. package/distTs/src/command/vt/exec.js +4 -3
  15. package/distTs/src/command/vt/storybook.js +4 -3
  16. package/distTs/src/format.js +0 -19
  17. package/distTs/src/index.js +0 -2
  18. package/distTs/src/input.js +17 -139
  19. package/distTs/src/output/interactive/tunnel.js +860 -0
  20. package/distTs/src/output/noninteractive/agent/tunnels.js +43 -0
  21. package/distTs/src/output/noninteractive/config/tunnel.js +65 -0
  22. package/distTs/src/output/noninteractive/config/tunnels.js +18 -0
  23. package/distTs/src/output/noninteractive/tunnel.js +59 -0
  24. package/distTs/src/output.js +0 -6
  25. package/distTs/src/server/cert.js +52 -0
  26. package/distTs/src/server/http1.js +75 -0
  27. package/distTs/src/server/http2.js +78 -0
  28. package/distTs/src/server/sftp.js +497 -0
  29. package/distTs/src/server/ssh.js +446 -0
  30. package/distTs/src/server/tls.js +41 -0
  31. package/distTs/src/ssh/client.js +197 -0
  32. package/distTs/src/texts.js +7 -100
  33. package/distTs/src/tunnel/html/503.html +338 -0
  34. package/distTs/src/tunnel/tunnel.js +31 -13
  35. package/distTs/src/tunnel.js +656 -0
  36. package/distTs/src/unitTest/ci.js +12 -8
  37. package/distTs/src/utils.js +17 -13
  38. package/distTs/src/visualTest/context.js +4 -4
  39. package/distTs/src/visualTest/exec.js +0 -24
  40. package/distTs/src/visualTest/resources.js +18 -8
  41. package/package.json +13 -12
  42. package/distTs/src/api/client.js +0 -112
  43. package/distTs/src/command/pipeline/run.js +0 -136
  44. package/distTs/src/command/pipeline.js +0 -12
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getCiInfo = getCiInfo;
4
- const ciInfo_1 = require("../types/ciInfo");
5
- const ci_1 = require("../visualTest/ci");
7
+ const ci_info_1 = require("@buddy-works/ci-info");
8
+ const ci_info_2 = require("@buddy-works/ci-info");
6
9
  const uuid_1 = require("uuid");
10
+ const output_1 = __importDefault(require("../output"));
7
11
  function getGithubRefType() {
8
12
  const ref = process.env.GITHUB_REF || '';
9
13
  if (ref.startsWith('refs/heads/')) {
@@ -52,7 +56,7 @@ async function getCiInfo() {
52
56
  const isGithubAction = process.env.GITHUB_ACTIONS === 'true';
53
57
  const isCircleCI = process.env.CIRCLECI === 'true';
54
58
  if (isBuddy) {
55
- const ciProvider = ciInfo_1.CI.BUDDY;
59
+ const ciProvider = ci_info_1.CI.BUDDY;
56
60
  const refType = process.env.BUDDY_RUN_REF_TYPE || '';
57
61
  const refName = process.env.BUDDY_RUN_REF || '';
58
62
  const buildId = process.env.BUDDY_RUN_HASH || '';
@@ -66,7 +70,7 @@ async function getCiInfo() {
66
70
  };
67
71
  }
68
72
  if (isGithubAction) {
69
- const ciProvider = ciInfo_1.CI.GITHUB_ACTION;
73
+ const ciProvider = ci_info_1.CI.GITHUB_ACTION;
70
74
  const refType = getGithubRefType();
71
75
  const refName = process.env.GITHUB_REF_NAME || '';
72
76
  const buildId = process.env.GITHUB_RUN_ID || '';
@@ -80,7 +84,7 @@ async function getCiInfo() {
80
84
  };
81
85
  }
82
86
  if (isCircleCI) {
83
- const ciProvider = ciInfo_1.CI.CIRCLE_CI;
87
+ const ciProvider = ci_info_1.CI.CIRCLE_CI;
84
88
  const refType = getCircleRefType();
85
89
  const refName = getCircleRefName();
86
90
  const buildId = process.env.CIRCLE_BUILD_NUM || '';
@@ -93,11 +97,11 @@ async function getCiInfo() {
93
97
  toRevision,
94
98
  };
95
99
  }
96
- const ciProvider = ciInfo_1.CI.NONE;
100
+ const ciProvider = ci_info_1.CI.NONE;
97
101
  const refType = 'BRANCH';
98
- const refName = (await (0, ci_1.getBranchName)()) || '';
102
+ const refName = (await (0, ci_info_2.getBranchName)({ logger: output_1.default.warning })) || '';
99
103
  const buildId = (0, uuid_1.v4)();
100
- const toRevision = (await (0, ci_1.getCommitHash)()) || '';
104
+ const toRevision = (await (0, ci_info_2.getCommitHash)({ logger: output_1.default.warning })) || '';
101
105
  return {
102
106
  ciProvider,
103
107
  refType,
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -29,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.getBasicCommandTls = exports.getBasicCommandHttp = exports.getBasicCommandTcp = exports.createSshHostKey = exports.getRealTargetHost = exports.isWindows = exports.isLinux = exports.isOsx = exports.isDocker = exports.sleep = exports.getLatestVersion = exports.getVersionEnv = exports.getVersionWithoutEnv = exports.getVersion = exports.getHomeDirectory = exports.newCommand = exports.formatHelp = exports.getPlatform = exports.getHostname = exports.isStringRegExp = exports.getRootDir = exports.TARGET_ONLY_PORT_REGEX = exports.TARGET_HTTP_REGEX = exports.TARGET_TCP_TLS_REGEX = exports.ApiErrorTunnelsDisabled = exports.ApiErrorWorkspaceFlagged = exports.ApiErrorTunnelLimitReached = exports.ApiErrorAgentLimitReached = exports.ApiErrorDomainRestricted = exports.ApiErrorTargetInvalid = exports.ApiErrorWrongToken = exports.ApiErrorFailedToConnect = exports.ApiErrorAgentNotFound = exports.SUGGESTED_BROWSER_VERSION = exports.DEFAULT_TIMEOUT = exports.TUNNEL_HTTP_CB_MIN_REQUESTS = exports.TUNNEL_HTTP_CB_WINDOW = exports.TUNNEL_MAX_REQUEST_SIZE_TO_SYNC = exports.TUNNEL_HTTP_LOG_MAX_REQUESTS = exports.TUNNEL_HTTP_LOG_MAX_BODY = exports.TUNNEL_HTTP_RATE_WINDOW = exports.TUNNEL_HTTP_RATE_LIMIT = void 0;
30
40
  exports.apiErrorCodeToClass = apiErrorCodeToClass;
31
41
  exports.isFile = isFile;
32
- exports.asyncWait = asyncWait;
33
42
  const node_path_1 = __importStar(require("node:path"));
34
43
  const node_fs_1 = require("node:fs");
35
44
  const texts_1 = require("./texts");
@@ -377,8 +386,3 @@ function isFile(path) {
377
386
  return false;
378
387
  }
379
388
  }
380
- async function asyncWait(ms) {
381
- return new Promise((resolve) => {
382
- setTimeout(resolve, ms);
383
- });
384
- }
@@ -5,8 +5,8 @@ exports.setExecOptions = setExecOptions;
5
5
  exports.setBrowserPath = setBrowserPath;
6
6
  exports.setCiAndCommitInfo = setCiAndCommitInfo;
7
7
  const uuid_1 = require("uuid");
8
- const ciInfo_1 = require("../types/ciInfo");
9
8
  const utils_1 = require("../utils");
9
+ const ci_info_1 = require("@buddy-works/ci-info");
10
10
  exports.cliVersion = (0, utils_1.getVersion)();
11
11
  exports.oneByOne = false;
12
12
  exports.skipDiscovery = false;
@@ -15,7 +15,7 @@ exports.token = process.env.BUDDY_VT_TOKEN || '';
15
15
  exports.buildId = process.env.SNAPSHOTS_BUILD_ID || (0, uuid_1.v4)();
16
16
  exports.cliId = (0, uuid_1.v4)();
17
17
  exports.defaultTimeout = Number(process.env.SNAPSHOTS_DEFAULT_TIMEOUT) || 60_000;
18
- exports.ci = ciInfo_1.CI.NONE;
18
+ exports.ci = ci_info_1.CI.NONE;
19
19
  exports.debug = process.env.DEBUG === '1';
20
20
  function setExecOptions(options) {
21
21
  if (options.oneByOne) {
@@ -39,14 +39,14 @@ function setCiAndCommitInfo(ciInfo) {
39
39
  exports.commit = ciInfo.commit;
40
40
  exports.baseCommit = ciInfo.baseCommit;
41
41
  exports.commitDetails = ciInfo.commitDetails;
42
- if (ciInfo.ci === ciInfo_1.CI.BUDDY) {
42
+ if (ciInfo.ci === ci_info_1.CI.BUDDY) {
43
43
  exports.pipelineId = ciInfo.pipelineId;
44
44
  exports.actionId = ciInfo.actionId;
45
45
  exports.executionId = ciInfo.executionId;
46
46
  exports.invokerId = ciInfo.invokerId;
47
47
  exports.pipelineName = ciInfo.pipelineName;
48
48
  }
49
- if (ciInfo.ci === ciInfo_1.CI.GITHUB_ACTION || ciInfo.ci === ciInfo_1.CI.CIRCLE_CI) {
49
+ if (ciInfo.ci === ci_info_1.CI.GITHUB_ACTION || ciInfo.ci === ci_info_1.CI.CIRCLE_CI) {
50
50
  exports.executionUrl = ciInfo.executionUrl;
51
51
  }
52
52
  }
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.testExec = testExec;
7
- exports.gitExec = gitExec;
8
7
  const cross_spawn_1 = require("cross-spawn");
9
8
  const output_1 = __importDefault(require("../output"));
10
9
  const texts_1 = require("../texts");
@@ -26,26 +25,3 @@ function testExec(command, arguments_) {
26
25
  });
27
26
  });
28
27
  }
29
- function gitExec(arguments_) {
30
- return new Promise((resolve, reject) => {
31
- const process = (0, cross_spawn_1.spawn)('git', arguments_, {
32
- stdio: ['ignore', 'pipe', 'pipe'],
33
- });
34
- let errorOutput = '';
35
- let output = '';
36
- process.stdout.on('data', (message) => {
37
- output += message;
38
- });
39
- process.stderr.on('data', (message) => {
40
- errorOutput += message;
41
- });
42
- process.on('close', (code) => {
43
- if (code === 0) {
44
- resolve(output);
45
- }
46
- else {
47
- reject(errorOutput);
48
- }
49
- });
50
- });
51
- }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -176,7 +186,7 @@ async function scrapeResources({ url, devices, resourceDiscoveryTimeout, cookies
176
186
  try {
177
187
  if ((status < 300 || status > 399) &&
178
188
  !contentType.startsWith('text/html')) {
179
- body = new Blob([await response.buffer()]);
189
+ body = new Blob([new Uint8Array(await response.buffer())]);
180
190
  }
181
191
  }
182
192
  catch (error) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.12.10-dev-pipeline-run",
4
+ "version": "1.12.10-stage",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -17,15 +17,16 @@
17
17
  "bdy": "distTs/bin/cli.js"
18
18
  },
19
19
  "dependencies": {
20
+ "@buddy-works/ci-info": "1.0.5",
20
21
  "@fastify/accept-negotiator": "1.1.0",
21
22
  "@fastify/cors": "9.0.1",
22
23
  "@puppeteer/browsers": "2.4.0",
23
24
  "@xhmikosr/decompress": "10.0.1",
24
25
  "basic-auth": "2.0.1",
25
26
  "chalk": "4.1.2",
26
- "cookie": "1.0.2",
27
27
  "commander": "12.1.0",
28
28
  "content-disposition": "0.5.4",
29
+ "cookie": "1.0.2",
29
30
  "cross-spawn": "7.0.6",
30
31
  "eventsource": "4.0.0",
31
32
  "fastify": "4.28.1",
@@ -60,32 +61,32 @@
60
61
  "@rollup/plugin-node-resolve": "15.3.0",
61
62
  "@rollup/plugin-replace": "6.0.1",
62
63
  "@stylistic/eslint-plugin-js": "2.9.0",
64
+ "@types/basic-auth": "1.1.8",
65
+ "@types/content-disposition": "0.5.4",
63
66
  "@types/cross-spawn": "6.0.6",
64
67
  "@types/eslint__js": "8.42.3",
68
+ "@types/jsonwebtoken": "9.0.2",
69
+ "@types/mime-db": "1.43.6",
70
+ "@types/mime-types": "2.1.4",
71
+ "@types/netmask": "2.0.5",
72
+ "@types/node-forge": "1.3.1",
73
+ "@types/path-is-inside": "1.0.2",
65
74
  "@types/picomatch": "4.0.2",
66
75
  "@types/punycode": "2.1.4",
67
- "@types/netmask": "2.0.5",
76
+ "@types/range-parser": "1.2.1",
68
77
  "@types/ssh2": "1.15.5",
69
78
  "@types/tar-stream": "3.1.3",
70
79
  "@types/terminal-kit": "2.5.6",
71
80
  "@types/uuid": "10.0.0",
72
81
  "@types/which": "3.0.4",
73
82
  "@types/ws": "8.18.0",
74
- "@types/jsonwebtoken": "9.0.2",
75
- "@types/mime-db": "1.43.6",
76
- "@types/basic-auth": "1.1.8",
77
- "@types/path-is-inside": "1.0.2",
78
- "@types/range-parser": "1.2.1",
79
- "@types/content-disposition": "0.5.4",
80
- "@types/mime-types": "2.1.4",
81
- "@types/node-forge": "1.3.1",
82
83
  "eslint": "9.13.0",
83
84
  "eslint-config-prettier": "9.1.0",
84
85
  "globals": "15.11.0",
85
86
  "prettier": "3.3.3",
86
87
  "rollup": "4.24.2",
87
88
  "rollup-plugin-natives": "0.7.8",
88
- "typescript": "5.6.3",
89
+ "typescript": "5.9.3",
89
90
  "typescript-eslint": "8.11.0"
90
91
  }
91
92
  }
@@ -1,112 +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 undici_1 = require("undici");
7
- const texts_1 = require("../texts");
8
- const logger_1 = __importDefault(require("../logger"));
9
- class ApiClient {
10
- client;
11
- token;
12
- baseUrl;
13
- constructor(baseUrl, token) {
14
- this.baseUrl = baseUrl;
15
- this.token = token;
16
- this.client = new undici_1.Client(baseUrl, {
17
- connect: {
18
- rejectUnauthorized: false,
19
- },
20
- });
21
- }
22
- async request(method, path, body, parseResponseBody = false) {
23
- const headers = {
24
- authorization: `Bearer ${this.token}`,
25
- };
26
- let bodyParsed = undefined;
27
- if (body) {
28
- headers['content-type'] = 'application/json; charset=utf-8';
29
- bodyParsed = JSON.stringify(body);
30
- }
31
- const opts = {
32
- method,
33
- path,
34
- headers,
35
- body: bodyParsed,
36
- };
37
- let status;
38
- let responseBody;
39
- logger_1.default.debug(`REST API ${method} ${this.baseUrl.protocol}//${this.baseUrl.host}${path}`);
40
- logger_1.default.debug(headers);
41
- logger_1.default.debug(body);
42
- try {
43
- const r = await this.client.request(opts);
44
- status = r.statusCode;
45
- responseBody = r.body;
46
- logger_1.default.debug(`REST API RESPONSE STATUS: ${status}`);
47
- }
48
- catch (err) {
49
- logger_1.default.debug('REST API RESPONSE ERROR');
50
- logger_1.default.debug(err);
51
- throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
52
- }
53
- if (status === 404) {
54
- throw new Error(texts_1.ERR_REST_API_RESOURCE_NOT_FOUND);
55
- }
56
- if (status === 401) {
57
- throw new Error(texts_1.ERR_REST_API_WRONG_TOKEN);
58
- }
59
- if (status === 403) {
60
- throw new Error(texts_1.ERR_REST_API_RATE_LIMIT);
61
- }
62
- if (status === 400) {
63
- let json;
64
- try {
65
- json = await responseBody.json();
66
- }
67
- catch (err) {
68
- logger_1.default.debug('REST API PARSED RESPONSE ERROR:');
69
- logger_1.default.debug(err);
70
- throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
71
- // do nothing
72
- }
73
- logger_1.default.debug('REST API PARSED RESPONSE:');
74
- logger_1.default.debug(json);
75
- if (json.errors && json.errors[0] && json.errors[0].message) {
76
- throw new Error(json.errors[0].message);
77
- }
78
- throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
79
- }
80
- if (status === 200) {
81
- if (parseResponseBody) {
82
- try {
83
- const b = await responseBody.json();
84
- logger_1.default.debug('REST API PARSED RESPONSE:');
85
- logger_1.default.debug(b);
86
- return b;
87
- }
88
- catch (err) {
89
- logger_1.default.debug('REST API PARSED RESPONSE ERROR:');
90
- logger_1.default.debug(err);
91
- throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
92
- }
93
- }
94
- else {
95
- return null;
96
- }
97
- }
98
- else {
99
- throw new Error(texts_1.ERR_REST_API_GENERAL_ERROR);
100
- }
101
- }
102
- async getPipelineByIdentifier(workspace, project, identifier) {
103
- return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/identifiers?project=${encodeURIComponent(project)}&pipeline=${encodeURIComponent(identifier)}`, null, true);
104
- }
105
- async getPipelineRun(workspace, project, pipelineId, executionId) {
106
- return await this.request('GET', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions/${encodeURIComponent(executionId)}`, null, true);
107
- }
108
- async postPipelineRun(workspace, project, pipelineId, body) {
109
- return await this.request('POST', `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/pipelines/${encodeURIComponent(pipelineId)}/executions`, body, true);
110
- }
111
- }
112
- exports.default = ApiClient;
@@ -1,136 +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 utils_1 = require("../../utils");
7
- const texts_1 = require("../../texts");
8
- const output_1 = __importDefault(require("../../output"));
9
- const input_1 = __importDefault(require("../../input"));
10
- const client_1 = __importDefault(require("../../api/client"));
11
- const format_1 = __importDefault(require("../../format"));
12
- const commandPipelineRun = (0, utils_1.newCommand)('run', texts_1.DESC_COMMAND_PIPELINE_RUN);
13
- commandPipelineRun.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
14
- commandPipelineRun.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
15
- commandPipelineRun.option('--region <region>', texts_1.OPTION_REST_API_REGION);
16
- commandPipelineRun.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
- commandPipelineRun.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
- commandPipelineRun.option('-b, --branch <branch>', texts_1.OPTION_PIPELINE_RUN_BRANCH);
19
- commandPipelineRun.option('-t, --tag <tag>', texts_1.OPTION_PIPELINE_RUN_TAG);
20
- commandPipelineRun.option('-pr, --pull-request <pull request>', texts_1.OPTION_PIPELINE_RUN_PULL_REQUEST);
21
- commandPipelineRun.option('-r, --revision <revision>', texts_1.OPTION_PIPELINE_RUN_REVISION);
22
- commandPipelineRun.option('--comment <comment>', texts_1.OPTION_PIPELINE_RUN_COMMENT);
23
- commandPipelineRun.option('-f, --refresh', texts_1.OPTION_PIPELINE_RUN_REFRESH);
24
- commandPipelineRun.option('-c, --clear-cache', texts_1.OPTION_PIPELINE_RUN_CLEAR_CACHE);
25
- commandPipelineRun.option('--priority <priority>', texts_1.OPTION_PIPELINE_RUN_PRIORITY);
26
- commandPipelineRun.option('-v, --variable <variables...>', texts_1.OPTION_PIPELINE_RUN_VAR);
27
- commandPipelineRun.option('-ve, --variable-encrypted <variables...>', texts_1.OPTION_PIPELINE_RUN_VAR);
28
- commandPipelineRun.option('--delay <date>', texts_1.OPTION_PIPELINE_RUN_DELAY);
29
- commandPipelineRun.option('--action <actions...>', texts_1.OPTION_PIPELINE_RUN_ACTION);
30
- commandPipelineRun.option('--wait', texts_1.OPTION_PIPELINE_RUN_WAIT);
31
- commandPipelineRun.option('--wait-time <minutes>', texts_1.OPTION_PIPELINE_RUN_WAIT_TIMEOUT);
32
- commandPipelineRun.argument('<identifier>', texts_1.OPTION_PIPELINE_RUN_ARGUMENT);
33
- commandPipelineRun.action(async (identifier, options) => {
34
- const token = input_1.default.restApiToken(options.token);
35
- const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
36
- const workspace = input_1.default.restApiWorkspace(options.workspace);
37
- const project = input_1.default.restApiProject(options.project);
38
- const client = new client_1.default(baseUrl, token);
39
- const data = await client.getPipelineByIdentifier(workspace, project, identifier);
40
- if (!data || !data.domain) {
41
- output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WORKSPACE_NOT_FOUND);
42
- }
43
- if (!data.project_identifier) {
44
- output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_PROJECT_NOT_FOUND);
45
- }
46
- if (!data.pipeline_id) {
47
- output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_NOT_FOUND);
48
- }
49
- const body = {};
50
- if (options.branch) {
51
- body.branch = {
52
- name: options.branch,
53
- };
54
- }
55
- if (options.tag) {
56
- body.tag = {
57
- name: options.tag,
58
- };
59
- }
60
- if (options.pullRequest) {
61
- body.pull_request = {
62
- name: `pull/${options.pullRequest}`,
63
- };
64
- }
65
- if (options.revision) {
66
- body.to_revision = {
67
- revision: options.revision,
68
- };
69
- }
70
- if (options.comment) {
71
- body.comment = options.comment;
72
- }
73
- if (options.refresh) {
74
- body.refresh = true;
75
- }
76
- if (options.clearCache) {
77
- body.clear_cache = true;
78
- }
79
- const priority = input_1.default.pipelineRunPriority(options.priority);
80
- if (priority) {
81
- body.priority = priority;
82
- }
83
- body.variables = [];
84
- if (options.variable) {
85
- body.variables = body.variables.concat(input_1.default.pipelineRunVariable(options.variable, false));
86
- }
87
- if (options.variableEncrypted) {
88
- body.variables = body.variables.concat(input_1.default.pipelineRunVariable(options.variableEncrypted, true));
89
- }
90
- const delay = input_1.default.pipelineRunDelay(options.delay);
91
- if (delay) {
92
- body.delay_until = delay;
93
- }
94
- const actions = input_1.default.pipelineRunAction(options.action);
95
- if (actions) {
96
- body.actions_to_run = actions;
97
- }
98
- const result = await client.postPipelineRun(workspace, project, data.pipeline_id, body);
99
- if (options.wait) {
100
- const minutes = input_1.default.pipelineRunWaitTime(options.waitTime);
101
- const start = Date.now();
102
- output_1.default.normal((0, texts_1.TXT_PIPELINE_RUN_WAIT)(minutes));
103
- let fetchCounter = 1;
104
- const ts1 = setTimeout(() => {
105
- output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WAIT_TIMEOUT);
106
- }, minutes * 60 * 1000);
107
- const ts2 = setInterval(async () => {
108
- output_1.default.clearPreviousLine();
109
- output_1.default.normal((0, texts_1.TXT_PIPELINE_RUN_STILL_WAITING)(formatWaitTime(start)));
110
- if (fetchCounter >= 3) {
111
- const pip = await client.getPipelineRun(workspace, project, data.pipeline_id, result.id);
112
- if (!['INPROGRESS', 'ENQUEUED', 'TERMINATING'].includes(pip.status)) {
113
- clearTimeout(ts1);
114
- clearInterval(ts2);
115
- output_1.default.clearPreviousLine();
116
- if (pip.status === 'SUCCESSFUL') {
117
- output_1.default.exitSuccess((0, texts_1.TXT_PIPELINE_RUN_FINISH_SUCCESSFULLY)(result.html_url));
118
- }
119
- else {
120
- output_1.default.exitError((0, texts_1.TXT_PIPELINE_RUN_FINISH_FAILED)(pip.status, result.html_url));
121
- }
122
- }
123
- fetchCounter = 0;
124
- }
125
- fetchCounter += 1;
126
- }, 1000);
127
- }
128
- else {
129
- output_1.default.exitSuccess((0, texts_1.TXT_PIPELINE_RUN_SUCCESS)(result.html_url));
130
- }
131
- });
132
- const formatWaitTime = (start) => {
133
- const elapsed = Math.floor((Date.now() - start) / 1000);
134
- return format_1.default.pipelineRunWaitTime(elapsed);
135
- };
136
- exports.default = commandPipelineRun;
@@ -1,12 +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 utils_1 = require("../utils");
7
- const texts_1 = require("../texts");
8
- const run_1 = __importDefault(require("./pipeline/run"));
9
- const commandPipeline = (0, utils_1.newCommand)('pipeline', texts_1.DESC_COMMAND_PIPELINE);
10
- commandPipeline.alias('pip');
11
- commandPipeline.addCommand(run_1.default);
12
- exports.default = commandPipeline;