How to send emails automatically for each commit

Disclaimer

This describe the solution I am using in my setup. It's not necessarily the best. I suggest you have a look at axp, in particular, the axp triggers command.

Simulating server-side hooks

GNU Arch has the particularity of using a simple file server as its server. It is therefore not possible to run a hook on the server automatically for each action performed. However, actions like sending a mail for each commit can hardly be performed reliably in a client-side hook: It would require that all the users having write access to the archive have set up the hook correctly. This is unreasonable in the case of centralized development, and hard to guarantee even for a single commiter archive, since the user may have different machine, use different account, ...

My solution is to use arch-trigger. Called from a cron job and/or in a commit hook, it will search for new revisions in the archive, and trigger an action for each new revision found. The documentation is at the end of the script, or available with perldoc arch-trigger.

Sending email for a given revision

Here's a small shell script that will baz cat-archive-log the log for a revision, and send it by email to the address provided as argument: rev2mail.sh.

My configuration

My ~/.arch-trigger/triggers contains this for example:

thelove@canonical.com/bazaar--devo--1.5        mail ${HOME}/bin/rev2mail.sh $ARCH_ARCHIVE/$ARCH_REVISION "[commit][bazaar]" Matthieu.Moy-inp.fr
Matthieu.Moy-inp.fr--public/xtla--devo--1.2   mail ${HOME}/bin/rev2mail.sh $ARCH_ARCHIVE/$ARCH_REVISION "[commit][xtla 1.2]" xtla-el-dev@gna.org    
  

The first one tells me whenever a new commit is done on bazaar 1.5, the second one sends emails to the Xtla development mailing list (like this one).

My ~/.arch-params/hook contains this:

case "${ARCH_ACTION}" in
    commit | import)
        batch << EOF 
echo arch ${ARCH_ACTION} "${ARCH_ARCHIVE}/${ARCH_REVISION}"
echo in ${ARCH_TREE_ROOT}
echo

set -x

source $HOME/.profile
arch-trigger
baz archive-mirror -a $ARCH_ARCHIVE
EOF
        ;;
  

This way, I run arch-trigger each time I commit, but in a background and low-priority process (because of the use of batch). I also have it in a cron job: this way, I receive emails also for commits I performed from another machine, and for commit performed by other users.

Matthieu MOY
Retour à la page d'accueil
Last updated: October 10, 2004.