Skip to content

Instantly share code, notes, and snippets.

@kkosuge
Last active January 1, 2016 12:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkosuge/8146681 to your computer and use it in GitHub Desktop.
Save kkosuge/8146681 to your computer and use it in GitHub Desktop.
forked from https://github.com/mitukiii/capistrano-chatwork Capistrano 3 用デプロイすると ChatWork に通知するやつ
require 'json'
require 'net/http'
namespace :chatwork do
def post_message(message)
uri = URI("https://api.chatwork.com/v1/rooms/#{fetch(:chatwork_room_id)}/messages")
req = Net::HTTP::Post.new(uri)
req['X-ChatWorkToken'] = fetch(:chatwork_api_token)
req.set_form_data('body' => message)
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
case res
when Net::HTTPSuccess
else
logger.important JSON.parse(res.body)['errors'].first
end
end
def user
if (u = `git config user.name`.strip) != ''
u
elsif (u = ENV['USER']) != ''
u
else
'Someone'
end
end
def deployment_name
if fetch(:branch)
"#{fetch(:application)}/#{fetch(:branch)}"
else
application
end
end
def message
fetch(:revision_log_message,
t(:revision_log_message,
branch: fetch(:branch),
user: user,
sha: fetch(:current_revision),
release: release_timestamp)
)
end
task :notify do
post_message(message)
end
end
@kkosuge
Copy link
Author

kkosuge commented Dec 27, 2013

cd lib/capistrano/tasks/
wget https://gist.github.com/kkosuge/8146681/raw/b711781e3ae8959bd181dca46d69b09f1a29fe9e/chatwork.cap

cd ../../../
vim config/deploy.rb

+ set :chatwork_api_token, 'your api token'
+ set :chatwork_room_id, 'your room id'
+ after :finishing, 'chatwork:notify'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment