appcenter-cli
Version:
Command line tool for Visual Studio App Center
113 lines (93 loc) • 4.5 kB
text/typescript
import { AppCommand, CommandArgs, CommandResult, help, failure, ErrorCodes, success, required, shortName, longName, hasArg } from "../../util/commandline";
import { AppCenterClient, models, clientRequest } from "../../util/apis";
import { out } from "../../util/interaction";
import { inspect } from "util";
import * as chalk from "chalk";
import { isValidRollout, isValidRange } from "./lib/validation-utils";
const debug = require("debug")("appcenter-cli:commands:codepush:promote");
export default class CodePushPromoteCommand extends AppCommand {
public destinationDeploymentName: string;
public sourceDeploymentName: string;
public description: string;
public label: string;
public isMandatory: boolean;
public isDisabled: boolean;
public disableDuplicateReleaseError: boolean;
public rollout: string;
public targetBinaryRange: string;
constructor(args: CommandArgs) {
super(args);
}
async run(client: AppCenterClient): Promise<CommandResult> {
const app = this.app;
const rollout = Number(this.rollout);
if (this.rollout != null && (!Number.isSafeInteger(rollout) || !isValidRollout(rollout))) {
return failure(ErrorCodes.Exception, `Rollout value should be integer value between ${chalk.bold("0")} or ${chalk.bold("100")}.`);
}
if (this.targetBinaryRange != null && !isValidRange(this.targetBinaryRange)) {
return failure(ErrorCodes.Exception, "Invalid binary version(s) for a release.");
}
const promote : models.CodePushReleasePromote = {
targetBinaryRange: this.targetBinaryRange,
description: this.description,
label: this.label,
isDisabled: this.isDisabled,
isMandatory: this.isMandatory
};
if (this.rollout != null) {
promote.rollout = rollout;
}
try {
debug("Promote CodePush release");
await out.progress("Promoting CodePush release...", clientRequest<models.CodePushRelease>(
(cb) => client.codePushDeployments.promote(this.sourceDeploymentName, this.destinationDeploymentName, app.ownerName,
app.appName, { release: promote }, cb)));
} catch (error) {
if (error.response.statusCode === 409 && this.disableDuplicateReleaseError) {
// 409 (Conflict) status code means that uploaded package is identical
// to the contents of the specified deployment's current release
console.warn(chalk.yellow("[Warning] " + error.response.body));
return success();
} else {
debug(`Failed to promote CodePush release - ${inspect(error)}`);
return failure(ErrorCodes.Exception, error.response.body);
}
}
out.text(`Successfully promoted ${this.label ? `'${this.label}' of` : ""} the '${this.sourceDeploymentName}' deployment of the '${this.identifier}' app to the '${this.destinationDeploymentName}' deployment.`);
return success();
}
}