UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

103 lines (102 loc) 5.42 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SymbolType = void 0; const commandline_1 = require("../../../util/commandline"); const util_1 = require("util"); const azure_blob_upload_helper_1 = require("./azure-blob-upload-helper"); // eventually we may want to support UWP here var SymbolType; (function (SymbolType) { SymbolType["AndroidProGuard"] = "AndroidProguard"; SymbolType["Apple"] = "Apple"; SymbolType["Breakpad"] = "Breakpad"; SymbolType["UWP"] = "UWP"; })(SymbolType = exports.SymbolType || (exports.SymbolType = {})); class SymbolsUploadingHelper { constructor(client, app, debug) { this.client = client; this.app = app; this.debug = debug; } uploadSymbolsArtifact(artifactPath, symbolType) { return __awaiter(this, void 0, void 0, function* () { // executing API request to get an upload URL const uploadingBeginRequestResult = yield this.executeSymbolsUploadingBeginRequest(this.client, this.app, symbolType); // uploading const symbolUploadId = uploadingBeginRequestResult.symbolUploadId; try { // putting ZIP to the specified URL const uploadUrl = uploadingBeginRequestResult.uploadUrl; yield new azure_blob_upload_helper_1.default().upload(uploadUrl, artifactPath); // sending 'committed' API request to finish uploading yield this.executeSymbolsUploadingEndRequest(this.client, this.app, symbolUploadId, "committed"); } catch (error) { // uploading failed, aborting upload request yield this.abortUploadingRequest(this.client, this.app, symbolUploadId); throw error; } }); } executeSymbolsUploadingBeginRequest(client, app, symbolType) { return __awaiter(this, void 0, void 0, function* () { this.debug("Executing API request to get uploading URL"); try { return yield client.symbolUploads.create(app.ownerName, app.appName, symbolType); } catch (error) { this.debug("Analyzing upload start request response status code"); const uploadingBeginStatusCode = error.response.statusCode; const uploadingBeginStatusMessage = error.response.statusMessage; if (uploadingBeginStatusCode >= 400) { throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `the symbol upload begin API request was rejected: HTTP ${uploadingBeginStatusCode} - ${uploadingBeginStatusMessage}`); } else { this.debug(`Failed to start the symbol uploading - ${util_1.inspect(error)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, "failed to start the symbol uploading"); } } }); } executeSymbolsUploadingEndRequest(client, app, symbolUploadId, desiredStatus) { return __awaiter(this, void 0, void 0, function* () { this.debug(`Finishing symbols uploading with desired status: ${desiredStatus}`); try { return yield client.symbolUploads.complete(symbolUploadId, app.ownerName, app.appName, desiredStatus); } catch (error) { this.debug("Analyzing upload end request response status code"); const uploadingEndStatusCode = error.response.statusCode; const uploadingEndStatusMessage = error.response.statusMessage; if (uploadingEndStatusCode >= 400) { throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `the symbol upload end API request was rejected: HTTP ${uploadingEndStatusCode} - ${uploadingEndStatusMessage}`); } else { this.debug(`Failed to finalize the symbol upload - ${util_1.inspect(error)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to finalize the symbol upload with status`); } } }); } abortUploadingRequest(client, app, symbolUploadId) { return __awaiter(this, void 0, void 0, function* () { this.debug("Uploading failed, aborting upload request"); try { return yield this.executeSymbolsUploadingEndRequest(client, app, symbolUploadId, "aborted"); } catch (ex) { this.debug("Failed to correctly abort the uploading request"); } }); } } exports.default = SymbolsUploadingHelper;