ubuntu10.10 Send SVN change notification messages via hooks and mailer.py

Source: Internet
Author: User
Tags svn terminates

Nonsense: Although git is ferocious now, but SVN is still used a lot of time to toss their own SVN process record down.

SVN provides a handy hooks feature (which is also mentioned in my toss-and-go FTP article), which can be used to set related actions for repository operations. For a detailed introduction to the official SVN documentation, I'm just here to introduce post-commit to send notification messages. The Directory of Subversion repository contains a directory of Conf, DAV, DB, hooks, locks, etc. Where hooks is used to store hooks (and nonsense). There are currently nine kinds of hooks:

START-COMMIT: Notification of commencement of submission. Executes before a transaction is initiated (typically to determine whether a user has submit permissions). If the Start-commit hook program returns a value other than 0, the action (such as commit) will stop before the transaction is created, and any output from STDERR will be returned to the client. Pre-commit: Remind before the commit is complete. Post-commit hooks are run before a transaction creates a new version, which is usually used to protect a submission that is not allowed because the content or location (for example, you require all submissions to a particular branch must include a bug-tracking ticket number, or a request that the log information is not empty). If the Pre-commit hook returns a value other than 0, the commit terminates, the commit transaction is deleted, and all the stderr outputs are returned to the client. POST-COMMIT: Notification of a successful submission. Post-commit hooks are executed after the transaction is completed and a new version is created. Most people use this hook to send a descriptive email about a submission, or to remind other tools (such as problem tracking) that a commit action occurred. Some configurations also use this hook to trigger the backup process for the version library. If the Post-commit hook returns a value other than 0, the commit does not terminate because it is completed. All stderr output is then returned to the client, making it easier to diagnose the hook failure. Pre-revprop-change: Notification of revision property modification. The Pre-revprop-change hook is executed outside the normal commit range before modifying the version attribute modification. Unlike other hooks, this hook defaults to rejecting all attribute modifications, the hook must actually exist and returns a value of 0 to modify the property. If the Pre-revprop-change hook does not exist, cannot be executed, or returns a value other than 0, the property is not modified and all stderr output is returned to the client. Post-revprop-change: Revision property modifies a successful notification. The Post-revprop-change hook will be executed immediately after modifying the version attribute modification, outside of the commit scope. It can be paired from the pre-revprop-change know that if the Pre-revprop-change hook is not implemented, it will not execute. It is typically used to send notification of a message after a property has been modified. If the Post-revprop-change hook returns a value other than 0, the modification action does not terminate because it is completed. However, any output to stderr content is returned to the client, making it easier to diagnose the hook failure. Pre-lock: Notification of PATH lock attempt. The Pre-lock Hook executes every time someone tries to lock a file. To prevent the endFull lock, or to create a complex strategy that controls which users can lock which paths. If the hook finds a lock already in existence, it can also decide whether to allow the user to "steal" the lock. If the Pre-lock hook returns a value other than 0, the lock action terminates and any output to the stderr is returned to the client. Post-lock: Notification that the path was successfully locked. Post-lock is executed after the path is locked. Usually used to send a lock event mail notification. If the Post-lock hook returns a value other than 0, the lock action does not terminate because it is completed. However, any output to stderr content is returned to the client, making it easier to diagnose the hook failure. Pre-unlock: A notification that the path unlocks the attempt. Pre-unlock hook occurs when someone attempts to delete a hook on a file. A policy that can be used to create which users can unlock which files. It is important to develop a unlocking strategy. If User A locks a file, allow user B to open the lock. If this lock has been around for a week. This kind of thing can be determined and enforced by the hook. If Pre-unlock returns a value other than 0, the unlock operation terminates and any output to stderr is returned to the client. Post-unlock: Notification that the path was successfully unlocked. Post-unlock is executed after one or more paths have been unlocked. Typically used to send unlock event notification messages. If Post-unlock returns a value other than 0, the unlock process does not terminate because it is completed. However, any output to stderr content is returned to the client, making it easier to diagnose the hook failure.

The official documents of the above hooks subversion are described in more detail. What I need is change success notice, of course is choose Post-commit, here can choose according to have two kinds, commit-email.pl and mailer.py, because commit-email.pl can't handle NO-ASCII log message correctly , at the same time mailer.py function is more powerful, the most important thing is I am more familiar with Python easy to debug. The Ubuntu I use installs the Subversion-tools after the subversion, and this bag has a/usr/share/subversion/hook-scripts/mailer/mailer.py Used to compare two versions of the library and send mail to the specified mailing list person.

$ cd $repo/hooks
$ cp post-commit.tmpl post-commit
$ chmod a+x post-commit
$ cp/usr/lib/subversion/ Hook-scripts/mailer/mailer.conf "$REPOS"/conf/mailer.conf

The template provided here is a shell script, where as long as an executable file can be (can be python,perl or even a C executable) add the following in Post-commit:

#!/bin/sh
repos= "$"
rev= "$"
/usr/lib/subversion/hook-scripts/mailer/mailer.py commit $REPOS $REV "$ REPOS "/conf/mailer.conf
if [$-ne 0]; then
    echo" failure to mailer.py commit $REPOS $REV ">>/home/trac/s Vnrepository/gala/hooks/test.log
fi

The following if statement is used when I debug. Now the step is to modify the mailer.conf, in fact, the configuration file in the face of the configuration is very good, so look at the annotation can be configured, it is the official document here: http://opensource.perlig.de/svnmailer/doc-1.0/# General-sendmail-command time can be carefully scanned. The following are my main problems: mailer.conf inside the way to provide e-mail, there are two total, a sendmail, one is SMTP. If you choose the SendMail way, you need to change the mailer.py

cmd = Self.cmd + ['-t ', self.from_addr] + Self.to_addrs "" Modified to "" "
cmd = self.cmd + [' f ', self.from_addr] + SE Lf.to_addrs
The exact reason why it seems that I have forgotten. But this is easy to be rejected by the server as spam, so that you are under your user Debian is generally/var/mail/$USERNAME will receive rejected mail. General prompts SMTP protocol error. Here are some of the meanings of the SMTP return error codes: http://www.5dmail.net/bbs/thread-184743-1-1.html You can follow this debug. The tips are as follows:
/post-commit/path/to/the/svn/repository 689
689 represents a change in the source code.

If you choose SMTP to send mail, generally there is no problem, the main is server,username,passwd set well there is no problem. The way to debug is still the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.