@broadcom/endevor-bridge-for-git-for-zowe-cli
Version:
Endevor Bridge for Git plug-in for Zowe CLI
190 lines (185 loc) • 9.96 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('../../../../node_modules/tslib/tslib.es6.js');
var BaseHandler = require('../../../BaseHandler.js');
var imperative = require('@zowe/imperative');
var object = require('../../../../utils/object.js');
var BranchOptions = require('../../../options/BranchOptions.js');
var MappingUtils = require('../../../../api/utils/MappingUtils.js');
require('../../../../api/constants/EBGConstants.js');
require('../../../../api/constants/PluginConstants.js');
require('../../../../api/doc/ebg/IMappingView.js');
var EBGMappingService = require('../../../../api/service/EBGMappingService.js');
var EBGEndevorService = require('../../../../api/service/EBGEndevorService.js');
require('../../../../api/doc/IBranchMetadata.js');
require('child_process');
require('../../../../api/utils/ChangeValidator.js');
require('fs');
require('lodash');
require('../../../../api/utils/OptionValidator.js');
var index = require('../../../../node_modules/@broadcom/bridge-for-git-zowe-client/dist/index.js');
/*
* 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.
*/
class CreateBranchHandler extends BaseHandler.BaseHandler {
processWithSession() {
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
const task = {
percentComplete: imperative.TaskProgress.ZERO_PERCENT,
statusMessage: "Validate options",
stageName: imperative.TaskStage.IN_PROGRESS,
};
this.progress.startBar({ task });
const context = this.getOption(BranchOptions.BranchOptions.CONTEXT, true);
const repoName = this.getOption(BranchOptions.BranchOptions.MAPPING, true);
const branchId = this.getOption(BranchOptions.BranchOptions.BRANCH_ID, true);
const likeBranch = this.getOption(BranchOptions.BranchOptions.LIKE_BRANCH, false);
let system;
let systemAlias;
let subsystem;
let subsystemAlias;
let mappingMode;
let environment;
let readOnly;
let stageNumber;
let systems;
const mapping = yield MappingUtils.MappingUtils.getMapping(this.apiClient, context, repoName);
if (object.isNotNil(likeBranch)) {
this.validateRequiredOptions();
const branch = MappingUtils.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.BranchOptions.ENDEVOR_ENVIRONMENT, branch.environment);
mappingMode = this.overrideOptionFromArgument(BranchOptions.BranchOptions.MAPPING_MODE, branch.mappingMode.value);
readOnly = Boolean(this.overrideOptionFromArgument(BranchOptions.BranchOptions.READ_ONLY, branch.readOnly));
stageNumber = this.overrideOptionFromArgument(BranchOptions.BranchOptions.ENDEVOR_STAGE_NUMBER, branch.stage);
}
else {
system = this.getOption(BranchOptions.BranchOptions.ENDEVOR_SYSTEM, true);
systemAlias = this.getOption(BranchOptions.BranchOptions.ENDEVOR_SYSTEM_ALIAS, false);
subsystem = this.getOption(BranchOptions.BranchOptions.ENDEVOR_SUBSYSTEM, true);
subsystemAlias = this.getOption(BranchOptions.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS, false);
mappingMode =
this.getOption(BranchOptions.BranchOptions.MAPPING_MODE) ||
index.MappingModeE.FULL;
environment = this.getOption(BranchOptions.BranchOptions.ENDEVOR_ENVIRONMENT, true);
readOnly = Boolean(this.getOption(BranchOptions.BranchOptions.READ_ONLY, false));
systems = [
{
name: system,
alias: systemAlias,
subsystems: [
{
name: subsystem,
alias: subsystemAlias,
filter: undefined,
},
],
},
];
if (readOnly) {
stageNumber = this.getOption(BranchOptions.BranchOptions.ENDEVOR_STAGE_NUMBER);
// Validate after reading of the options
this.validateRequiredOptions();
}
else {
// Validate before making any API call
this.validateRequiredOptions();
task.statusMessage = "Get entry stage";
task.percentComplete = imperative.TaskProgress.TEN_PERCENT;
stageNumber = yield EBGEndevorService.EBGEndevorService.getEntryStage({
api: this.apiClient,
connectionName: mapping.connection.connection,
environment,
});
}
}
const repositoryCheck = String(this.getOption(BranchOptions.BranchOptions.REPOSITORY_CHECK));
const payload = {
addBranches: [
{
name: branchId,
environment,
stageNumber: Number(stageNumber),
systems,
mappingMode,
readOnly,
synchronizeListings: false,
defaultBranch: false,
},
],
deleteBranches: [],
repositoryCheck,
};
task.statusMessage = "Schedule branch creation";
task.percentComplete = imperative.TaskProgress.FIFTY_PERCENT;
yield EBGMappingService.EBGMappingService.updateMapping(this.apiClient, mapping.id, payload);
task.percentComplete = imperative.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 object.isNil(option) ? optionFromBranch : option;
}
isOptionSpecified(optionDefinition) {
return object.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.BranchOptions.ENDEVOR_SYSTEM) ||
this.isOptionSpecified(BranchOptions.BranchOptions.ENDEVOR_SYSTEM_ALIAS) ||
this.isOptionSpecified(BranchOptions.BranchOptions.ENDEVOR_SUBSYSTEM) ||
this.isOptionSpecified(BranchOptions.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.BranchOptions.ENDEVOR_SYSTEM, systems[0].name);
const systemAlias = this.overrideOptionFromArgument(BranchOptions.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.BranchOptions.ENDEVOR_SUBSYSTEM) ||
this.isOptionSpecified(BranchOptions.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.BranchOptions.ENDEVOR_SUBSYSTEM, subsystems[0].name);
const subsystemAlias = this.overrideOptionFromArgument(BranchOptions.BranchOptions.ENDEVOR_SUBSYSTEM_ALIAS, subsystems[0].alias);
systems[0].subsystems[0].name = subsystem;
systems[0].subsystems[0].alias = subsystemAlias;
}
}
return systems;
}
}
exports.default = CreateBranchHandler;