UNPKG

@atomist/sdm-core

Version:

Atomist Software Delivery Machine - Implementation

62 lines 3.31 kB
"use strict"; /* * 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 sdm_1 = require("@atomist/sdm"); const slack_messages_1 = require("@atomist/slack-messages"); const SetDeployEnablement_1 = require("./SetDeployEnablement"); const displayDeployEnablement = (cli) => __awaiter(void 0, void 0, void 0, function* () { const enabled = yield sdm_1.isDeployEnabled({ context: cli.context, id: cli.parameters }); const msgId = automation_client_1.guid(); return cli.context.messageClient.respond(reportDeployEnablement(cli.parameters, enabled, msgId), { id: cli.parameters.msgId }) .then(() => automation_client_1.Success, automation_client_1.failure); }); function reportDeployEnablement(params, enabled, msgId) { const text = `Deploy is currently ${enabled ? "enabled" : "disabled"} on ${slack_messages_1.bold(`${params.owner}/${params.repo}`)}`; const actions = [automation_client_1.buttonForCommand({ text: enabled ? "Disable" : "Enable" }, enabled ? "DisableDeploy" : "EnableDeploy", Object.assign(Object.assign({}, params), { msgId }))]; const msg = { attachments: [{ author_icon: `https://images.atomist.com/rug/check-circle.gif?gif=${automation_client_1.guid()}`, author_name: "Deploy Enablement", text, fallback: text, color: enabled ? "#37A745" : "#B5B5B5", mrkdwn_in: ["text"], actions, footer: `${params.name}:${params.version}`, }], }; return msg; } exports.reportDeployEnablement = reportDeployEnablement; exports.DisplayDeployEnablement = { name: "DisplayDeployEnablement", description: "Display whether deployment via Atomist SDM in enabled", intent: "is deploy enabled?", paramsMaker: SetDeployEnablement_1.SetDeployEnablementParameters, listener: displayDeployEnablement, }; //# sourceMappingURL=DisplayDeployEnablement.js.map