2008-09-29 31 views

回答

2

默認的一個名爲commit-email.pl,當您安裝Subversion時會包含它。但是here是一個在紅寶石:

#!/usr/bin/ruby -w 

# A Subversion post-commit hook. Edit the configurable stuff below, and 
# copy into your repository's hooks/ directory as "post-commit". Don't 
# forget to "chmod a+x post-commit". 

# ------------------------------------------------------------------------ 

# You *will* need to change these. 

address="[email protected]_DOMAIN.com" 
sendmail="/usr/sbin/sendmail" 
svnlook="/usr/bin/svnlook" 

# ------------------------------------------------------------------------ 

require 'cgi' 

# Subversion's commit-email.pl suggests that svnlook might create files. 
Dir.chdir("/tmp") 

# What revision in what repository? 
repo = ARGV.shift() 
rev = ARGV.shift() 

# Get the 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 the overview. 
body = "<p><b>#{author}</b> #{date}</p>" 
body << "<p>" 
comment.each { |line| body << "#{CGI.escapeHTML(line)}<br/>\n" } 
body << "</p>" 
body << "<hr noshade>" 

# Get and output the patch. 
changes=`#{svnlook} diff #{repo} -r #{rev}` 
body << "<pre>" 
changes.each do |top_line| 
    top_line.split("\n").each do |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 the 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 the mail. 
begin 
    fd = open("|#{sendmail} #{address}", "w") 
    fd.print(header) 
    fd.print(body) 
rescue 
    exit(1) 
end 
fd.close 

# We're done. 
exit(0) 
1

在你的svn庫的鉤子目錄,你會發現一個後commit.tmpl腳本。複製它以命名爲「提交後」並對其進行編輯以適應。通常它會運行subversion附帶的commit-email.pl腳本;那也需要編輯來設定你想要的東西。

2

由於某些原因,ruby腳本和默認鉤子腳本不適用於我。這可能是由於有些古怪的地方與我們的郵件服務器,但我會在這裏反正包括重要的部分:

#!/bin/sh 

REPOS="$1" 
REV="$2" 

svnnotify --repos-path "$REPOS" --revision "$REV" --with-diff --to [email protected] --smtp mailserver.domain --from [email protected] -VVVVVVVVV -P "[repository_name]" 

的-VVVVVVV部分顯示非常詳細的消息,如果你想在腳本之外測試命令。它應該在實際的腳本中被刪除。

當然,爲了這個工作,你需要安裝svnnotify。你可以通過首先安裝cpan來安裝,這應該與perl一起提供。然後你需要啓動cpan並安裝SVN :: Notify庫。

$ cpan 
cpan> install SVN::Notify 

請注意'$'和'cpan>'部分只是提示,您不需要輸入它們。

這個解決方案對我來說更具吸引力,因爲它提供了詳細的錯誤信息,這些錯誤信息有助於解決我提到的郵件服務器的這些問題。我們也有多個存儲庫,因此將整個程序/腳本複製到每個目錄中都是多餘的。你的旅費可能會改變。

頂部代碼塊中的文本應放置在名爲「post-commit」的文本文件中。該文件應位於/ path/to/svn/repos/repository_name/hooks並標記爲可執行文件。

+0

我也不得不這樣做`CPAN>獲得後安裝的Net :: SMTP_auth` 「無法找到網/ SMTP_auth.pm在@INC」 – philfreo 2010-08-09 20:18:03

1
#!/bin/ksh 
# 
# This is a custom post-commit for sending email 
# when an svn repo is changed. 
# 

rcpts="[email protected], [email protected]" 

repodir=$1 
revision=$2 

author=`/usr/bin/svnlook author -r $revision $repodir` 
date=`/usr/bin/svnlook date -r $revision $repodir` 
log=`/usr/bin/svnlook log  -r $revision $repodir` 
info=`/usr/bin/svnlook changed -r $revision $repodir` 

repo=${repodir##*/} 

subject="$repo svn updated by $author" 

url="https://myserver.bar.edu/svn/$repo" 

/usr/bin/mail -s "$subject" "$rcpts"<<EOM 
repository: $url 
date:  $date 
username: $author 
revision: $revision 
comment: $log 

$info 
EOM 
0

試試這個

/usr/bin/svnnotify --revision "$REV" --repos-path "$REPOS" \ --subject-cx --subject-prefix "[Project:commit] " --max-sub-length 128 \ --with-diff --handler Alternative --alt HTML::ColorDiff \ --to '[email protected]' --from '[email protected]' --set-sender

相關問題