当特定文件更改时,SVN 提交后挂钩向电子邮件用户发送

发布于 2024-12-05 14:46:44 字数 108 浏览 0 评论 0原文

我想添加一个提交后挂钩,以便如果用户提交对特定文件的更改,我将收到电子邮件通知。

有没有人见过这样的例子,或者有可能吗?

我之前已经设置了预提交挂钩,但这是我知识的限制。

I would like to add a post commit hook so that if a user commits changes to a particular file, I will be notified by email.

Has anyone seen an example of this, or is it possible?

I have set up a pre commit hook before, but that's limit of my knowledge.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三五鸿雁 2024-12-12 14:46:44

我在 github 上有一个 post-commit hook 正是这样做的,并且它允许用户(而不是管理员说出他们正在监视哪些文件的更改,以及这些更改应发送到哪些电子邮件地址。

您可以将其与我的 pre-commit-kitchen-sink hook 确保用户只能编辑他们自己的监视文件。钩子脚本使用 Perl,但它们不需要任何非标准模块,因此

每个用户都有自己的监视文件,语法非常简单:

mail = [email protected]
file =**/build.xml
match = [Mm]akefile

。邮件行是我想要通过电子邮件发送通知的位置。 file 是我正在观看的文件的全局表达式(锚定在表达式的前面和后面)。 code>match 行类似,并且使用未锚定的 Perl 正则表达式。

监视文件存储在 Subversion 存储库中您指定的目录中。这意味着用户可以设置自己的手表。您可以使用我的 pre-commit-kitchen-sink 挂钩来防止用户更改其他用户的监视文件:

[file You are only allowed to change their own watch files]
file =/watchfiles/**
permission = read-only
users = @ALL

[file You are only allowed to change their own watch files]
file = /watchfiles/<USER>.cfg
permission = read-write
users = @ALL

字符串被解释为用户的 ID。


例子

如果我想为多个文件设置提交后挂钩,我可以设置吗?像 file = ab/build.xml、bb/cs.txt、cc/. 等我只想通过电子邮件通知这些文件

您可以为每个模式添加一行:

 email = [email protected]
 file = **/ab/build.xml
 file = **/bb/cs.txt
 file = **/cc/*.*

请记住 file glob 模式锚定到存储库的根(使用 / 作为根),因此您需要指定完整路径,或使用 **/ 指定该文件的任何路径。

I have a post-commit hook on github that does exactly this, and it allows the users (instead of the administrator to say what files they're watching for changes, and what email addresses these changes should be sent to.

You can combine this with my pre-commit-kitchen-sink hook to make sure that users can only edit their own watch files. The hook scripts use Perl, but they don't require any non-standard modules, so they're pretty easy to use.

Each user gets their own watch file, the syntax is pretty easy:

mail = [email protected]
file =**/build.xml
match = [Mm]akefile

The mail line is where I want to email the notice. I can have multiple ones. The file is a glob expression (anchored at the front and back of the expression) of what files I'm watching. The match line is similar, and uses a Perl regular expression which is unanchored.

The watch files are stored in the Subversion repository in a directory you specify. This means that the users can set their own watches. You can use my pre-commit-kitchen-sink hook to prevent users from changing other users' watch files:

[file You are only allowed to change their own watch files]
file =/watchfiles/**
permission = read-only
users = @ALL

[file You are only allowed to change their own watch files]
file = /watchfiles/<USER>.cfg
permission = read-write
users = @ALL

The <USER> string is interpreted as the user's ID.


Example

If I want to set post commit hook to more than one files, so can I set? like file = ab/build.xml, bb/cs.txt, cc/. etc I want notification by email of these files only

You can put a line in for each pattern:

 email = [email protected]
 file = **/ab/build.xml
 file = **/bb/cs.txt
 file = **/cc/*.*

Remember that file glob pattern is anchored to the root of the repository (using / as the root) so you need to specify the full path, or use the **/ to specify any path to that file.

孤云独去闲 2024-12-12 14:46:44

在 subversion 发行版中有几个发送电子邮件的钩子脚本。查看目录

tools/hook-scripts

< a href="http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/" rel="nofollow">contrib/hook-scripts

In the subversion distribution are several hook scripts which send email. Look in the directories

tools/hook-scripts

contrib/hook-scripts

欢烬 2024-12-12 14:46:44

我设置了一个 PHP 脚本来在提交后执行。您可以将 PHP 脚本编辑得非常智能,并根据更新的文件执行某些操作。

/subversion/hooks/post-commit:/usr/share/subversion/hook-scripts/commit-email.php

 REPOS="$1"
 REV="$2"
 MESSAGE=$(svnlook propget --revprop -r $REV $REPOS svn:log)
 CHANGES=$(svnlook changed -r $REV $REPOS)
 php /usr/share/subversion/hook-scripts/commit-email.php "$REPOS" "$REV" "$MESSAGE" "$CHANGES"

 <?php
      //files updated will be in $_SERVER['argv'][4], you could expand it in to an a
      //array and search for what you need, and depending on what's found, send emails accordingly.
 ?>

i setup a PHP script to execute with post-commit. You could edit the PHP script to be pretty smart, and depending on which files were udpated do certain actions.

/subversion/hooks/post-commit:

 REPOS="$1"
 REV="$2"
 MESSAGE=$(svnlook propget --revprop -r $REV $REPOS svn:log)
 CHANGES=$(svnlook changed -r $REV $REPOS)
 php /usr/share/subversion/hook-scripts/commit-email.php "$REPOS" "$REV" "$MESSAGE" "$CHANGES"

/usr/share/subversion/hook-scripts/commit-email.php:

 <?php
      //files updated will be in $_SERVER['argv'][4], you could expand it in to an a
      //array and search for what you need, and depending on what's found, send emails accordingly.
 ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文