UNPKG

5.47 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2019 Atomist, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18 return new (P || (P = Promise))(function (resolve, reject) {
19 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
22 step((generator = generator.apply(thisArg, _arguments || [])).next());
23 });
24};
25Object.defineProperty(exports, "__esModule", { value: true });
26const automation_client_1 = require("@atomist/automation-client");
27const info_1 = require("@atomist/automation-client/lib/internal/util/info");
28const slack_messages_1 = require("@atomist/slack-messages");
29const appRoot = require("app-root-path");
30const path = require("path");
31/**
32 * Return a command handler that can describe the present software delivery machine
33 * @param {SoftwareDeliveryMachine} sdm
34 * @return {HandleCommand<EmptyParameters>}
35 */
36function selfDescribeCommand(sdm) {
37 return {
38 name: "SelfDescribe",
39 listener: selfDescribeListener(sdm),
40 description: "Describe this SDM",
41 intent: [`describe sdm ${sdm.configuration.name.replace("@", "")}`],
42 };
43}
44exports.selfDescribeCommand = selfDescribeCommand;
45function selfDescribeListener(sdm) {
46 return (cli) => __awaiter(this, void 0, void 0, function* () {
47 const pj = require(path.join(appRoot.path, "package.json"));
48 const clientPj = require(path.join(appRoot.path, "node_modules", "@atomist", "automation-client", "package.json"));
49 const sdmPj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm", "package.json"));
50 const sdmCorePj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm-core", "package.json"));
51 const gitInfo = info_1.info(automation_client_1.automationClientInstance().automations.automations);
52 const msg = {
53 attachments: [{
54 author_name: pj.author && pj.author.name ? pj.author.name : pj.author,
55 title: sdm.name,
56 title_link: pj.homepage,
57 fallback: sdm.name,
58 text: `${pj.description}
59Version: ${slack_messages_1.codeLine(sdm.configuration.version)} - License: ${slack_messages_1.codeLine(pj.license)}`,
60 }, {
61 author_name: "Details",
62 fallback: "Details",
63 text: `Sha: ${slack_messages_1.codeLine(gitInfo.git && gitInfo.git.sha ? gitInfo.git.sha.slice(0, 7) : "n/a")}
64Repository: ${slack_messages_1.codeLine(gitInfo.git && gitInfo.git.repository ? gitInfo.git.repository : "n/a")}
65Policy: ${slack_messages_1.codeLine(sdm.configuration.policy)}
66Environment: ${slack_messages_1.codeLine(sdm.configuration.environment)}
67Cluster: ${slack_messages_1.codeLine(sdm.configuration.cluster.enabled ? "enabled" : "disabled")}`,
68 }, {
69 author_name: "Dependencies",
70 fallback: "Dependencies",
71 text: `${slack_messages_1.codeLine(`${clientPj.name}:${clientPj.version}`)}
72${slack_messages_1.codeLine(`${sdmPj.name}:${sdmPj.version}`)}
73${slack_messages_1.codeLine(`${sdmCorePj.name}:${sdmCorePj.version}`)}`,
74 }, {
75 author_name: "Extension Packs",
76 fallback: "Extension Packs",
77 text: [...sdm.extensionPacks]
78 .sort((e1, e2) => e1.name.localeCompare(e2.name))
79 .map(e => `${slack_messages_1.codeLine(`${e.name}:${e.version}`)} ${e.vendor}`).join("\n"),
80 }, {
81 author_name: "Events",
82 fallback: "Events",
83 text: automation_client_1.automationClientInstance().automations.automations.events
84 .sort((e1, e2) => e1.name.localeCompare(e2.name))
85 .map(e => `${slack_messages_1.bold(e.name)} ${e.description}`).join("\n"),
86 }, {
87 author_name: "Commands",
88 fallback: "Commands",
89 text: automation_client_1.automationClientInstance().automations.automations.commands
90 .sort((e1, e2) => e1.name.localeCompare(e2.name))
91 .map(e => `${slack_messages_1.bold(e.name)} ${e.intent.map(slack_messages_1.codeLine).join(", ")} ${e.description}`).join("\n"),
92 footer: `${sdm.configuration.name}:${sdm.configuration.version}`,
93 }],
94 };
95 yield cli.context.messageClient.respond(msg);
96 return automation_client_1.Success;
97 });
98}
99//# sourceMappingURL=SelfDescribe.js.map
\No newline at end of file