@atomist/sdm-core
Version:
Atomist Software Delivery Machine - Implementation
100 lines • 5.55 kB
JavaScript
/*
* 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) {
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 automation_client_1 = require("@atomist/automation-client");
const info_1 = require("@atomist/automation-client/lib/internal/util/info");
const slack_messages_1 = require("@atomist/slack-messages");
const appRoot = require("app-root-path");
const path = require("path");
/**
* Return a command handler that can describe the present software delivery machine
* @param {SoftwareDeliveryMachine} sdm
* @return {HandleCommand<EmptyParameters>}
*/
function selfDescribeCommand(sdm) {
return {
name: "SelfDescribe",
listener: selfDescribeListener(sdm),
description: "Describe this SDM",
intent: [`describe sdm ${sdm.configuration.name.replace("@", "")}`],
};
}
exports.selfDescribeCommand = selfDescribeCommand;
function selfDescribeListener(sdm) {
return (cli) => __awaiter(this, void 0, void 0, function* () {
const pj = require(path.join(appRoot.path, "package.json"));
const clientPj = require(path.join(appRoot.path, "node_modules", "@atomist", "automation-client", "package.json"));
const sdmPj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm", "package.json"));
const sdmCorePj = require(path.join(appRoot.path, "node_modules", "@atomist", "sdm-core", "package.json"));
const gitInfo = info_1.info(automation_client_1.automationClientInstance().automations.automations);
const msg = {
attachments: [{
author_name: pj.author && pj.author.name ? pj.author.name : pj.author,
title: sdm.name,
title_link: pj.homepage,
fallback: sdm.name,
text: `${pj.description}
Version: ${slack_messages_1.codeLine(sdm.configuration.version)} - License: ${slack_messages_1.codeLine(pj.license)}`,
}, {
author_name: "Details",
fallback: "Details",
text: `Sha: ${slack_messages_1.codeLine(gitInfo.git && gitInfo.git.sha ? gitInfo.git.sha.slice(0, 7) : "n/a")}
Repository: ${slack_messages_1.codeLine(gitInfo.git && gitInfo.git.repository ? gitInfo.git.repository : "n/a")}
Policy: ${slack_messages_1.codeLine(sdm.configuration.policy)}
Environment: ${slack_messages_1.codeLine(sdm.configuration.environment)}
Cluster: ${slack_messages_1.codeLine(sdm.configuration.cluster.enabled ? "enabled" : "disabled")}`,
}, {
author_name: "Dependencies",
fallback: "Dependencies",
text: `${slack_messages_1.codeLine(`${clientPj.name}:${clientPj.version}`)}
${slack_messages_1.codeLine(`${sdmPj.name}:${sdmPj.version}`)}
${slack_messages_1.codeLine(`${sdmCorePj.name}:${sdmCorePj.version}`)}`,
}, {
author_name: "Extension Packs",
fallback: "Extension Packs",
text: [...sdm.extensionPacks]
.sort((e1, e2) => e1.name.localeCompare(e2.name))
.map(e => `${slack_messages_1.codeLine(`${e.name}:${e.version}`)} ${e.vendor}`).join("\n"),
}, {
author_name: "Events",
fallback: "Events",
text: automation_client_1.automationClientInstance().automations.automations.events
.sort((e1, e2) => e1.name.localeCompare(e2.name))
.map(e => `${slack_messages_1.bold(e.name)} ${e.description}`).join("\n"),
}, {
author_name: "Commands",
fallback: "Commands",
text: automation_client_1.automationClientInstance().automations.automations.commands
.sort((e1, e2) => e1.name.localeCompare(e2.name))
.map(e => `${slack_messages_1.bold(e.name)} ${e.intent.map(slack_messages_1.codeLine).join(", ")} ${e.description}`).join("\n"),
footer: `${sdm.configuration.name}:${sdm.configuration.version}`,
}],
};
yield cli.context.messageClient.respond(msg);
return automation_client_1.Success;
});
}
//# sourceMappingURL=SelfDescribe.js.map
;