SVN post commit hook to email user when a particular file is changed
Asked Answered
B

3

5

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.

Borges answered 19/9, 2011 at 16:0 Comment(1)
This is a good example of a post-commit hook email notifier (mikewest.org/2006/06/subversion-post-commit-hooks-101). You'll still have to add the bit for only notifying for a specific file...Nephew
S
6

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.

Sitton answered 19/9, 2011 at 18:35 Comment(5)
@Jharwood I've moved them into Github since this port: My pre-commit hook script. My post-commit watcher scriptSitton
@DavidW. 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.Babby
You can add a line for each file pattern you want. See example in my answer.Sitton
@DavidW. Thanks for the solution, but its feasible..?? I mean when i have hundreds of files in different folders, then how can i do ths..?? Is it possible that keeping a list of files in a text file and reading file names from that text file...?Babby
The watch file can be hundreds of lines, so there's no feasibility issue there. I could modify the hook to allow multiple files on one line, but that adds programming complexity with little benefit. The hook won't run faster, nor is it necessarily easier for the user. Is there something special about these files? Maybe I can add a feature to help you select the files you want. Do they have a special property on them or some other issue I can use for a selection criteria?Sitton
T
1

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

tools/hook-scripts

contrib/hook-scripts

Tithe answered 19/9, 2011 at 17:1 Comment(0)
P
0

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.
 ?>
Purview answered 13/4, 2012 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.