Last active
August 29, 2015 13:56
-
-
Save sorentwo/9072369 to your computer and use it in GitHub Desktop.
Slack deploy notification task (adapted from capistrano-slack)
This file contains hidden or 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' | |
| namespace :slack do | |
| def post_to_slack(payload) | |
| slack_subdomain = fetch(:slack_subdomain) | |
| slack_token = fetch(:slack_token) | |
| uri = URI.parse("https://#{slack_subdomain}.slack.com/services/hooks/incoming-webhook?token=#{slack_token}") | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = true | |
| http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
| request = Net::HTTP::Post.new(uri.request_uri) | |
| request.set_form_data(payload: payload.merge(default_payload).to_json) | |
| http.request(request) | |
| end | |
| def default_payload | |
| { channel: fetch(:slack_room), username: 'deploybot', icon_emoji: ':ghost:' } | |
| end | |
| desc 'Begin deploy notifications to Slack' | |
| task :starting do | |
| announced_deployer = fetch(:deployer) | |
| announced_stage = fetch(:stage) | |
| application = fetch(:slack_application) | |
| post_to_slack(text: "#{announced_deployer} is deploying #{application} to #{announced_stage}") | |
| set(:start_time, Time.now) | |
| end | |
| task :finished do | |
| announced_deployer = fetch(:deployer) | |
| application = fetch(:slack_application) | |
| elapsed_time = Time.now.to_i - fetch(:start_time).to_i | |
| post_to_slack(text: "#{announced_deployer} deployed #{application} successfully in #{elapsed_time} seconds.") | |
| end | |
| before 'deploy', 'slack:starting' | |
| after 'deploy', 'slack:finished' | |
| end |
Maybe even a link to the commit on GitHub?
Really awesome to see a custom slack integration at work!
Author
The SHA should be pretty easy, as we can just grab it with git. We could probably hack together a github link from the SHA if desired.
Nice. Thinking of adapting this integration for the dscovr deploy process as well. Looks pretty straight-forward!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we include the short git sha in the deploy notice?