Created
July 2, 2013 20:12
-
-
Save tmountain/5912701 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
require 'net/smtp' | |
FROM = "noc@example.com" | |
DOMAIN = "example.com" | |
ACCOUNT = "gmail.account@example.com" | |
PASSWORD = "secret" | |
def current_commit | |
pipe = IO.popen("git log") | |
commit = pipe.gets | |
pipe.close | |
return commit.split.last | |
end | |
def previous_commit | |
fh = File.new('/tmp/git.last', 'r') | |
commit = fh.read.chomp | |
fh.close | |
return commit | |
end | |
def log_current_commit | |
fh = File.new('/tmp/git.last', 'w') | |
fh.write current_commit | |
fh.close | |
end | |
def get_changes(previous_commit, current_commit) | |
puts "git log #{previous_commit}..#{current_commit}" | |
pipe = IO.popen("git log #{previous_commit}..#{current_commit}") | |
data = pipe.readlines | |
pipe.close | |
return data.to_s | |
end | |
def send_email(to, body, opts={}) | |
msg = "Subject: WENTLIVE (app.example.com)\n\n#{body}" | |
smtp = Net::SMTP.new 'smtp.gmail.com', 587 | |
smtp.enable_starttls | |
smtp.start(DOMAIN, ACCOUNT, PASSWORD, :login) do | |
smtp.send_message(msg, FROM, to) | |
end | |
end | |
arg = ARGV[0] | |
if arg == 'log_current_commit' | |
log_current_commit | |
elsif arg == 'email_change_manifest' | |
current = current_commit | |
previous = previous_commit | |
send_email('all@example.com', get_changes(previous, current)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment