-
-
Save vangberg/29184 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/env ruby | |
#-- | |
# Name : git_watch.rb | |
# Author : Jerod Santo | |
# Contact : "moc.liamg@otnas.dorej".reverse | |
# Date : 2008 October 14 | |
# About : Checks a git repository for changes and emails provided email | |
# address if changes have been made. Schedule with cron. | |
#-- | |
require 'net/smtp' | |
require 'fileutils' | |
SEND_TO = "jerod.santo@gmail.com" | |
def send_email(to,opts={}) | |
opts[:server] ||= 'localhost' | |
opts[:from] ||= 'git@example.com' | |
opts[:from_alias] ||= 'Git Watch' | |
opts[:subject] ||= "A repo has changed!" | |
opts[:body] ||= "A repo has changed!" | |
msg = <<END_OF_MESSAGE | |
From: #{opts[:from_alias]} <#{opts[:from]}> | |
To: <#{to}> | |
Subject: #{opts[:subject]} | |
#{opts[:body]} | |
END_OF_MESSAGE | |
Net::SMTP.start(opts[:server]) do |smtp| | |
smtp.send_message msg, opts[:from], to | |
end | |
end | |
unless ARGV.length == 1 | |
puts "Usage: #{__FILE__} [path to repo with .git directory]" | |
exit | |
end | |
path = File.expand_path(ARGV.first) | |
unless Dir.entries(path).include? ".git" | |
puts "Sorry, but there's no git repository in #{path}" | |
exit | |
end | |
FileUtils.cd path | |
result = `git status` | |
unless result =~ /working directory clean/ | |
message = "Host: #{`hostname`}\n" | |
message += "Repository: #{path}\n" | |
message += "Checked at: #{Time.now}\n" | |
message += "Change log:\n\n" | |
message += result | |
send_email SEND_TO, :body => message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment