UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

85 lines 4.59 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const automation_client_1 = require("@atomist/automation-client"); const sdm_pack_fingerprints_1 = require("@atomist/sdm-pack-fingerprints"); const _ = require("lodash"); const overview_1 = require("../../../views/overview"); const topLevelPage_1 = require("../../../views/topLevelPage"); const DefaultAspectRegistry_1 = require("../../aspect/DefaultAspectRegistry"); function exposeOverviewPage(express, handlers, topLevelRoute, aspectRegistry, store) { express.get(topLevelRoute, ...handlers, (req, res) => __awaiter(this, void 0, void 0, function* () { try { const repos = yield store.loadInWorkspace(req.query.workspace || req.params.workspace_id, false); const workspaceId = "*"; const fingerprintUsage = yield store.fingerprintUsageForType(workspaceId); const ideals = yield aspectRegistry.idealStore.loadIdeals(workspaceId); const aspectsEligibleForDisplay = aspectRegistry.aspects.filter(a => !!a.displayName) .filter(a => fingerprintUsage.some(fu => fu.type === a.name)); const importantAspects = _.sortBy(aspectsEligibleForDisplay, a => a.displayName) .map(aspect => { const fingerprintsForThisAspect = fingerprintUsage.filter(fu => fu.type === aspect.name); return { aspect, fingerprints: fingerprintsForThisAspect .map(fp => formatFingerprintUsageForDisplay(aspect, ideals, fp)), }; }); const unfoundAspects = aspectRegistry.aspects .filter(f => !!f.displayName) .filter(f => !fingerprintUsage.some(fu => fu.type === f.name)); const virtualProjectCount = yield store.virtualProjectCount(workspaceId); res.send(topLevelPage_1.renderStaticReactNode(overview_1.Overview({ projectsAnalyzed: repos.length, importantAspects, unfoundAspects, repos: repos.map(r => ({ id: r.id, repo: r.repoRef.repo, owner: r.repoRef.owner, url: r.repoRef.url, })), virtualProjectCount, }), `Atomist Visualizer (${repos.length} repositories)`)); } catch (e) { automation_client_1.logger.error(e.stack); res.status(500).send("failure"); } })); } exports.exposeOverviewPage = exposeOverviewPage; function idealMatchesFingerprint(id, fp) { const c = sdm_pack_fingerprints_1.idealCoordinates(id); return c.type === fp.type && c.name === fp.name; } function formatFingerprintUsageForDisplay(aspect, ideals, fp) { const foundIdeal = ideals.find(ide => idealMatchesFingerprint(ide, fp)); const ideal = foundIdeal && sdm_pack_fingerprints_1.isConcreteIdeal(foundIdeal) && aspect.toDisplayableFingerprint ? { displayValue: aspect.toDisplayableFingerprint(foundIdeal.ideal) } : undefined; return Object.assign({}, fp, { ideal, displayName: DefaultAspectRegistry_1.defaultedToDisplayableFingerprintName(aspect)(fp.name), entropy: sdm_pack_fingerprints_1.supportsEntropy(aspect) ? fp.entropy : undefined }); } //# sourceMappingURL=overviewPage.js.map