Last active
August 29, 2015 14:06
-
-
Save kid1412-net/1fb7944259635c3d1c16 to your computer and use it in GitHub Desktop.
SVN post commit
This file contains hidden or 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
#!/home/hain/.rvm/rubies/ruby-1.8.7-head/bin/ruby | |
############################################################### | |
# | |
# This script is written by Akhil Bansal(http://webonrails.com) | |
# It worked fine for me. Use this script at your own risk, if | |
# your computer explode, it will not be my fault ;-) | |
# | |
############################################################### | |
require 'rubygems' | |
gem 'actionmailer', '=2.2.2' | |
require 'action_mailer' | |
require 'cgi' | |
# Fix for Ruby 2.1 | |
# require 'time' | |
# You can edit below | |
# Subject prefix | |
sub = "[svn]" # A project 'test_project' is maitained at vinsol | |
#list of users who will recieve commit notification | |
recipients = ["[email protected]"] | |
# email which will appear in from email field | |
from_user = "\"kid1412_net\" <[email protected]>" | |
# your smtp settings here | |
=begin | |
ActionMailer::Base.smtp_settings = { | |
address: 'smtp.gmail.com', | |
port: 587, | |
domain: 'gmail.com', | |
user_name: '[email protected]', | |
password: 'Abcd1234~@', | |
authentication: 'plain', | |
enable_starttls_auto: true | |
} | |
=end | |
ActionMailer::Base.smtp_settings = { | |
:enable_starttls_auto => true, | |
:address => "smtp.gmail.com", | |
:port => 587, | |
:domain => "gmail.com", | |
:user_name => "[email protected]", | |
:password => "Abcd1234~@", | |
:authentication => "plain" | |
} | |
# Do not edit below this line | |
path = ARGV[0] | |
revision = ARGV[1] | |
class Mailer < ActionMailer::Base | |
def message(to, from_user, sub, message) | |
from from_user | |
recipients to.join(", ") | |
subject sub | |
body message | |
content_type "text/html" | |
end | |
end | |
user = `/usr/bin/svnlook author #{path} -r #{revision}`.chomp | |
log = `/usr/bin/svnlook log #{path} -r #{revision}`.chomp | |
changed = `/usr/bin/svnlook changed #{path} -r #{revision}`.chomp | |
diff = `/usr/bin/svnlook diff #{path} --no-diff-deleted --no-diff-added -r #{revision}`.chomp | |
dirs = `/usr/bin/svnlook dirs-changed #{path} -r #{revision}`.chomp | |
date = `/usr/bin/svnlook date #{path} -r #{revision}`.chomp | |
date = Time.parse(date).getutc + (5.5 * 3600) | |
date = date.strftime("%A %b %d,%Y %I:%M %p") | |
dir_list = dirs.split("\n").collect do |dir| | |
dir =~ /([^\/]+)/ | |
$1 | |
end | |
dir_list.uniq! | |
subject_log = log.slice(0..100) | |
dir_string = dir_list.join(", ") | |
subject = "#{sub} #{user}: \"#{subject_log}\" (Revision:#{revision} )" | |
changed = changed.gsub(/\n/, '<br>') | |
subject = subject.gsub(/\n/, '<br>') | |
message = "<div style = 'color: white; background:#336699 none repeat scroll 0%; border:1px solid #000066; overflow:auto; padding:6px; font-family:verdana,arial,helvetica,sans-serif; font-size:10pt;'><b>Revision:</b> #{revision}<br><b>Author:</b> #{user}<br><b>Date:</b> #{date}<br></div> <br><br>" | |
message += "<div style = 'color: black; background:#FFFFCC none repeat scroll 0%; border:1px solid #FFCC00; overflow:auto; padding:6px;'><b>Log Message: </b>#{CGI.escapeHTML(log)}</div> <br><br>" | |
message += "<div style = 'color: white; background:#336699 none repeat scroll 0%; border:1px solid #000066; overflow:auto; padding:6px; font-family:verdana,arial,helvetica,sans-serif; font-size:10pt;'><b>Modified Path(s):</b><br>#{changed}</div> <br><br>" | |
count = 0 | |
diff.each do |top_line| | |
top_line.split("\n").each do |line| | |
count +=1; | |
# Fix for ruby 2.1.2 | |
# Ref: http://stackoverflow.com/questions/6964876/ruby-1-9-1-syntax-error | |
color = case | |
when line =~ /^\+\+\+ / || line =~ /^--- / then "#FFDD88" | |
when line =~ /^Modified: / || line =~ /^=+$/ || line =~ /^@@ / then "#FFDD88" | |
when line =~ /^-/ then "#FF8888" | |
when line =~ /^\+/ then "#BBFFBB" | |
else "#FFFFFF" | |
end | |
modified = "" | |
if line =~ /^Modified: / | |
modified = true | |
mod_div_border = "border:1px solid black; margin-bottom: 15px;padding:2px;" | |
mod_div_end = "</div>" and count =1 unless count ==1 | |
mod_div = "<div style = '#{mod_div_border}'>" if count == 1 | |
end | |
if line =~ /^\+\+\+/ || line =~ /^---/ || line =~ /^Modified: / || line =~ /^=+$/ || line =~ /^@@ / | |
font = "font-weight: bold;" | |
end | |
if line =~ /^Added: / | |
line = "" | |
end | |
if line =~ /^Property changes on: / | |
mod_div_end = "</div>" and count =1 unless count == 1 | |
mod_div_border = "border:1px solid black; margin-bottom: 15px;" | |
mod_div = "<div style = '#{mod_div_border}'>" if count == 1 | |
color = "#FFCCFF" | |
end | |
if line =~ /^Name: / || line =~ /^ \+/ || line =~ /^___/ | |
line = "" | |
end | |
message << %Q{#{mod_div_end}#{mod_div}<div style="background:#{color};#{font}">#{CGI.escapeHTML(line)}</div>} | |
end | |
end | |
message += "</div>" | |
# Mailer.deliver_message(recipients, from_user, subject, message) | |
File.open('/tmp/svn-pc.log', 'w') do |s| | |
s.puts "#{recipients}, #{from_user}, #{subject}" | |
s.puts "#{path}, #{revision}" | |
s.puts "#{log}" | |
s.puts "#{dirs}" | |
end |
This file contains hidden or 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
[defaults] | |
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s | |
commit_subject_prefix = [svn] | |
max_subject_length = 127 | |
from_addr = [email protected] | |
to_addr = %(author)s | |
# reply_to = | |
generate_diffs = add copy modify | |
show_nonmatching_paths = yes | |
[general] | |
smtp_hostname = smtp.gmail.com:587 | |
smtp_username = [email protected] | |
smtp_password = hellohiking | |
smtp_use_ssl = true | |
[maps] | |
to_addr = [author table] | |
[author table] | |
user = [email protected] |
This file contains hidden or 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
#!/bin/sh | |
# POST-COMMIT HOOK | |
# | |
# The post-commit hook is invoked after a commit. Subversion runs | |
# this hook by invoking a program (script, executable, binary, etc.) | |
# named 'post-commit' (for which this file is a template) with the | |
# following ordered arguments: | |
# | |
# [1] REPOS-PATH (the path to this repository) | |
# [2] REV (the number of the revision just committed) | |
# | |
# The default working directory for the invocation is undefined, so | |
# the program should set one explicitly if it cares. | |
# | |
# Because the commit has already completed and cannot be undone, | |
# the exit code of the hook program is ignored. The hook program | |
# can use the 'svnlook' utility to help it examine the | |
# newly-committed tree. | |
# | |
# On a Unix system, the normal procedure is to have 'post-commit' | |
# invoke other programs to do the real work, though it may do the | |
# work itself too. | |
# | |
# Note that 'post-commit' must be executable by the user(s) who will | |
# invoke it (typically the user httpd runs as), and that user must | |
# have filesystem-level permission to access the repository. | |
# | |
# On a Windows system, you should name the hook program | |
# 'post-commit.bat' or 'post-commit.exe', | |
# but the basic idea is the same. | |
# | |
# The hook program typically does not inherit the environment of | |
# its parent process. For example, a common problem is for the | |
# PATH environment variable to not be set to its usual value, so | |
# that subprograms fail to launch unless invoked via absolute path. | |
# If you're having unexpected problems with a hook program, the | |
# culprit may be unusual (or missing) environment variables. | |
# | |
# Here is an example hook script, for a Unix /bin/sh interpreter. | |
# For more examples and pre-written hooks, see those in | |
# the Subversion repository at | |
# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and | |
# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ | |
REPOS="$1" | |
REV="$2" | |
MAILER_FILE="/data/tmp/svn/subversion-1.8.9/tools/hook-scripts/mailer/mailer.py" | |
CONF_FILE="/data/tmp/svn/my_repo/hooks/mailer/mailer.conf" | |
MAILER_RB="/data/tmp/svn/subversion-1.8.9/tools/hook-scripts/commit_email_new.rb" | |
# /data/tmp/svn/subversion-1.8.9/tools/hook-scripts/mailer/mailer.py commit "$REPOS" "$REV" /data/tmp/svn/subversion-1.8.9/tools/hook-scripts/mailer/mailer.conf | |
# "$MAILER_FILE" commit "$REPOS" "$REV" "$CONF_FILE" > /tmp/commit.log | |
source /home/hain/.rvm/environments/ruby-1.8.7-head | |
/home/hain/.rvm/rubies/ruby-1.8.7-head/bin/ruby "$MAILER_RB" "$REPOS" "$REV" | |
curl -O /dev/null "http://127.0.0.1/sys/fetch_changesets?key=owRgwzudRL795TQ3Wjlq" > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment