2

可以和我分享这个脚本吗?

4

5 回答 5

2

默认的被称为 commit-email.pl 并且在您安装 Subversion 时包含在内。但这里有一个红宝石:

#!/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)
于 2008-09-29T08:37:42.753 回答
2

出于某种原因,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。您可以通过首先安装 cpan 来安装它,它应该随 perl 一起提供。然后你需要启动 cpan 并安装 SVN::Notify 库。

$ cpan
cpan> install SVN::Notify

请注意,'$' 和 'cpan>' 部分只是提示,您不需要输入它们。

这个解决方案对我来说更有吸引力,因为它提供了详细的错误消息,有助于解决我提到的邮件服务器的这些问题。我们还有多个存储库,因此将整个程序/脚本复制到每个目录中是多余的。你的旅费可能会改变。

顶部代码块中的文本应放在名为“post-commit”的文本文件中。该文件应位于 /path/to/svn/repos/repository_name/hooks 并标记为可执行文件。

于 2008-09-29T08:59:03.950 回答
1

在 svn 存储库的 hooks 目录中,您会找到一个 post-commit.tmpl 脚本。将其复制以命名为“post-commit”并对其进行编辑以适应。通常它会运行 subversion 自带的 commit-email.pl 脚本;这还需要编辑以设置您想要的东西。

于 2008-09-29T08:43:18.497 回答
1
#!/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
于 2011-03-10T00:53:49.733 回答
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 'abc@xyz.com' --from 'svn@xyz.com' --set-sender

于 2015-04-18T09:43:10.967 回答