Edgewall Software

Version 4 (modified by Peter Suter, 7 years ago) ( diff )

#12898 ICachedRepositoryChangeListener

Extension Point : IRepositoryChangeListener

InterfaceIRepositoryChangeListenerSince0.12
Moduletrac.versioncontrol.apiSourceapi.py

The IRepositoryChangeListener allows components to listen for and to react to changes in repositories.

Purpose

Trac can be connected to Version Control systems to e.g. browse files, visualize changesets or revision logs. Plugins can hook into the version control module to trigger their own actions when changesets are added or modified.

The main purpose for this interface is to allow plugins to react to commits and trigger appropriate actions elsewhere (e.g. sending notifications or triggering changes via commands in the commit log messages etc.)

For example the CommitTicketUpdater allows referencing or closing tickets by embedding the ticket number in a commit log message.

Usage

Implementing the interface follows the standard guidelines found in TracDev/ComponentArchitecture and of course TracDev/PluginDevelopment.

The method changeset_added is called once for each new changeset committed to the repository.

For repositories that allow revision property changes (SVN), the method changeset_modified is called once for each changeset modified.

Note that the methods will not be called if the TracRepositoryAdmin is not configured correctly to call trac-admin $ENV changeset added/modified from the source control hooks.

Examples

Similarly to the CommitTicketUpdater mentioned above, you might want to close a milestone from a commit log message, e.g. when committing a tag or merging a branch. The following minimal example IRepositoryChangeListener implementation could implement such a feature:

from datetime import datetime
import re
from trac.core import Component, implements
from trac.ticket.model import Milestone
from trac.util.datefmt import utc
from trac.versioncontrol.api import IRepositoryChangeListener

class CommitMilestoneCloser(Component):
    implements(IRepositoryChangeListener)

    def changeset_added(self, repos, changeset):
        ref = re.search('complete milestone ([^\s]+)', changeset.message)
        if ref:
            milestone = Milestone(self.env, ref.group(1))
            milestone.completed = datetime.now(utc)
            milestone.update()

    def changeset_modified(self, repos, changeset, old_changeset):
        pass

Available Implementations

Additional Information and References

API History

Note: See TracWiki for help on using the wiki.