appcenter-cli
Version:
Command line tool for Visual Studio App Center
149 lines (148 loc) • 8.14 kB
JavaScript
;
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) {
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 });
const commandline_1 = require("../../../util/commandline");
const interaction_1 = require("../../../util/interaction");
const distribute_util_1 = require("../lib/distribute-util");
const util_1 = require("util");
const debug = require("debug")("appcenter-cli:commands:distribute:releases:add-destination");
const ValidDestinationTypes = ["store", "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 release ${releaseId} to 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 ${releaseId} to ${this.destinationType} '${this.destination}' 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 === "store") {
yield interaction_1.out.progress(`Distributing release to store ${this.destination}...`, this.addStoreToRelease(client, releaseId));
}
else 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));
}
});
}
addStoreToRelease(client, releaseId) {
return __awaiter(this, void 0, void 0, function* () {
const store = yield interaction_1.out.progress("Fetching store information...", distribute_util_1.getExternalStoreToDistributeRelease({
client,
app: this.app,
storeName: this.destination,
releaseId,
}));
yield client.releases.addStore(releaseId, this.app.ownerName, this.app.appName, store.id, {
onResponse: (rawResponse, _flatResponse, _error) => this.handleAddDestinationResponse(rawResponse),
});
});
}
addTesterToRelease(client, releaseId) {
return __awaiter(this, void 0, void 0, function* () {
yield client.releases.addTesters(releaseId, this.app.ownerName, this.app.appName, this.destination, {
mandatoryUpdate: this.mandatory,
notifyTesters: !this.silent,
onResponse: (rawResponse, _flatResponse, _error) => this.handleAddDestinationResponse(rawResponse),
});
});
}
handleAddDestinationResponse(response) {
var _a;
if (response.status >= 200 && response.status < 400) {
return;
}
else if (response.status === 404) {
throw commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Could not find release ${this.releaseId}`);
}
else if (response.status === 400 && ((_a = response.parsedBody) === null || _a === void 0 ? void 0 : _a.message)) {
throw commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, response.parsedBody.message);
}
else {
debug(`Failed to distribute the release - ${util_1.inspect(response.parsedBody)}`);
const extraInfo = response.status ? `: ${response.status}` : "";
throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `Could not add ${this.destinationType} ${this.destination} to release ${this.releaseId}${extraInfo}`);
}
}
};
__decorate([
commandline_1.help("The ID of the release"),
commandline_1.shortName("r"),
commandline_1.longName("release-id"),
commandline_1.required,
commandline_1.hasArg
], AddDestinationCommand.prototype, "releaseId", void 0);
__decorate([
commandline_1.help("The type of destination: [" + 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("The name of the store or group, or the email of the tester"),
commandline_1.shortName("d"),
commandline_1.longName("destination"),
commandline_1.required,
commandline_1.hasArg
], AddDestinationCommand.prototype, "destination", void 0);
__decorate([
commandline_1.help("Whether the release is mandatory for the testers (Not used for stores)"),
commandline_1.shortName("m"),
commandline_1.longName("mandatory")
], AddDestinationCommand.prototype, "mandatory", void 0);
__decorate([
commandline_1.help("If set, do not send a notification to the testers (Not used for stores)"),
commandline_1.shortName("s"),
commandline_1.longName("silent")
], AddDestinationCommand.prototype, "silent", void 0);
AddDestinationCommand = __decorate([
commandline_1.help("Distribute an existing release to an additional destination")
], AddDestinationCommand);
exports.default = AddDestinationCommand;