UNPKG

@devicecloud.dev/dcd

Version:

Better cloud maestro testing

139 lines (138 loc) • 5.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const constants_1 = require("../constants"); const api_gateway_1 = require("../gateways/api-gateway"); const methods_1 = require("../methods"); class Status extends core_1.Command { static description = 'Get the status of an upload by name or upload ID'; static enableJsonFlag = true; static examples = [ '<%= config.bin %> <%= command.id %> --name my-upload-name', '<%= config.bin %> <%= command.id %> --upload-id 123e4567-e89b-12d3-a456-426614174000 --json', ]; static flags = { apiKey: constants_1.flags.apiKey, apiUrl: constants_1.flags.apiUrl, json: core_1.Flags.boolean({ description: 'output in json format', }), name: core_1.Flags.string({ description: 'Name of the upload to check status for', exclusive: ['upload-id'], }), 'upload-id': core_1.Flags.string({ description: 'UUID of the upload to check status for', exclusive: ['name'], }), }; // eslint-disable-next-line complexity async run() { const { flags } = await this.parse(Status); const { apiKey: apiKeyFlag, apiUrl, json, name, 'upload-id': uploadId, } = flags; const apiKey = apiKeyFlag || process.env.DEVICE_CLOUD_API_KEY; if (!apiKey) { this.error('API key is required. Please provide it via --api-key flag or DEVICE_CLOUD_API_KEY environment variable.'); return; } if (name && uploadId) { this.error('Cannot provide both --name and --upload-id. These options are mutually exclusive.'); return; } if (!name && !uploadId) { this.error('Either --name or --upload-id must be provided'); return; } let lastError = null; let status = null; for (let attempt = 1; attempt <= 5; attempt++) { try { status = (await api_gateway_1.ApiGateway.getUploadStatus(apiUrl, apiKey, { name, uploadId, })); break; } catch (error) { lastError = error; if (attempt < 5) { this.log(`Network error on attempt ${attempt}/5. Retrying...`); await new Promise((resolve) => { setTimeout(resolve, 1000 * attempt); }); } } } if (!status) { const errorMessage = `Failed to get status after 5 attempts. Check your network. Last error: ${lastError?.message || 'Unknown error'}`; if (json) { return { attempts: 5, error: errorMessage, status: 'FAILED', tests: [], }; } this.error(errorMessage); return; } try { if (json) { return status; } this.log('\nšŸ“Š Upload Status'); this.log('═'.repeat(80)); // Display overall status const overallSymbol = this.getStatusSymbol(status.status); this.log(`${overallSymbol} Status: ${status.status}`); if (status.uploadId) { this.log(`šŸ†” Upload ID: ${status.uploadId}`); } if (status.appBinaryId) { this.log(`šŸ“± Binary ID: ${status.appBinaryId}`); } if (status.consoleUrl) { this.log(`šŸ”— Console: ${status.consoleUrl}`); } if (status.tests.length > 0) { this.log('\nšŸ“‹ Test Results'); this.log('─'.repeat(80)); for (const item of status.tests) { const symbol = this.getStatusSymbol(item.status); this.log(`${symbol} ${item.name}`); this.log(` Status: ${item.status}`); if (item.status === 'FAILED' && item.failReason) { this.log(` Fail reason: ${item.failReason}`); } if (item.durationSeconds) { this.log(` Duration: ${(0, methods_1.formatDurationSeconds)(item.durationSeconds)}`); } this.log(''); } } } catch (error) { this.error(`Failed to get status: ${error.message}`); } } getStatusSymbol(status) { switch (status) { case 'PASSED': { return 'āœ“'; } case 'FAILED': { return 'āœ—'; } case 'CANCELLED': { return '⊘'; } case 'PENDING': { return '⋯'; } default: { return '?'; } } } } exports.default = Status;