Svn hook script email body html formatting -
i have below script sends email whenever developer commits svn repository. mail body includes name of file plus changes developer has added , removed.
i want additions blue , removals red, color formatting not working.
folks can please advise has been long time , stuck solution
#!/usr/bin/ruby -w # subversion post-commit hook. edit configurable stuff below, , # copy repository's hooks/ directory "post-commit". don't # forget "chmod a+x post-commit". # ------------------------------------------------------------------------ # *will* need change these. address="foo@some_domain.com" sendmail="/usr/sbin/sendmail" svnlook="/usr/bin/svnlook" # ------------------------------------------------------------------------ require 'cgi' # subversion's commit-email.pl suggests svnlook might create files. dir.chdir("/tmp") # revision in repository? repo = argv.shift() rev = argv.shift() # overview information. info=`#{svnlook} info #{repo} -r #{rev}` info_lines=info.split("\n") author=info_lines.shift date=info_lines.shift info_lines.shift comment=info_lines # output overview. body = "<p><b>#{author}</b> #{date}</p>" body << "<p>" comment.each { |line| body << "#{cgi.escapehtml(line)}<br/>\n" } body << "</p>" body << "<hr noshade>" # , output patch. changes=`#{svnlook} diff #{repo} -r #{rev}` body << "<pre>" changes.each |top_line| top_line.split("\n").each |line| color = case when line =~ /^modified: / || line =~ /^=+$/ || line =~ /^@@ /: "gray" when line =~ /^-/: "red" when line =~ /^\+/: "blue" else "black" end body << %q{<font style="color:#{color}">#{cgi.escapehtml(line)}</font><br/>\n} end end body << "</pre>" # write header. header = "" header << "to: #{address}\n" header << "from: #{address}\n" header << "subject: [svn] #{repo} revision #{rev}\n" header << "reply-to: #{address}\n" header << "mime-version: 1.0\n" header << "content-type: text/html; charset=utf-8\n" header << "content-transfer-encoding: 8bit\n" header << "\n" # send mail. begin fd = open("|#{sendmail} #{address}", "w") fd.print(header) fd.print(body) rescue exit(1) end fd.close # we're done. exit(0)
i getting mail in outlook in format, not correct. can see html tags coming in between:
to: abferw.arya@def.com from: abferw.arya@def.com subject: [svn] /atc/htr revision 2941 reply-to: abferw.arya@def.com mime-version: 1.0 content-type: text/html; charset=utf-8 content-transfer-encoding: 8bit <p><b>aryasb</b> 2015-04-29 06:39:41 +0100 (wed, 29 apr 2015)</p><p>ok<br/> </p><hr noshade><pre><font style="color:gray">modified: ities/trew/bdev1.properties</font><br/> <font style="color:gray">===================================================================</font><br/> <font style="color:red">--- ities/trew/bdev1.properties 2015-04-29 05:16:46 utc (rev 2950)</font><br/> <font style="color:blue">+++ ities/trew/bdev1.properties 2015-04-29 05:39:41 utc (rev 2951)</font><br/> <font style="color:gray">@@ -20,4 +20,5 @@</font><br/> <font style="color:black"> cube.events.lon=lonrs01815 </font><br/> <font style="color:black"> cube.hermes.lon= </font><br/> <font style="color:black"> cube.external.lon= </font><br/> <font style="color:red">-cube.extras.lon=</font><br/> <font style="color:black">\ no newline @ end of file</font><br/> <font style="color:blue">+cube.extras.lon= </font><br/>
Comments
Post a Comment