gpt4 book ai didi

svn - 有人有提交通知 Hook 脚本,可以在提交代码时发送电子邮件吗?

转载 作者:行者123 更新时间:2023-12-02 09:02:25 25 4
gpt4 key购买 nike

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

最佳答案

默认的名称为 commit-email.pl,在安装 Subversion 时包含在内。但是here是 ruby 中的一个:

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

关于svn - 有人有提交通知 Hook 脚本,可以在提交代码时发送电子邮件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/147924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com