1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
25 | Object.defineProperty(exports, "__esModule", { value: true });
|
26 | const automation_client_1 = require("@atomist/automation-client");
|
27 | const info_1 = require("@atomist/automation-client/lib/internal/util/info");
|
28 | const slack_messages_1 = require("@atomist/slack-messages");
|
29 | const appRoot = require("app-root-path");
|
30 | const path = require("path");
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function 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 | }
|
44 | exports.selfDescribeCommand = selfDescribeCommand;
|
45 | function 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}
|
59 | Version: ${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")}
|
64 | Repository: ${slack_messages_1.codeLine(gitInfo.git && gitInfo.git.repository ? gitInfo.git.repository : "n/a")}
|
65 | Policy: ${slack_messages_1.codeLine(sdm.configuration.policy)}
|
66 | Environment: ${slack_messages_1.codeLine(sdm.configuration.environment)}
|
67 | Cluster: ${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 |
|
\ | No newline at end of file |