UNPKG

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

Version:

Endevor Bridge for Git plug-in for Zowe CLI

218 lines (213 loc) 9.47 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../../../../node_modules/tslib/tslib.es6.js'); var BaseHandler = require('../../../BaseHandler.js'); var EBGConstants = require('../../../../api/constants/EBGConstants.js'); require('../../../../api/constants/PluginConstants.js'); require('../../../../api/doc/ebg/IMappingView.js'); var EBGMappingService = require('../../../../api/service/EBGMappingService.js'); require('@zowe/imperative'); require('../../../../api/doc/IBranchMetadata.js'); require('child_process'); require('../../../../api/utils/ChangeValidator.js'); var fs = require('fs'); require('lodash'); require('../../../../api/utils/OptionValidator.js'); var MappingOptions = require('../../../options/MappingOptions.js'); var MappingUtils = require('../../../../api/utils/MappingUtils.js'); var index = require('../../../../node_modules/@broadcom/bridge-for-git-zowe-client/dist/index.js'); var PageableOptions = require('../../../options/PageableOptions.js'); var luxon = require('luxon'); /* * 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 ListMappingHandler extends BaseHandler.BaseHandler { static getMappingStatus(mapping) { return mapping.branchStatus.label; } static getPercentage(mapping) { return mapping.processingStatus.value === index.ProcessingStatusE.NONE ? mapping.processingStatus.label : `${mapping.processingStatus.label} (${mapping.completedActions} / ${mapping.totalActions})`; } processWithSession() { return tslib_es6.__awaiter(this, void 0, void 0, function* () { // case insensitive const viewType = String(this.getOption(MappingOptions.MappingOptions.VIEW_TYPE)).toLowerCase(); const exportList = this.getOption(MappingOptions.MappingOptions.EXPORT_LIST, false); this.validateRequiredOptions(); let branches; let workEnvironmentOnly; let mappingMode; let stage; let readOnly; let systemName; let subsystemName; let environment; let status; const page = this.getOption(PageableOptions.PageableOptions.PAGE) - 1; const size = this.getOption(PageableOptions.PageableOptions.SIZE); const mappings = yield EBGMappingService.EBGMappingService.listMappings(this.apiClient, { page, size, }); const output = mappings.map((mapping) => { if (mapping.branches) { const branch = mapping.branches[0]; if (mapping.branches.length > 1) { for (const branchMulti of mapping.branches) { if (!MappingUtils.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.value === index.MappingModeE.FULL ? "false" : "true"); mappingMode = branch.mappingMode.value; 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 + EBGConstants.EBGConstants.BRANCHES; } else if (branch) { if (MappingUtils.MappingUtils.isMultiSystem(branch)) { systemName = "multi"; subsystemName = "multi"; } else { systemName = branch.systems[0].name; subsystemName = branch.systems[0].subsystems[0].name; } branches = mapping.branches.length + EBGConstants.EBGConstants.BRANCH; workEnvironmentOnly = String(branch.mappingMode.value === index.MappingModeE.FULL ? "false" : "true"); mappingMode = branch.mappingMode.value; stage = branch.stage; readOnly = String(branch.readOnly); environment = branch.environment; } } status = ListMappingHandler.getMappingStatus(mapping); return { context: mapping.context, mapping: mapping.repository, repository: mapping.mirrorRepoUrl, owner: mapping.adminUsername, init: ListMappingHandler.getPercentage(mapping), system: systemName, configuration: mapping.connection.configuration, subsystem: subsystemName, environment, stage, webServices: mapping.connection.baseUrl, connection: mapping.connection.connection, readOnly, branches, workEnvironmentOnly, mappingMode, status, }; }); if (exportList) { const fileDateTime = luxon.DateTime.now().toFormat("yyyy-MM-dd-HH-mm"); const json = JSON.stringify(mappings, null, 2); 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.MappingOptions.MAPPING_VIEW_ENDEVOR) { fields = ListMappingHandler.ENDEVOR_FIELDS; } else if (viewType === MappingOptions.MappingOptions.MAPPING_VIEW_ALL) { fields = ListMappingHandler.ALL_FIELDS; } else { fields = ListMappingHandler.DEFAULT_FIELDS; } this.setOutput("table", output, fields, true); // Return the original mappingResponse when using --response-format-json this.data.setObj(mappings); }); } } ListMappingHandler.DEFAULT_FIELDS = [ "context", "mapping", "branches", "owner", "init", "readOnly", "repository", "status", ]; ListMappingHandler.ENDEVOR_FIELDS = [ "context", "mapping", "connection", "environment", "stage", "system", "subsystem", ]; ListMappingHandler.ALL_FIELDS = [ "context", "mapping", "branches", "owner", "init", "readOnly", "repository", "connection", "environment", "stage", "system", "subsystem", "mappingMode", "status", ]; exports.default = ListMappingHandler;