UNPKG

@broadcom/endevor-bridge-for-git-for-zowe-cli

Version:

Endevor Bridge for Git plug-in for Zowe CLI

175 lines 9.97 kB
"use strict"; /* * Copyright (c) 2019 Broadcom. All Rights Reserved. The term * "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This software and all information contained therein is * confidential and proprietary and shall not be duplicated, * used, disclosed, or disseminated in any way except as * authorized by the applicable license agreement, without the * express written permission of Broadcom. All authorized * reproductions must be marked with this language. * * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO * THE EXTENT PERMITTED BY APPLICABLE LAW, BROADCOM PROVIDES THIS * SOFTWARE WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT * LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL BROADCOM * BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR * DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE, * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS * INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF BROADCOM IS * EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE. */ 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 BaseHandler_1 = require("../../BaseHandler"); const EBGMappingService_1 = require("../../../api/service/EBGMappingService"); const imperative_1 = require("@zowe/imperative"); const object_1 = require("../../../utils/object"); const api_1 = require("../../../api"); const MappingUtils_1 = require("../../../api/utils/MappingUtils"); const BranchOptions_1 = require("../BranchOptions"); class BranchAddHandler extends BaseHandler_1.BaseHandler { processWithSession() { return __awaiter(this, void 0, void 0, function* () { const task = { percentComplete: imperative_1.TaskProgress.ZERO_PERCENT, statusMessage: "Validate options", stageName: imperative_1.TaskStage.IN_PROGRESS }; this.progress.startBar({ task }); let payload; const context = this.getOption(BranchOptions_1.BranchOptions.CONTEXT, true); const repoName = this.getOption(BranchOptions_1.BranchOptions.MAPPING, true); const branchId = this.getOption(BranchOptions_1.BranchOptions.BRANCH_ID, true); const likeBranch = this.getOption(BranchOptions_1.BranchOptions.LIKE_BRANCH, false); let system; let systemAlias; let subsystem; let subsystemAlias; let mappingMode; let environment; let readOnly; let stageNumber; let systems = null; if ((0, object_1.isNotNil)(likeBranch)) { this.validateRequiredOptions(); const mapping = yield MappingUtils_1.MappingUtils.getMapping(this.ebgService, context, repoName); const branch = MappingUtils_1.MappingUtils.getBranch(mapping, likeBranch); // handle all cases in which the user specifies system, system-alias, subsystem or subsystem-alias systems = this.handleSystemsAndSubsystemsOverride(branch.systems); environment = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_ENVIRONMENT, branch.environment); mappingMode = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.MAPPING_MODE, branch.mappingMode); readOnly = Boolean(this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.READ_ONLY, branch.readOnly)); stageNumber = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_STAGE_NUMBER, branch.stageNumber); } else { system = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM); systemAlias = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM_ALIAS, false); subsystem = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM, true); subsystemAlias = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS, false); mappingMode = this.getOption(BranchOptions_1.BranchOptions.MAPPING_MODE); environment = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_ENVIRONMENT); readOnly = Boolean(this.getOption(BranchOptions_1.BranchOptions.READ_ONLY, false)); systems = [{ name: system, alias: systemAlias, subsystems: [{ name: subsystem, alias: subsystemAlias, filter: null }] }]; if (readOnly) { stageNumber = this.getOption(BranchOptions_1.BranchOptions.ENDEVOR_STAGE_NUMBER); // Validate after reading of the options this.validateRequiredOptions(); } else { const endevorSession = this.createEndevorSession(); const mapping = yield MappingUtils_1.MappingUtils.getMapping(this.ebgService, context, repoName); // Validate before making any API call this.validateRequiredOptions(); task.statusMessage = "Get entry stage"; task.percentComplete = imperative_1.TaskProgress.TEN_PERCENT; stageNumber = String(yield api_1.EndevorService.getEntryStage(endevorSession, mapping.connection.configuration, environment)); } } const repositoryCheck = String(this.getOption(BranchOptions_1.BranchOptions.REPOSITORY_CHECK)); payload = { context, repository: repoName, addBranches: [{ name: branchId, environment, stageNumber: Number(stageNumber), systems, mappingMode, readOnly }], deleteBranches: [], repositoryCheck }; task.statusMessage = "Schedule branch creation"; task.percentComplete = imperative_1.TaskProgress.FIFTY_PERCENT; yield EBGMappingService_1.EBGMappingService.updateMapping(this.ebgService, payload); task.percentComplete = imperative_1.TaskProgress.ONE_HUNDRED_PERCENT; this.console.log(`Branch ${branchId} will be initialized in background. You will be notified once this operation is completed`); }); } overrideOptionFromArgument(optionDefinition, optionFromBranch) { const option = this.getOptionFromArgument(optionDefinition); return (0, object_1.isNil)(option) ? optionFromBranch : option; } isOptionSpecified(optionDefinition) { return (0, object_1.isNotNil)(this.getOptionFromArgument(optionDefinition)); } handleSystemsAndSubsystemsOverride(systems) { if (systems.length > 1) { // if it's a multi system branch we cannot override system, sub-sysstem etc if (this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM) || this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM_ALIAS) || this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM) || this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS)) { this.fail({ msg: "Cannot override system, subsystem, system-alias or subsystem-alias" + " if the template branch contains multiple systems." }); } } else { const system = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM, systems[0].name); const systemAlias = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_SYSTEM_ALIAS, systems[0].alias); systems[0].name = system; systems[0].alias = systemAlias; const subsystems = systems[0].subsystems; if (subsystems.length > 1) { if (this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM) || this.isOptionSpecified(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS)) { this.fail({ msg: "Cannot override subsystem or subsystem-alias" + " if the template branch contains multiple subsystems." }); } } else { const subsystem = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM, subsystems[0].name); const subsystemAlias = this.overrideOptionFromArgument(BranchOptions_1.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS, subsystems[0].alias); systems[0].subsystems[0].name = subsystem; systems[0].subsystems[0].alias = subsystemAlias; } } return systems; } } exports.default = BranchAddHandler; //# sourceMappingURL=BranchAdd.handler.js.map