1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import {
|
18 | buttonForCommand,
|
19 | failure,
|
20 | guid,
|
21 | RepoRef,
|
22 | Success,
|
23 | } from "@atomist/automation-client";
|
24 | import {
|
25 | CommandHandlerRegistration,
|
26 | CommandListener,
|
27 | isDeployEnabled,
|
28 | } from "@atomist/sdm";
|
29 | import {
|
30 | bold,
|
31 | SlackMessage,
|
32 | } from "@atomist/slack-messages";
|
33 | import { SetDeployEnablementParameters } from "./SetDeployEnablement";
|
34 |
|
35 | const displayDeployEnablement: CommandListener<SetDeployEnablementParameters> =
|
36 | async cli => {
|
37 | const enabled = await isDeployEnabled({ context: cli.context, id: cli.parameters as any as RepoRef });
|
38 | const msgId = guid();
|
39 | return cli.context.messageClient.respond(
|
40 | reportDeployEnablement(cli.parameters, enabled, msgId), { id: cli.parameters.msgId })
|
41 | .then(() => Success, failure);
|
42 | };
|
43 |
|
44 | export function reportDeployEnablement(params: SetDeployEnablementParameters,
|
45 | enabled: boolean,
|
46 | msgId: string): SlackMessage {
|
47 | const text = `Deploy is currently ${enabled ? "enabled" : "disabled"} on ${bold(`${params.owner}/${params.repo}`)}`;
|
48 | const actions =
|
49 | [buttonForCommand({ text: enabled ? "Disable" : "Enable" },
|
50 | enabled ? "DisableDeploy" : "EnableDeploy",
|
51 | { ...params, msgId })];
|
52 | const msg: SlackMessage = {
|
53 | attachments: [{
|
54 | author_icon: `https:
|
55 | author_name: "Deploy Enablement",
|
56 | text,
|
57 | fallback: text,
|
58 | color: enabled ? "#37A745" : "#B5B5B5",
|
59 | mrkdwn_in: ["text"],
|
60 | actions,
|
61 | footer: `${params.name}:${params.version}`,
|
62 | }],
|
63 | };
|
64 | return msg;
|
65 | }
|
66 |
|
67 | export const DisplayDeployEnablement: CommandHandlerRegistration<SetDeployEnablementParameters> = {
|
68 | name: "DisplayDeployEnablement",
|
69 | description: "Display whether deployment via Atomist SDM in enabled",
|
70 | intent: "is deploy enabled?",
|
71 | paramsMaker: SetDeployEnablementParameters,
|
72 | listener: displayDeployEnablement,
|
73 | };
|