Skip to content

Instantly share code, notes, and snippets.

@z0lope0z
Created March 18, 2016 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0lope0z/dbc00525b14927ab0f31 to your computer and use it in GitHub Desktop.
Save z0lope0z/dbc00525b14927ab0f31 to your computer and use it in GitHub Desktop.
git hook for sending email regarding migration changes
#!/usr/bin/env ruby
require 'pony'
def send_mail(to, from, message)
Pony.mail({
:to => to,
:via => :smtp,
:from => from,
:subject => 'new migrations detected for master branch',
:body => message,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV["EMAIL_USERNAME"],
:password => ENV["EMAIL_PASSWORD"],
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
}
})
end
branch = `git rev-parse --abbrev-ref HEAD`.strip
if branch == 'master'
migration_diff = `git diff HEAD^ db/migrate`
send_mail('email_to', 'email_from', migration_diff)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment