UNPKG

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

Version:

Endevor Bridge for Git plug-in for Zowe CLI

245 lines 13.1 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 api_1 = require("../../../api"); const api_2 = require("@broadcom/endevor-for-zowe-cli/lib/api"); const MappingUtils_1 = require("../../../api/utils/MappingUtils"); const object_1 = require("../../../utils/object"); const endevor_bridge_for_git_rest_api_1 = require("@broadcom/endevor-bridge-for-git-rest-api"); const MappingOptions_1 = require("../MappingOptions"); class MappingListHandler extends BaseHandler_1.BaseHandler { static getMappingStatus(mapping) { if (mapping.branches.some(branch => [endevor_bridge_for_git_rest_api_1.BranchStatus.revertRunning, endevor_bridge_for_git_rest_api_1.BranchStatus.revertRestart, endevor_bridge_for_git_rest_api_1.BranchStatus.revertFailed, endevor_bridge_for_git_rest_api_1.BranchStatus.initFailed] .indexOf(branch.queueStatus) > -1)) { return api_1.MappingStatus.error; } if (mapping.branches.some(branch => [endevor_bridge_for_git_rest_api_1.BranchStatus.disabled].indexOf(branch.queueStatus) > -1)) { return api_1.MappingStatus.warning; } if ((0, object_1.isNotNil)(mapping.completedActions) && (0, object_1.isNotNil)(mapping.totalActions)) { if (MappingListHandler.isPreparingState(mapping) && !MappingListHandler.isInitialized(mapping)) { return api_1.MappingStatus.empty; } if (MappingListHandler.isRetrieveState(mapping)) { return mapping.completedActions + " out of " + mapping.totalActions + api_1.MappingStatus.inProgress; } if (MappingListHandler.isPushingState(mapping)) { return api_1.MappingStatus.pushing; } return api_1.MappingStatus.success; } return api_1.MappingStatus.empty; } static isInitialized(mapping) { return !(mapping.branches.some(branch => [endevor_bridge_for_git_rest_api_1.BranchStatus.new, endevor_bridge_for_git_rest_api_1.BranchStatus.initInProgress] .indexOf(branch.queueStatus) > -1)); } static getPercentage(mapping) { if ((0, object_1.isNotNil)(mapping.completedActions) && (0, object_1.isNotNil)(mapping.totalActions)) { if (MappingListHandler.isPreparingState(mapping) && !MappingListHandler.isInitialized(mapping)) { return "0"; } if (MappingListHandler.isRetrieveState(mapping)) { // tslint:disable-next-line:no-magic-numbers return String(Math.round(mapping.completedActions / mapping.totalActions * 100)); } if (MappingListHandler.isPushingState(mapping)) { return "100"; } return "100"; } else { return undefined; } } processWithSession() { return __awaiter(this, void 0, void 0, function* () { // case insensitive const viewType = String(this.getOption(MappingOptions_1.MappingOptions.VIEW_TYPE)).toLowerCase(); const exportList = this.getOption(MappingOptions_1.MappingOptions.EXPORT_LIST, false); let mappingVersion; this.validateRequiredOptions(); let branches; let workEnvironmentOnly; let mappingMode; let stage; let readOnly; let systemName; let subsystemName; let environment; let status; const mappings = yield api_1.EBGMappingService.listMappings(this.ebgService); const output = mappings.map(mapping => { mappingVersion = MappingUtils_1.MappingUtils.getVersion(mapping); const branch = mapping.branches[0]; if (mapping.branches.length > 1) { for (const branchMulti of mapping.branches) { if (!MappingUtils_1.MappingUtils.isMultiSystem(branch) && branchMulti.systems[0].name === branch.systems[0].name && branchMulti.systems[0].subsystems[0].name === branch.systems[0].subsystems[0].name && branchMulti.mappingMode === branch.mappingMode && branchMulti.environment === branch.environment && branchMulti.readOnly === branch.readOnly && branchMulti.stage === branch.stage) { systemName = branch.systems[0].name; subsystemName = branch.systems[0].subsystems[0].name; workEnvironmentOnly = String(branch.mappingMode === endevor_bridge_for_git_rest_api_1.MappingMode.full ? "false" : "true"); mappingMode = branch.mappingMode; environment = branch.environment; readOnly = String(branch.readOnly); stage = branch.stage; } else { mappingMode = "multi"; workEnvironmentOnly = "multi"; stage = "multi"; readOnly = "multi"; systemName = "multi"; subsystemName = "multi"; environment = "multi"; break; } } branches = mapping.branches.length + api_1.EBGConstants.BRANCHES; } else { if (MappingUtils_1.MappingUtils.isMultiSystem(branch)) { systemName = "multi"; subsystemName = "multi"; } else { systemName = branch.systems[0].name; subsystemName = branch.systems[0].subsystems[0].name; } branches = mapping.branches.length + api_1.EBGConstants.BRANCH; workEnvironmentOnly = String(branch.mappingMode === endevor_bridge_for_git_rest_api_1.MappingMode.full ? "false" : "true"); mappingMode = branch.mappingMode; stage = branch.stage; readOnly = String(branch.readOnly); environment = branch.environment; } status = MappingListHandler.getMappingStatus(mapping); let config; let webservices; let connection; if (mappingVersion !== MappingUtils_1.MappingVersion.V2) { config = mapping.connection.configuration; webservices = mapping.connection.baseUrl; connection = mapping.connection.connection; } else { config = branch.config; webservices = branch.baseUrl; } return { context: mapping.context, mapping: mapping.repository, repository: mapping.mirrorRepoUrl, owner: mapping.adminUsername, init: MappingListHandler.getPercentage(mapping), system: systemName, configuration: config, subsystem: subsystemName, environment, stage, webServices: webservices, connection, readOnly, branches, workEnvironmentOnly, mappingMode, status, }; }); if (exportList) { const now = new Date(); const fileDateTime = api_2.EndevorUtils.formatDate(now, false) + "-" + api_2.EndevorUtils.formatTime(now, true, ""); const json = JSON.stringify(mappings, null, 2); const fs = require("fs"); const fileName = "mappingList" + fileDateTime + ".json"; fs.writeFile(fileName, json, "utf8", (err) => { if (err) { this.console.log("Error writing to file."); throw err; } else { this.console.log("Mapping List is written to: " + fileName); } }); return; } let fields; if (viewType === MappingOptions_1.MappingOptions.MAPPING_VIEW_ENDEVOR) { fields = mappingVersion === MappingUtils_1.MappingVersion.V2 ? MappingListHandler.ENDEVOR_FIELDS : MappingListHandler.ENDEVOR_FIELDS_V3; } else if (viewType === MappingOptions_1.MappingOptions.MAPPING_VIEW_ALL) { switch (mappingVersion) { case MappingUtils_1.MappingVersion.V3: fields = MappingListHandler.ALL_FIELDS_V3; break; case MappingUtils_1.MappingVersion.V4: fields = MappingListHandler.ALL_FIELDS_V4; break; default: fields = MappingListHandler.ALL_FIELDS; } } else { fields = MappingListHandler.DEFAULT_FIELDS; } this.format.output({ fields, output, format: "table", header: true }); // Return the original mappingResponse when using --response-format-json this.data.setObj(mappings); }); } } exports.default = MappingListHandler; MappingListHandler.DEFAULT_FIELDS = ["context", "mapping", "branches", "owner", "init", "readOnly", "repository", "status"]; MappingListHandler.ENDEVOR_FIELDS = ["context", "mapping", "webServices", "configuration", "environment", "stage", "system", "subsystem"]; MappingListHandler.ALL_FIELDS = ["context", "mapping", "branches", "owner", "init", "readOnly", "repository", "webServices", "configuration", "environment", "stage", "system", "subsystem", "workEnvironmentOnly", "status"]; MappingListHandler.ENDEVOR_FIELDS_V3 = ["context", "mapping", "connection", "environment", "stage", "system", "subsystem"]; MappingListHandler.ALL_FIELDS_V3 = ["context", "mapping", "branches", "owner", "init", "readOnly", "repository", "connection", "environment", "stage", "system", "subsystem", "workEnvironmentOnly", "status"]; MappingListHandler.ALL_FIELDS_V4 = ["context", "mapping", "branches", "owner", "init", "readOnly", "repository", "connection", "environment", "stage", "system", "subsystem", "mappingMode", "status"]; MappingListHandler.isPreparingState = (mapping) => { return mapping.totalActions === 0 && mapping.completedActions === 0; }; MappingListHandler.isRetrieveState = (mapping) => { return mapping.totalActions !== 0 && mapping.completedActions < mapping.totalActions; }; MappingListHandler.isPushingState = (mapping) => { return mapping.totalActions === mapping.completedActions && mapping.completedActions > 0; }; //# sourceMappingURL=MappingList.handler.js.map