Commits

Anonymous committed 2e1b2bb

[svn r4425] support multiple types of hook; doco; import NoSuchChangeset where needed

  • Participants
  • Parent commits ba1378a

Comments (0)

Files changed (5)

File 0.11/repository_hook_system/README

+To make the sample TicketChanger plugin work, you need to add this to
+your trac.ini:
+
+[repository-hooks]
+post-commit = TicketChanger
+
+You also need to add a post-commit hook to SVN:
+#!/bin/sh
+
+
+REPOS="$1"
+REV="$2"
+
+
+full_path_to_python full_path_to_repository_hook_system/listener.py --hook=post-commit -p full_path_to_repository $REV

File 0.11/repository_hook_system/interface.py

     def is_available(repository, hookname):
         """can this subscriber be invoked on this hook?"""        
 
-    def invoke(changeset):
-        """what to do on a commit"""
+    def after_commit(changeset):
+        """what to do after a commit"""
+
+    def before_commit(changeset):
+        """what to do before a commit"""
+
+    def other_repository_action(*args):
+        """what to do in the case of some other repositiory action"""
 
 ### interfaces for the hook system
 
 class IRepositoryChangeListener(Interface):
-    """listeners to changes from repository hooks"""
+    """This is a particular type of repository (SVN, Git, etc)'s change
+    listener."""
 
     def type():
         """list of types of repository to listen for changes"""

File 0.11/repository_hook_system/listener.py

 
         # find the active listeners
         listeners = ExtensionPoint(IRepositoryChangeListener).extensions(env)
-        
+
         # find the listener for the given repository type and invoke the hook
         for listener in listeners:
             if env.config.get('trac', 'repository_type') in listener.type():
-                changeset = listener.changeset(repo, *args)
+                changeset = listener.changeset(repo, hook, *args)
                 subscribers = listener.subscribers(hook)
                 for subscriber in subscribers:
-                    subscriber.invoke(changeset)
+                    funcname = hook.replace("-","_")
+                    func = getattr(subscriber, funcname, None)
+                    if func:
+                        func(changeset)
         
 def filename():
     return os.path.abspath(__file__.rstrip('c'))

File 0.11/repository_hook_system/svnhooksystem.py

 from trac.config import ListOption
 from trac.core import *
 from trac.util.text import CRLF
+from trac.versioncontrol.api import NoSuchChangeset
 from utils import iswritable
 
 class SVNHookSystem(FileSystemHooks):
                  in getattr(self, hookname, []) 
                  and subscriber.is_available(self.type(), hookname) ]
 
-    def changeset(self, repo, revision):
+    def changeset(self, repo, hook, revision):
         """ 
         return the changeset given the repository object and revision number
         """
         try:
-            chgset = repo.get_changeset(revision)
+            if hook == 'pre-commit':
+                chgset = {'transaction' : revision} #Trac has no way to get a transaction out of svn
+            else:
+                chgset = repo.get_changeset(revision)
         except NoSuchChangeset:
             # XXX should probably throw an exception (same one?)
             return # out of scope changesets are not cached

File 0.11/repository_hook_system/ticketchanger.py

     def is_available(self, repository, hookname):
         return True
 
-    def invoke(self, chgset):
+    def post_commit(self, chgset):
 
         # regular expressions        
         ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)'