UNPKG

@atomist/org-visualizer

Version:

Organization Visualizer using Atomist project scanning

115 lines 4.32 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 yaml = require("yamljs"); const TravisScriptsType = "travis-scripts"; exports.TravisScriptsAspect = { name: TravisScriptsType, displayName: "Travis scripts", extract: (p) => __awaiter(this, void 0, void 0, function* () { const travis = yield exports.travisScanner(p); if (!travis) { return undefined; } const data = travis.scripts; return (!!travis) ? { type: TravisScriptsType, name: TravisScriptsType, data, sha: sdm_pack_fingerprints_1.sha256(JSON.stringify(data)), } : undefined; }), toDisplayableFingerprint: fp => fp.data.join(","), }; /** * Scan for Travis information */ exports.travisScanner = (p) => __awaiter(this, void 0, void 0, function* () { const travisYaml = yield p.getFile(".travis.yml"); if (!travisYaml) { return undefined; } let nativeObject; try { nativeObject = tryAsYamlThenJson(yield travisYaml.getContent()); } catch (e) { automation_client_1.logger.warn("Cannot parse Travis file: %s", e.message); return undefined; } const services = {}; // Services can be a single value or list if (typeof nativeObject.services === "string") { services[nativeObject.services] = {}; } else { for (const e of nativeObject.services || []) { services[e] = {}; } } const branches = nativeObject.branches ? { only: nativeObject.branches.only ? automation_client_1.toStringArray(nativeObject.branches.only) : [], except: nativeObject.branches.except ? automation_client_1.toStringArray(nativeObject.branches.except) : [], } : undefined; const travis = { branches, language: nativeObject.language, scripts: nativeObject.script ? automation_client_1.toStringArray(nativeObject.script) : [], addons: nativeObject.addons, beforeInstall: nativeObject.before_install ? automation_client_1.toStringArray(nativeObject.before_install) : [], afterSuccess: nativeObject.after_success ? automation_client_1.toStringArray(nativeObject.after_success) : [], services, referencedEnvironmentVariables: [], nodeJs: nativeObject.node_js ? automation_client_1.toStringArray(nativeObject.node_js) : [], }; return travis; }); /** * First try to parse as YAML then try as JSON (yes, this is legal!) * @param {string} content * @return {TravisCi} */ function tryAsYamlThenJson(content) { try { return yaml.parse(content); } catch (error) { automation_client_1.logger.warn("Failed to parse as YAML: %s", error); return JSON.parse(content); } } //# sourceMappingURL=travisAspects.js.map