1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import {
|
18 | addressEvent,
|
19 | failure,
|
20 | HandlerError,
|
21 | HandlerResult,
|
22 | MappedParameter,
|
23 | MappedParameters,
|
24 | Parameter,
|
25 | Parameters,
|
26 | Success,
|
27 | Value,
|
28 | } from "@atomist/automation-client";
|
29 | import {
|
30 | CommandHandlerRegistration,
|
31 | CommandListenerInvocation,
|
32 | slackSuccessMessage,
|
33 | } from "@atomist/sdm";
|
34 | import { bold } from "@atomist/slack-messages";
|
35 | import {
|
36 | DeployEnablementRootType,
|
37 | SdmDeployEnablement,
|
38 | } from "../../ingesters/sdmDeployEnablement";
|
39 |
|
40 | @Parameters()
|
41 | export class SetDeployEnablementParameters {
|
42 |
|
43 | @Parameter({ required: false, displayable: false })
|
44 | public msgId?: string;
|
45 |
|
46 | @MappedParameter(MappedParameters.GitHubOwner)
|
47 | public owner: string;
|
48 |
|
49 | @MappedParameter(MappedParameters.GitHubRepository)
|
50 | public repo: string;
|
51 |
|
52 | @MappedParameter(MappedParameters.GitHubRepositoryProvider)
|
53 | public providerId: string;
|
54 |
|
55 | @Value("name")
|
56 | public name: string;
|
57 |
|
58 | @Value("version")
|
59 | public version: string;
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | export function setDeployEnablement(cli: CommandListenerInvocation<SetDeployEnablementParameters>,
|
69 | enable: boolean): Promise<HandlerResult | HandlerError> {
|
70 | const deployEnablement: SdmDeployEnablement = {
|
71 | state: enable ? "requested" : "disabled",
|
72 | owner: cli.parameters.owner,
|
73 | repo: cli.parameters.repo,
|
74 | providerId: cli.parameters.providerId,
|
75 | };
|
76 | return cli.context.messageClient.send(deployEnablement, addressEvent(DeployEnablementRootType))
|
77 | .then(() => cli.context.messageClient.respond(
|
78 | slackSuccessMessage(
|
79 | "Deploy Enablement",
|
80 | `Successfully ${enable ? "enabled" : "disabled"} deployment of ${
|
81 | bold(`${cli.parameters.owner}/${cli.parameters.repo}`)}`,
|
82 | {
|
83 | footer: `${cli.parameters.name}:${cli.parameters.version}`,
|
84 | }), { id: cli.parameters.msgId }))
|
85 | .then(() => Success, failure);
|
86 | }
|
87 |
|
88 | export const EnableDeploy: CommandHandlerRegistration<SetDeployEnablementParameters> = {
|
89 | name: "EnableDeploy",
|
90 | intent: "enable deploy",
|
91 | description: "Enable deployment via Atomist SDM",
|
92 | paramsMaker: SetDeployEnablementParameters,
|
93 | listener: async cli => setDeployEnablement(cli, true),
|
94 | };
|
95 |
|
96 | export const DisableDeploy: CommandHandlerRegistration<SetDeployEnablementParameters> = {
|
97 | name: "DisableDeploy",
|
98 | intent: "disable deploy",
|
99 | description: "Disable deployment via Atomist SDM",
|
100 | paramsMaker: SetDeployEnablementParameters,
|
101 | listener: async cli => setDeployEnablement(cli, false),
|
102 | };
|
103 |
|
\ | No newline at end of file |