Created
June 3, 2009 03:35
-
-
Save kelan/122774 to your computer and use it in GitHub Desktop.
run queued trac post commits
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 | |
tracDir = '/home/myUser/trac_projects/myProject' | |
logFilePath = tracDir + '/queued_post_commits.txt' | |
doneFilePath = tracDir + '/queued_post_commits_done.txt' | |
errorFilePath = tracDir + '/queued_post_commits_errors.txt' | |
postCommitScriptPath = tracDir + '/trac-post-commit-hook.py' | |
tracURL = 'http://trac.myDomain.com/myProject/' | |
errorEmailTo = '[email protected]' | |
queuedCommits = Array.new | |
begin | |
File.open(logFilePath, "r") do |file| | |
file.each_line do |line| | |
queuedCommits << line | |
end | |
end | |
rescue | |
# no queued commits to process | |
exit | |
end | |
# Empty out the file | |
system("echo '' > #{logFilePath}") | |
queuedCommits.each do |line| | |
line.chomp! | |
repo,rev = line.split(':') | |
next unless repo and rev | |
logMessage = `/usr/bin/svnlook log -r #{rev} #{repo}` | |
author = `/usr/bin/svnlook author -r #{rev} #{repo}` | |
# to make sure python can fine the trac module | |
exportCmd = 'export PYTHONPATH="$HOME/packages/lib/python2.4/site-packages/:$PYTHONPATH"' | |
postCommitCmd = %{/usr/bin/python #{postCommitScriptPath} -p "#{tracDir}" -r "#{rev}" -u "#{author}" -m "#{logMessage}" -s "#{tracURL}"} | |
if system("#{exportCmd}; #{postCommitCmd}") | |
# log the success | |
File.open(doneFilePath, "a") do |file| | |
file.puts("#{Time.now}:#{repo}:#{rev}:#{author}:#{logMessage}") | |
end | |
else | |
# write an error | |
errorCode = $? | |
File.open(errorFilePath, "a") do |file| | |
file.puts("#{Time.now}:#{errorCode}:#{repo}:#{rev}:#{author}:#{logMessage}") | |
end | |
# and put the commit info back in the queue file | |
File.open(logMessage, "a") do |file| | |
file.puts line | |
end | |
# send an email | |
system("echo #{errorFilePath} | mail -s 'Post Commit Errors' #{errorEmailTo}") | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment