Created
March 18, 2016 08:22
-
-
Save z0lope0z/dbc00525b14927ab0f31 to your computer and use it in GitHub Desktop.
git hook for sending email regarding migration changes
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
#!/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