Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
run queued trac post commits
#!/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 = 'me@myDomain.com'
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