async run()

in src/commands/codepush/patch.ts [76:138]


  async run(client: AppCenterClient): Promise<CommandResult> {
    const app = this.app;
    let release: models.CodePushRelease;

    if (!this.targetBinaryRange && !this.isDisabled && !this.isMandatory && !this.description && !this.rollout) {
      return failure(ErrorCodes.Exception, "At least one property must be specified to patch a release.");
    }

    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 patch: models.CodePushReleaseModification = {
      targetBinaryRange: this.targetBinaryRange,
      isMandatory: this.isMandatory,
      isDisabled: this.isDisabled,
      description: this.description,
    };

    if (this.rollout != null) {
      patch.rollout = rollout;
    }

    if (this.releaseLabel == null || this.releaseLabel === "") {
      debug("Release label is not set, get latest...");
      this.releaseLabel = await this.getLatestReleaseLabel(client, app);
    }

    try {
      const httpRequest = await out.progress(
        "Patching CodePush release...",
        clientRequest<models.CodePushRelease>((cb) =>
          client.deploymentReleases.update(this.deploymentName, this.releaseLabel, patch, app.ownerName, app.appName, cb)
        )
      );
      release = httpRequest.result;
      if (httpRequest.response.statusCode === 204) {
        out.text(
          `No update for the ${chalk.bold(this.releaseLabel)} of ${this.identifier} app's ${chalk.bold(
            this.deploymentName
          )} deployment`
        );
      } else {
        out.text(
          `Successfully updated the ${chalk.bold(release.label)} of ${this.identifier} app's ${chalk.bold(
            this.deploymentName
          )} deployment`
        );
      }
      return success();
    } catch (error) {
      debug(`Failed to patch Codepush deployment - ${inspect(error)}`);
      return failure(ErrorCodes.Exception, error.response.body);
    }
  }