"use strict";
/*
 * Copyright © 2020 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.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DisplayDeployEnablement = exports.reportDeployEnablement = void 0;
const HandlerResult_1 = require("@atomist/automation-client/lib/HandlerResult");
const string_1 = require("@atomist/automation-client/lib/internal/util/string");
const MessageClient_1 = require("@atomist/automation-client/lib/spi/message/MessageClient");
const slack_messages_1 = require("@atomist/slack-messages");
const deployPushTests_1 = require("../../../api/mapping/support/deployPushTests");
const SetDeployEnablement_1 = require("./SetDeployEnablement");
const displayDeployEnablement = async (cli) => {
    const enabled = await deployPushTests_1.isDeployEnabled({ context: cli.context, id: cli.parameters });
    const msgId = string_1.guid();
    return cli.context.messageClient.respond(reportDeployEnablement(cli.parameters, enabled, msgId), { id: cli.parameters.msgId })
        .then(() => HandlerResult_1.Success, HandlerResult_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 = [MessageClient_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=${string_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