From 28d0af5f0c73a89e0455fa1615da0cf46da8d7cb Mon Sep 17 00:00:00 2001 From: Laurent Vallar Date: Thu, 21 Jun 2018 17:39:12 +0200 Subject: [PATCH 1/3] update set_default calls mina version >= 1.X Fix #4 Signed-off-by: Laurent Vallar --- lib/mina/slack/defaults.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/mina/slack/defaults.rb b/lib/mina/slack/defaults.rb index d552cac..94e7fd9 100644 --- a/lib/mina/slack/defaults.rb +++ b/lib/mina/slack/defaults.rb @@ -1,11 +1,11 @@ # Required -set_default :slack_url, -> { ENV['SLACK_URL'] } -set_default :slack_room, -> { ENV['SLACK_ROOM'] } +set :slack_url, -> { ENV['SLACK_URL'] } +set :slack_room, -> { ENV['SLACK_ROOM'] } # Optional -set_default :slack_stage, -> { ENV['SLACK_STAGE'] || ENV['to'] || fetch(:rails_env, 'production') } -set_default :slack_application, -> { ENV['SLACK_APPLICATION'] || application } -set_default :slack_username, -> { ENV['SLACK_USERNAME'] || 'deploybot' } -set_default :slack_emoji, -> { ENV['SLACK_EMOJI'] || ':cloud:' } +set :slack_stage, -> { ENV['SLACK_STAGE'] || ENV['to'] || fetch(:rails_env, 'production') } +set :slack_application, -> { ENV['SLACK_APPLICATION'] || application } +set :slack_username, -> { ENV['SLACK_USERNAME'] || 'deploybot' } +set :slack_emoji, -> { ENV['SLACK_EMOJI'] || ':cloud:' } # Git -set_default :deployer, -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp } -set_default :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{branch}].strip } +set :deployer, -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp } +set :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{branch}].strip } From bdf29621dd2f4fb5de2f8d83a5b1dbba2639ef5c Mon Sep 17 00:00:00 2001 From: Laurent Vallar Date: Thu, 21 Jun 2018 18:58:47 +0200 Subject: [PATCH 2/3] use fetch to get settings Signed-off-by: Laurent Vallar --- lib/mina/slack/defaults.rb | 4 ++-- lib/mina/slack/tasks.rb | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/mina/slack/defaults.rb b/lib/mina/slack/defaults.rb index 94e7fd9..2eba79c 100644 --- a/lib/mina/slack/defaults.rb +++ b/lib/mina/slack/defaults.rb @@ -3,9 +3,9 @@ set :slack_room, -> { ENV['SLACK_ROOM'] } # Optional set :slack_stage, -> { ENV['SLACK_STAGE'] || ENV['to'] || fetch(:rails_env, 'production') } -set :slack_application, -> { ENV['SLACK_APPLICATION'] || application } +set :slack_application, -> { ENV['SLACK_APPLICATION'] || fetch(:application) } set :slack_username, -> { ENV['SLACK_USERNAME'] || 'deploybot' } set :slack_emoji, -> { ENV['SLACK_EMOJI'] || ':cloud:' } # Git set :deployer, -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp } -set :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{branch}].strip } +set :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{fetch(:branch)}].strip } diff --git a/lib/mina/slack/tasks.rb b/lib/mina/slack/tasks.rb index 0a82034..46ff4cf 100644 --- a/lib/mina/slack/tasks.rb +++ b/lib/mina/slack/tasks.rb @@ -13,6 +13,9 @@ namespace :slack do task :starting do + slack_room = fetch(:slack_room) + slack_url = fetch(:slack_url) + if slack_url and slack_room announcement = "#{announced_deployer} is deploying #{announced_application_name} to #{announced_stage}" @@ -24,6 +27,9 @@ end task :finished do + slack_room = fetch(:slack_room) + slack_url = fetch(:slack_url) + if slack_url and slack_room end_time = Time.now start_time = fetch(:start_time) @@ -39,18 +45,23 @@ def announced_stage - slack_stage + fetch(:slack_stage) end def announced_deployer - deployer + fetch(:deployer) end def short_revision + deployed_revision = fetch(:deployed_revision) + deployed_revision[0..7] if deployed_revision end def announced_application_name + slack_application = fetch(:slack_application) + branch = fetch(:branch) + "".tap do |output| output << slack_application if slack_application output << " `#{branch}`" if branch @@ -59,6 +70,11 @@ def announced_application_name end def post_slack_message(message) + slack_emoji = fetch(:slack_emoji) + slack_room = fetch(:slack_room) + slack_url = fetch(:slack_url) + slack_username = fetch(:slack_username) + # Parse the URI and handle the https connection uri = URI.parse(slack_url) http = Net::HTTP.new(uri.host, uri.port) From f680e5b52fffc65cb3fa61900937c0e6e44ff465 Mon Sep 17 00:00:00 2001 From: Laurent Vallar Date: Thu, 21 Jun 2018 19:03:00 +0200 Subject: [PATCH 3/3] remove deprecated before/after_mina calls Signed-off-by: Laurent Vallar --- README.md | 16 ++++++++++++++++ lib/mina/slack/tasks.rb | 6 ------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 718f8cf..359fb1c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,22 @@ Or use the ENV variables: ENV['SLACK_EMOJI'] = '' ENV['SLACK_STAGE'] = '' # or ENV['to'] +### Add tasks +Invoke tasks in your deploy.rb + + ```Ruby + task deploy do + run(:local) { invoke :'slack:starting' } + deploy do + # [...] + on :launch do + # [...] + end + end + run(:local) { invoke :'slack:finished' } + end + ``` + ## Contributing 1. Fork it ( http://github.com//mina-slack/fork ) diff --git a/lib/mina/slack/tasks.rb b/lib/mina/slack/tasks.rb index 46ff4cf..d74c8d8 100644 --- a/lib/mina/slack/tasks.rb +++ b/lib/mina/slack/tasks.rb @@ -3,12 +3,6 @@ require 'json' require 'net/http' - -# Before and after hooks for mina deploy -before_mina :deploy, :'slack:starting' -after_mina :deploy, :'slack:finished' - - # Slack tasks namespace :slack do