Last active
January 1, 2016 12:48
-
-
Save kkosuge/8146681 to your computer and use it in GitHub Desktop.
forked from https://github.com/mitukiii/capistrano-chatwork
Capistrano 3 用デプロイすると ChatWork に通知するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
kkosuge
commented
Dec 27, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment