Skip to content

Instantly share code, notes, and snippets.

@jerodsanto
Created November 25, 2008 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jerodsanto/29142 to your computer and use it in GitHub Desktop.
Save jerodsanto/29142 to your computer and use it in GitHub Desktop.
#!/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