Author: julianfoad Date: Mon Nov 30 17:30:17 2009 New Revision: 885511 URL: http://svn.apache.org/viewvc?rev=885511&view=rev Log: Extend "mailer.py" with an option "search_logmsg=REGEXP" to allow filtering based on matching expressions in the log message such as bug id's.
Patch by: Justin Vallon <justin.vallon{_AT_}deshaw.com> * tools/hook-scripts/mailer/mailer.conf.example Add documentation and an example of the new configuration options. * tools/hook-scripts/mailer/mailer.py (Commit): Pass the log message to the which_groups() call. (PropChange, Lock): Pass no log message to the which_groups() call. (Config): Parse the new option and extend the which_groups() function to include groups specified through matching the log message. * tools/hook-scripts/mailer/tests/mailer.conf (bugtracker): New section with the new configuration options. * tools/hook-scripts/mailer/tests/mailer-init.sh Put some example bug id's into some of the commit messages. * tools/hook-scripts/mailer/tests/mailer-t1.output Adjust for the additions and changes to the expected output. Modified: subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example subversion/trunk/tools/hook-scripts/mailer/mailer.py subversion/trunk/tools/hook-scripts/mailer/tests/mailer-init.sh subversion/trunk/tools/hook-scripts/mailer/tests/mailer-t1.output subversion/trunk/tools/hook-scripts/mailer/tests/mailer.conf Modified: subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example?rev=885511&r1=885510&r2=885511&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example (original) +++ subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example Mon Nov 30 17:30:17 2009 @@ -35,15 +35,16 @@ # Any sections other than [general], [defaults], [maps] and sections # referred to within [maps] are considered to be user-defined groups # which override values in the [defaults] section. -# These groups are selected using the following two options: +# These groups are selected using the following three options: # # for_repos # for_paths +# search_logmsg # -# Both options specify a regular expression. The former is matched against -# the absolute path to the repository the mailer is operating against. The -# second is matched against *every* path (files and dirs) that was modified -# during the commit. +# Each option specifies a regular expression. for_repos is matched +# against the absolute path to the repository the mailer is operating +# against. for_paths is matched against *every* path (files and +# dirs) that was modified during the commit. # # 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 @@ -62,6 +63,14 @@ # none of the paths, even though its for_paths would have selected some of # the paths in the commit. # +# search_logmsg specifies a regular expression to match against the +# log message. If the regular expression does not match the log +# message, the group is not matched; if the regular expression matches +# once, the group is used. If there are multiple matches, each +# successful match generates another group-match (this is useful if +# "named groups" are used). If search_logmsg is not used, no log +# message filtering is performed. +# # Groups are matched in no particular order. Do not depend upon their # order within this configuration file. The values from [defaults] will # be used if no group is matched or an option in a group does not override @@ -111,6 +120,20 @@ # If none of the groups match, but a for_paths is present in [defaults], # then its extracted names will be available. # +# Further suppose you want to match bug-ids in log messages: +# +# search_logmsg = (?P<bugid>(ProjA|ProjB)#\d) +# +# The bugids would be of the form ProjA#123 and ProjB#456. In this +# case, each time the regular expression matches, another match group +# will be generated. Thus, if you use: +# +# commit_subject_prefix = %(bugid)s: +# +# Then, a log message such as "Fixes ProjA#123 and ProjB#234" would +# match both bug-ids, and two emails would be generated - one with +# subject "ProjA#123: <...>" and "ProjB#234: <...>". +# # Note that each unique set of names for substitution will generate an # email. In the above example, if a commit modified files in all three # client subdirectories, then an email will be sent to all three commits@ @@ -329,3 +352,10 @@ # for_repos = /home/(?P<who>[^/]*)/repos # to_addr = %(who)s...@example.com # +# [issuetracker] +# search_logmsg = (?P<bugid>(?P<project>projecta|projectb|projectc)#\d+) +# # (or, use a mapping if the bug-id to email address is not this trivial) +# to_addr = %(project)s-trac...@example.com +# commit_subject_prefix = %(bugid)s: +# propchange_subject_prefix = %(bugid)s: + Modified: subversion/trunk/tools/hook-scripts/mailer/mailer.py URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/mailer.py?rev=885511&r1=885510&r2=885511&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/mailer.py (original) +++ subversion/trunk/tools/hook-scripts/mailer/mailer.py Mon Nov 30 17:30:17 2009 @@ -348,10 +348,12 @@ self.changelist = sorted(editor.get_changes().items()) + log = repos.get_rev_prop(svn.core.SVN_PROP_REVISION_LOG) or '' + # collect the set of groups and the unique sets of params for the options self.groups = { } for path, change in self.changelist: - for (group, params) in self.cfg.which_groups(path): + for (group, params) in self.cfg.which_groups(path, log): # turn the params into a hashable object and stash it away param_list = sorted(params.items()) # collect the set of paths belonging to this group @@ -422,7 +424,7 @@ # collect the set of groups and the unique sets of params for the options self.groups = { } - for (group, params) in self.cfg.which_groups(''): + for (group, params) in self.cfg.which_groups('', None): # turn the params into a hashable object and stash it away param_list = sorted(params.items()) self.groups[group, tuple(param_list)] = params @@ -512,7 +514,7 @@ # collect the set of groups and the unique sets of params for the options self.groups = { } for path in self.dirlist: - for (group, params) in self.cfg.which_groups(path): + for (group, params) in self.cfg.which_groups(path, None): # turn the params into a hashable object and stash it away param_list = sorted(params.items()) # collect the set of paths belonging to this group @@ -1263,32 +1265,56 @@ else: exclude_paths_re = None - self._group_re.append((group, re.compile(for_paths), - exclude_paths_re, params)) + # check search_logmsg re + search_logmsg = getattr(sub, 'search_logmsg', None) + if search_logmsg is not None: + search_logmsg_re = re.compile(search_logmsg) + else: + search_logmsg_re = None + + self._group_re.append((group, + re.compile(for_paths), + exclude_paths_re, + params, + search_logmsg_re)) # after all the groups are done, add in the default group try: self._group_re.append((None, re.compile(self.defaults.for_paths), None, - self._default_params)) + self._default_params, + None)) except AttributeError: # there is no self.defaults.for_paths pass - def which_groups(self, path): + def which_groups(self, path, logmsg): "Return the path's associated groups." groups = [] - for group, pattern, exclude_pattern, repos_params in self._group_re: + for group, pattern, exclude_pattern, repos_params, search_logmsg_re in self._group_re: match = pattern.match(path) if match: if exclude_pattern and exclude_pattern.match(path): continue params = repos_params.copy() params.update(match.groupdict()) - groups.append((group, params)) + + if search_logmsg_re is None: + groups.append((group, params)) + else: + if logmsg is None: + logmsg = '' + + for match in search_logmsg_re.finditer(logmsg): + # Add captured variables to (a copy of) params + msg_params = params.copy() + msg_params.update(match.groupdict()) + groups.append((group, msg_params)) + if not groups: groups.append((None, self._default_params)) + return groups Modified: subversion/trunk/tools/hook-scripts/mailer/tests/mailer-init.sh URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/tests/mailer-init.sh?rev=885511&r1=885510&r2=885511&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/tests/mailer-init.sh (original) +++ subversion/trunk/tools/hook-scripts/mailer/tests/mailer-init.sh Mon Nov 30 17:30:17 2009 @@ -56,7 +56,7 @@ svn ps prop1 propval1 file2 svn ps prop3 propval3 dir1 echo change C2 >> dir2/file5 -svn commit -m "two file changes" +svn commit -m "two file changes. Fixes Blah#123" # copy a file and a dir and change property svn cp file1 dir2/file7 @@ -84,7 +84,7 @@ svn add file9 svn mkdir dir4 echo change C4 >> dir1/file3 -svn commit -m "mixed addition and change" +svn commit -m "mixed addition and change. Fixes Blaz#456 Blah#987" # add a file, add a dir, delete a file, delete a dir, and make a change echo file10 > dir1/file10 Modified: subversion/trunk/tools/hook-scripts/mailer/tests/mailer-t1.output URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/tests/mailer-t1.output?rev=885511&r1=885510&r2=885511&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/tests/mailer-t1.output (original) +++ subversion/trunk/tools/hook-scripts/mailer/tests/mailer-t1.output Mon Nov 30 17:30:17 2009 @@ -152,24 +152,29 @@ +++ file2 Sun Sep 9 01:46:40 2001 (r1) @@ -0,0 +1 @@ +file2 -Group: file plus other areas -Subject: r2 - dir1 dir2 +Group: bugtracker +Subject: Fix for Blah#123: r2 - dir1 dir2 Author: mailer test Date: Sun Sep 9 04:33:20 2001 New Revision: 2 Log: -two file changes +two file changes. Fixes Blah#123 Modified: + dir1/ (props changed) + dir2/file5 file1 (props changed) file2 (contents, props changed) -Changes in other areas also in this revision: -Modified: - dir1/ (props changed) - dir2/file5 +Modified: dir2/file5 +============================================================================== +--- dir2/file5 Sun Sep 9 01:46:40 2001 (r1) ++++ dir2/file5 Sun Sep 9 04:33:20 2001 (r2) +@@ -1 +1,2 @@ + file5 ++change C2 Modified: file2 ============================================================================== @@ -178,16 +183,6 @@ @@ -1 +1,2 @@ file2 +change C1 - -Diffs of changes in other areas also in this revision: - -Modified: dir2/file5 -============================================================================== ---- dir2/file5 Sun Sep 9 01:46:40 2001 (r1) -+++ dir2/file5 Sun Sep 9 04:33:20 2001 (r2) -@@ -1 +1,2 @@ - file5 -+change C2 Group: All Subject: r2 - dir1 dir2 @@ -196,7 +191,7 @@ New Revision: 2 Log: -two file changes +two file changes. Fixes Blah#123 Modified: dir1/ (props changed) @@ -219,6 +214,42 @@ @@ -1 +1,2 @@ file2 +change C1 +Group: file plus other areas +Subject: r2 - dir1 dir2 + +Author: mailer test +Date: Sun Sep 9 04:33:20 2001 +New Revision: 2 + +Log: +two file changes. Fixes Blah#123 + +Modified: + file1 (props changed) + file2 (contents, props changed) + +Changes in other areas also in this revision: +Modified: + dir1/ (props changed) + dir2/file5 + +Modified: file2 +============================================================================== +--- file2 Sun Sep 9 01:46:40 2001 (r1) ++++ file2 Sun Sep 9 04:33:20 2001 (r2) +@@ -1 +1,2 @@ + file2 ++change C1 + +Diffs of changes in other areas also in this revision: + +Modified: dir2/file5 +============================================================================== +--- dir2/file5 Sun Sep 9 01:46:40 2001 (r1) ++++ dir2/file5 Sun Sep 9 04:33:20 2001 (r2) +@@ -1 +1,2 @@ + file5 ++change C2 Group: file Subject: r2 - dir1 dir2 @@ -227,7 +258,7 @@ New Revision: 2 Log: -two file changes +two file changes. Fixes Blah#123 Modified: file1 (props changed) @@ -326,6 +357,25 @@ Modified: file2 (props changed) +Group: file +Subject: r6 - dir1 dir4 + +Author: mailer test +Date: Sun Sep 9 15:40:00 2001 +New Revision: 6 + +Log: +mixed addition and change. Fixes Blaz#456 Blah#987 + +Added: + file9 + +Added: file9 +============================================================================== +--- /dev/null 00:00:00 1970 (empty, because file is newly added) ++++ file9 Sun Sep 9 15:40:00 2001 (r6) +@@ -0,0 +1 @@ ++file9 Group: file plus other areas Subject: r6 - dir1 dir4 @@ -334,7 +384,7 @@ New Revision: 6 Log: -mixed addition and change +mixed addition and change. Fixes Blaz#456 Blah#987 Added: file9 @@ -369,7 +419,7 @@ New Revision: 6 Log: -mixed addition and change +mixed addition and change. Fixes Blaz#456 Blah#987 Added: dir4/ @@ -391,18 +441,59 @@ +++ file9 Sun Sep 9 15:40:00 2001 (r6) @@ -0,0 +1 @@ +file9 -Group: file -Subject: r6 - dir1 dir4 +Group: bugtracker +Subject: Fix for Blah#987: r6 - dir1 dir4 Author: mailer test Date: Sun Sep 9 15:40:00 2001 New Revision: 6 Log: -mixed addition and change +mixed addition and change. Fixes Blaz#456 Blah#987 Added: + dir4/ file9 +Modified: + dir1/file3 + +Modified: dir1/file3 +============================================================================== +--- dir1/file3 Sun Sep 9 12:53:20 2001 (r5) ++++ dir1/file3 Sun Sep 9 15:40:00 2001 (r6) +@@ -1 +1,2 @@ + file3 ++change C4 + +Added: file9 +============================================================================== +--- /dev/null 00:00:00 1970 (empty, because file is newly added) ++++ file9 Sun Sep 9 15:40:00 2001 (r6) +@@ -0,0 +1 @@ ++file9 +Group: bugtracker +Subject: Fix for Blaz#456: r6 - dir1 dir4 + +Author: mailer test +Date: Sun Sep 9 15:40:00 2001 +New Revision: 6 + +Log: +mixed addition and change. Fixes Blaz#456 Blah#987 + +Added: + dir4/ + file9 +Modified: + dir1/file3 + +Modified: dir1/file3 +============================================================================== +--- dir1/file3 Sun Sep 9 12:53:20 2001 (r5) ++++ dir1/file3 Sun Sep 9 15:40:00 2001 (r6) +@@ -1 +1,2 @@ + file3 ++change C4 Added: file9 ============================================================================== Modified: subversion/trunk/tools/hook-scripts/mailer/tests/mailer.conf URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/tests/mailer.conf?rev=885511&r1=885510&r2=885511&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/tests/mailer.conf (original) +++ subversion/trunk/tools/hook-scripts/mailer/tests/mailer.conf Mon Nov 30 17:30:17 2009 @@ -338,3 +338,9 @@ [file] for_paths = file.* show_nonmatching_paths = no + +[bugtracker] +search_logmsg = (?P<bugid>(Blaz|Blah)#\d+) +to_addr = issue-trac...@example.com +commit_subject_prefix = Fix for %(bugid)s: +