Commit 9d33ba6d authored by PiTrem's avatar PiTrem
Browse files

add slackistrano

parent 6479e644
......@@ -13,6 +13,7 @@ require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
#require 'capistrano/delayed_job'
require 'whenever/capistrano'
require 'slackistrano/capistrano'
require_relative 'lib/slackistrano_custom_messaging'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
......@@ -167,6 +167,7 @@ group :development, :test do
gem 'capistrano-rails'
gem 'capistrano-rvm'
# gem 'capistrano3-delayed-job'
gem 'slackistrano'
end
group :test do
......
......@@ -486,6 +486,8 @@ GEM
skinny (0.2.4)
eventmachine (~> 1.0.0)
thin (>= 1.5, < 1.7)
slackistrano (3.8.1)
capistrano (>= 3.8.1)
spring (1.7.1)
sprite-factory (1.7.1)
sprockets (3.7.1)
......@@ -630,6 +632,7 @@ DEPENDENCIES
sass-rails (~> 5.0, >= 5.0.6)
sdoc (~> 0.4.0)
selenium-webdriver (~> 3.0.5)
slackistrano
spring
stackprof
swot
......
......@@ -50,6 +50,8 @@ set :linked_dirs, fetch(:linked_dirs, []).push(
set :rvm_ruby_version, (`cat .ruby-version`).strip
set :slackistrano, false
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
......
# modified from https://github.com/phallstrom/slackistrano#customizing-the-messaging
if defined?(Slackistrano::Messaging)
module Slackistrano
class SlackistranoCustomMessaging < Messaging::Base
# Send failed message to #ops. Send all other messages to default channels.
# The #ops channel must exist prior.
# def channels_for(action)
# if action == :failed
# "#ops"
# else
# super
# end
# end
# def payload_for_updating
# nil
# end
def payload_for_updating
{
text: "#{member_links}: On server #{server_hostnames} " + super[:text]
}
end
# Fancy updated message.
# See https://api.slack.com/docs/message-attachments
def payload_for_updated
{
text: "#{member_links}",
attachments: [{
color: 'good',
title: ':tada: Application Deployed :tada:',
fields: [{
title: 'Environment',
value: stage,
short: true
}, {
title: 'server',
value: server_hostnames,
short: true
}, {
title: 'Branch',
value: branch,
short: true
}, {
title: 'Deployer',
value: deployer,
short: true
}, {
title: 'Time',
value: elapsed_time,
short: true
}],
fallback: super[:text]
}]
}
end
# Default reverted message. Alternatively simply do not redefine this
# method.
# def payload_for_reverted
# super
# end
# Slightly tweaked failed message.
# See https://api.slack.com/docs/message-formatting
def payload_for_failed
payload = super
payload[:text] = ":shit: on server #{server_hostnames} #{payload[:text]} "
payload
end
# Override the deployer helper to pull the best name available (git, password file, env vars).
# See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb
# def deployer
# name = `git config user.name`.strip
# name = nil if name.empty?
# name ||= Etc.getpwnam(ENV['USER']).gecos || ENV['USER'] || ENV['USERNAME']
# name
# end
def server_hostnames
roles(:web).map do |host|
"#{host.user}@#{host.hostname}"
end.join(', ')
end
def member_links
fetch(:slack_members, nil)&.inject do |ms,m|
ms << "<@#{m}>"
end
end
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment