UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

116 lines (115 loc) 6.49 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const commandline_1 = require("../../../util/commandline"); const apis_1 = require("../../../util/apis"); const interaction_1 = require("../../../util/interaction"); const util_1 = require("util"); const distribute_util_1 = require("../lib/distribute-util"); const debug = require("debug")("appcenter-cli:commands:distribute:releases:add-destination"); const ValidDestinationTypes = ["group", "tester"]; let AddDestinationCommand = class AddDestinationCommand extends commandline_1.AppCommand { run(client) { return __awaiter(this, void 0, void 0, function* () { const releaseId = Number(this.releaseId); if (!Number.isSafeInteger(releaseId) || releaseId <= 0) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `${this.releaseId} is not a valid release id`); } if (ValidDestinationTypes.indexOf(this.destinationType) === -1) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `${this.destinationType} is not a valid destination type. Available types are: ${ValidDestinationTypes.join(", ")}`); } debug(`Distributing destination ${this.destination} of type ${this.destinationType} to release ${releaseId}`); try { yield this.addDestination(client, releaseId); } catch (error) { return error; } interaction_1.out.text(`Distribution of ${this.mandatory ? "mandatory " : ""}release ${this.releaseId} to ${this.destinationType} was successful ${this.silent ? "without" : "with"} notification`); return commandline_1.success(); }); } addDestination(client, releaseId) { return __awaiter(this, void 0, void 0, function* () { if (this.destinationType === "group") { const distributionGroup = yield interaction_1.out.progress(`Fetching distribution group information ...`, distribute_util_1.getDistributionGroup({ client, releaseId, app: this.app, destination: this.destination, destinationType: this.destinationType })); yield interaction_1.out.progress(`Distributing release to group ${this.destination}...`, distribute_util_1.addGroupToRelease({ client, releaseId, distributionGroup, app: this.app, destination: this.destination, destinationType: this.destinationType, mandatory: this.mandatory, silent: this.silent })); } else if (this.destinationType === "tester") { yield interaction_1.out.progress(`Distributing release to tester ${this.destination}...`, this.addTesterToRelease(client, releaseId)); } }); } addTesterToRelease(client, releaseId) { return __awaiter(this, void 0, void 0, function* () { const { result, response } = yield apis_1.clientRequest((cb) => __awaiter(this, void 0, void 0, function* () { client.releases.addTesters(releaseId, this.app.ownerName, this.app.appName, this.destination, { mandatoryUpdate: this.mandatory, notifyTesters: !this.silent }, cb); })); if (response.statusCode >= 200 && response.statusCode < 400) { return result; } else if (response.statusCode === 404) { throw commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Could not find release ${releaseId}`); } else { debug(`Failed to distribute the release - ${util_1.inspect(result)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `Could not add ${this.destinationType} ${this.destination} to release ${releaseId}`); } }); } }; __decorate([ commandline_1.help("Release ID"), commandline_1.shortName("r"), commandline_1.longName("release-id"), commandline_1.required, commandline_1.hasArg ], AddDestinationCommand.prototype, "releaseId", void 0); __decorate([ commandline_1.help("Destination Type: " + ValidDestinationTypes.join(", ")), commandline_1.shortName("t"), commandline_1.longName("type"), commandline_1.required, commandline_1.hasArg ], AddDestinationCommand.prototype, "destinationType", void 0); __decorate([ commandline_1.help("Destination: The name of the group or the email of a tester"), commandline_1.shortName("d"), commandline_1.longName("destination"), commandline_1.required, commandline_1.hasArg ], AddDestinationCommand.prototype, "destination", void 0); __decorate([ commandline_1.help("Mandatory"), commandline_1.shortName("m"), commandline_1.longName("mandatory") ], AddDestinationCommand.prototype, "mandatory", void 0); __decorate([ commandline_1.help("Silent"), commandline_1.shortName("s"), commandline_1.longName("silent") ], AddDestinationCommand.prototype, "silent", void 0); AddDestinationCommand = __decorate([ commandline_1.help("Distributes an existing release to an additional destination") ], AddDestinationCommand); exports.default = AddDestinationCommand;