require 'capistrano/sozo_magento2/slack'
include SozoMagento2::Slack
namespace :slack do
desc "Post to channel that the site has been deployed" task :deployed do on roles(:all) do slack_template = message_hash slack_template['text'] = "#{fetch(:url)} Deployment Process Successful" slack_template['blocks'][0]['text']['text'] = ":smile: Deployment Successful :smile:" slack_template['blocks'][2]['text']['text'] = "#{fetch(:url)} Deployed." execute :curl, "--request", "POST", "--header", "'Content-Type: application/json'", "--data", "'" + JSON.generate(slack_template) + "'", fetch(:slack_webhook) end end desc "Post to channel that the site is being deployed" task :deploying do on roles(:all) do slack_template = message_hash slack_template['text'] = "#{fetch(:url)} Deployment Process Begun" slack_template['blocks'][0]['text']['text'] = ":crossed_fingers: Deployment Process Begun :crossed_fingers:" slack_template['blocks'][2]['text']['text'] = "#{fetch(:url)} is being Deployed." execute :curl, "--request", "POST", "--header", "'Content-Type: application/json'", "--data", "'" + JSON.generate(slack_template) + "'", fetch(:slack_webhook) end end desc "Post to channel that something is happening" task :message do on roles(:all) do slack_template = message_hash slack_template['text'] = "Some message here" slack_template['blocks'][0]['text']['text'] = "Message" slack_template['blocks'][2]['text']['text'] = "Some message to go here" execute :curl, "--request", "POST", "--header", "'Content-Type: application/json'", "--data", "'" + JSON.generate(slack_template) + "'", fetch(:slack_webhook) end end desc "Post to channel that the site deployment has failed" task :failed do on roles(:all) do slack_template = message_hash slack_template['text'] = "#{fetch(:url)} Deployment Process Failed!" slack_template['blocks'][0]['text']['text'] = ":boom: Deployment Process Failed :boom:" slack_template['blocks'][2]['text']['text'] = "#{fetch(:url)} deployment has failed." execute :curl, "--request", "POST", "--header", "'Content-Type: application/json'", "--data", "'" + JSON.generate(slack_template) + "'", fetch(:slack_webhook) end end
end