Nicolas Payart
Nicolas Payart

Reputation: 1086

SVN hook mailer.py configuration

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 = [email protected]
to_addr = [email protected]

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

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

[defaults]
from_addr = [email protected]
to_addr = [email protected]
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.

Upvotes: 4

Views: 7075

Answers (3)

Jack
Jack

Reputation: 1

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($|.*)

Upvotes: 0

Ben Reser
Ben Reser

Reputation: 5765

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 [email protected] 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.

Upvotes: 4

Nicolas Payart
Nicolas Payart

Reputation: 1086

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 [email protected] [email protected]

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

Upvotes: 0

Related Questions