2008-09-29 3 views

답변

2

기본값은 commit-email.pl이며 Subversion을 설치할 때 포함됩니다. 그러나 here 루비에서 하나 : 당신의 SVN 저장소의 후크 디렉토리에서

#!/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

, 당신은 포스트 commit.tmpl 스크립트를 찾을 수 있습니다. 그것을 "post-commit"이라는 이름으로 복사하고 적합하도록 편집하십시오. 보통 Subversion과 함께 제공되는 commit-email.pl 스크립트를 실행합니다. 또한 원하는 방식으로 편집 할 수 있어야합니다.

2

웬일인지, 루비 스크립트와 기본 훅 스크립트가 나에게 적합하지 않았다. 이것은 우리의 메일 서버와 몇 가지 이상한 점 때문일 수도 있지만 어쨌든 여기에서 중요한 부분을 포함합니다 :

#!/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를 설치해야합니다. perl과 함께 제공되는 cpan을 먼저 설치하면됩니다. 그런 다음 cpan을 시작하고 SVN :: Notify 라이브러리를 설치해야합니다.

$ cpan 
cpan> install SVN::Notify 

'$'및 'cpan>'부분은 단지 프롬프트이므로 입력 할 필요가 없습니다.

이 솔루션은 제가 언급 한 메일 서버의 문제를 해결하는 데 도움이되는 자세한 오류 메시지를 제공했기 때문에 훨씬 매력적이었습니다. 또한 여러 저장소가 있으므로 전체 프로그램/스크립트를 각 디렉토리에 복사하는 것이 불필요합니다. 귀하의 마일리지가 다를 수 있습니다.

맨 위에있는 코드 블록의 텍스트는 "post-commit"이라는 텍스트 파일에 있어야합니다. 이 파일은/path/to/svn/repos/repository_name/hooks에 있고 실행 가능으로 표시되어야합니다.

+0

가'CPAN을하려고 – philfreo

+0

또한주의 "NET/SMTP_auth.pm가 @INC에서 찾을 수 없습니다" Gmail로 보내기 위해 기본적으로 작동하지 않습니다. http://cpanforum.com/posts/10541와'cpan> install Net :: SMTP :: SSL'을보십시오. – philfreo

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

받은 후 인터넷 :: SMTP_auth`를 설치> 나는 또한 한이

/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

관련 문제