このスクリプトを共有できますか?
5 に答える
何らかの理由で、Ruby スクリプトとデフォルトのフック スクリプトが機能しませんでした。これは、メール サーバーの奇妙な点によるものかもしれませんが、重要な部分をここに含めておきます。
#!/bin/sh
REPOS="$1"
REV="$2"
svnnotify --repos-path "$REPOS" --revision "$REV" --with-diff --to mailinglist@server.domain --smtp mailserver.domain --from svn@server.domain -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 に配置し、実行可能としてマークする必要があります。
デフォルトのものは commit-email.pl と呼ばれ、Subversion のインストール時に含まれます。しかし、ここにルビーの1つがあります:
#!/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="FOO@SOME_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)
#!/bin/ksh
#
# This is a custom post-commit for sending email
# when an svn repo is changed.
#
rcpts="foo@bar.edu, baz@bar.edu"
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
svn リポジトリの hooks ディレクトリに、post-commit.tmpl スクリプトがあります。「post-commit」という名前になるようにコピーし、それに合わせて編集します。通常、Subversion に付属の commit-email.pl スクリプトを実行します。また、必要に応じて設定するための編集も必要になります。