UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

58 lines (57 loc) 3.06 kB
"use strict"; 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 apis_1 = require("../../../util/apis"); const commandline_1 = require("../../../util/commandline"); const util_1 = require("util"); const debug = require("debug")("appcenter-cli:commands:distribute"); function getDistributionGroup(options) { return __awaiter(this, void 0, void 0, function* () { const { client, app, destination, destinationType, releaseId } = options; try { const { result } = yield apis_1.clientRequest((cb) => __awaiter(this, void 0, void 0, function* () { client.distributionGroups.get(app.ownerName, app.appName, destination, cb); })); return result; } catch (error) { if (error.statusCode === 404) { throw commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Could not find group ${destination}`); } else { debug(`Failed to distribute the release - ${util_1.inspect(error)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `Could not add ${destinationType} ${destination} to release ${releaseId}`); } } }); } exports.getDistributionGroup = getDistributionGroup; function addGroupToRelease(options) { return __awaiter(this, void 0, void 0, function* () { const { client, app, distributionGroup, releaseId, mandatory, silent, destination, destinationType } = options; const { result, response } = yield apis_1.clientRequest((cb) => __awaiter(this, void 0, void 0, function* () { client.releases.addDistributionGroup(releaseId, app.ownerName, app.appName, distributionGroup.id, { mandatoryUpdate: mandatory, notifyTesters: !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 ${destinationType} ${destination} to release ${releaseId}`); } }); } exports.addGroupToRelease = addGroupToRelease;