SVN hook mailer.py configuration

≯℡__Kan透↙ 提交于 2019-12-10 16:19:15

问题


I try to set up a post-commit hook on a subversion 1.6.12 server to send a notification mail on commit.

I am already using the script mailer.py (delivered by subversion team in the utils folder) with basic configuration (just send an email after each commit) and it works well.

But now, I want to send a mail only when there is a commit in the /tags/ folder.

This is my standard mailer.conf (that works well) :

[general]
smtp_hostname = xxx.xxx.xxx.xxx

[defaults]
from_addr = myemail@domain.tld
to_addr = myemail@domain.tld

And this is what I tried to configure for a mail on /tags/ only :

[general]
smtp_hostname = xxx.xxx.xxx.xxx

[defaults]
from_addr = myemail@domain.tld
to_addr = myemail@domain.tld
for_paths = .*/tags/.*

But it looks like I am misunderstand the configuration because it does not work : I receive mail on all commits (tags or not)

Any idea? Thank you.


回答1:


There isn't really a good way to do this. mailer.py is designed so that any commit that isn't matched to another group goes to the defaults group.

The documentation in mailer.conf.example hints at this but doesn't really explain it very well:

The options specified in the [defaults] section are always selected. The presence of a non-matching for_repos has no relevance. Note that you may still use a for_repos value to extract useful information (more on this later). Any user-defined groups without a for_repos, or which contains a matching for_repos, will be selected for potential use.

The subset of user-defined groups identified by the repository are further refined based on the for_paths option. A group is selected if at least one path(*) in the commit matches the for_paths regular expression. Note that the paths are relative to the root of the repository and do not have a leading slash.

What is says for for_repos also applies to for_paths with respect to the defaults group. I.E. that that for_paths is only useful for variable extraction.

One option without making any code changes would be to set your to_addr in your [defaults] to an address like devnull@example.com which you just throw away. Then set a different group up with a different to_addr that will actually be delivered someplace.

If you're willing to modify your mailer.py a tad you can avoid this by commenting out the following two lines in the which_groups function of the Config class:

if not groups:
  groups.append((None, self._default_params))

As a Subversion developer long term I think we should add an option to mailer.py to request that no mail be generated by the defaults section. Additionally, we should fix the documentation to be clearer about this behavior.




回答2:


Finally, I solved my problem using another notification script available in the utils folder (even if it is deprecated) : commit-email.pl

Using it like this in my post-commit hook work as expected :

REPOS="$1"
REV="$2"

LC_ALL=C /usr/share/subversion/hook-scripts/commit-email.pl "$REPOS" $REV -m "tags/.*" -s "[TAGS]" --from noreply@domain.tld myemail@domain.tld

But if someone have the correct configuration for doing the same thing with mailer.py, I am still interested!




回答3:


Instead of:

for_paths = .*/tags/.*

Try this:

for_paths = ^tags($|.*)

This is assuming the tags dir is at the root of your repository.

If you have tags under a project it would be like

for_paths = ^<project name>/tags($|.*)


来源:https://stackoverflow.com/questions/11315754/svn-hook-mailer-py-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!