<commit_before>## slack notification requires:
# set :slack_channel
# set :slack_team
# set :slack_token
# set :stage, "production"

class ShipistranoSlack
  require 'net/http'

  def self.post_to_slack(slack_team, slack_token, slack_channel, message)
    uri = URI(URI.encode("https://#{slack_team}.slack.com/services/hooks/slackbot?token=#{slack_token}&channel=##{slack_channel}"))

    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
      http.request_post uri.request_uri, message
    end
  end

end

namespace :slack do
  task :prenotify do
    user = `whoami`.chomp.split(".").map(&:capitalize).join(' ')
    revision = `cat #{local_cache}/REVISION`.chomp
    message = "#{user} is deploying #{app} version #{revision} to #{stage}"

    ShipistranoSlack.post_to_slack(slack_team, slack_token, slack_channel, message)
  end

  task :postnotify do
    user = `whoami`.chomp.split(".").map(&:capitalize).join(' ')
    revision = `cat #{local_cache}/REVISION`.chomp
    message = "#{user} has deployed #{app} version #{revision} to #{stage}"

    ShipistranoSlack.post_to_slack(slack_team, slack_token, slack_channel, message)
  end
end

before 'deploy', 'slack:prenotify'

after 'deploy:create_symlink', 'slack:postnotify'<commit_msg>Make sure slack is last to be notified<commit_after>## slack notification requires:
# set :slack_channel
# set :slack_team
# set :slack_token
# set :stage, "production"

class ShipistranoSlack
  require 'net/http'

  def self.post_to_slack(slack_team, slack_token, slack_channel, message)
    uri = URI(URI.encode("https://#{slack_team}.slack.com/services/hooks/slackbot?token=#{slack_token}&channel=##{slack_channel}"))

    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
      http.request_post uri.request_uri, message
    end
  end

end

namespace :slack do
  task :prenotify do
    user = `whoami`.chomp.split(".").map(&:capitalize).join(' ')
    revision = `cat #{local_cache}/REVISION`.chomp
    message = "#{user} is deploying #{app} version #{revision} to #{stage}"

    ShipistranoSlack.post_to_slack(slack_team, slack_token, slack_channel, message)
  end

  task :postnotify do
    user = `whoami`.chomp.split(".").map(&:capitalize).join(' ')
    revision = `cat #{local_cache}/REVISION`.chomp
    message = "#{user} has deployed #{app} version #{revision} to #{stage}"

    ShipistranoSlack.post_to_slack(slack_team, slack_token, slack_channel, message)
  end
end

before 'deploy', 'slack:prenotify'

after 'deploy:cleanup', 'slack:postnotify'
{'fraction_non_alphanumeric': 0.14682539682539683, 'fraction_numerical': 0.0, 'mean_word_length': 4.9739336492890995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664048', 'n_tokens_mistral': 915, 'n_tokens_neox': 886, 'n_words': 186}