Commits

Anonymous committed 889ddaf

[svn r5322] pass a fake request and call TicketManipulators

Comments (0)

Files changed (2)

0.11/repository_hook_system/ticketchanger.py

 from trac.config import ListOption
 from trac.config import Option
 from trac.core import *
+from trac.perm import PermissionCache
 from trac.ticket import Ticket
 from trac.ticket.notification import TicketNotifyEmail
 from trac.ticket.web_ui import TicketModule
 from trac.util.datefmt import utc
 
-# TODO: look only for tickets that match 
-# `projectname:#|(ticket|issue|bug)`
-# according to configuration
-# (which also means moving the regex to the class TicketChanger)
-# move more/all of configuration into the .ini file and therefor editable
+from trac.web.api import Request # XXX needed for the TicketManipulators
+
+from StringIO import StringIO
 
 class TicketChanger(Component):
     """annotes and closes tickets on repository commit messages"""
                 for cmd in cmds:
                     cmd(ticket)
 
-                # determine sequence number... 
+                # determine comment sequence number
                 cnum = 0
                 tm = TicketModule(self.env)
                 for change in tm.grouped_changelog_entries(ticket, db):
                     if change['permanent']:
                         cnum += 1
-                
+
+                # validate the ticket
+                # TODO
+
+
+                # fake a request
+                # XXX cargo-culted environ from 
+                # http://trac.edgewall.org/browser/trunk/trac/web/tests/api.py
+                environ = { 'wsgi.url_scheme': 'http',
+                            'wsgi.input': StringIO(''),
+                            'SERVER_NAME': '0.0.0.0',
+                            'REQUEST_METHOD': 'POST',
+                            'SERVER_PORT': 80,
+                            'SCRIPT_NAME': '/' + self.env.project_name,
+                            'REMOTE_USER': chgset.author,
+                            'QUERY_STRING': ''
+                            }
+                req = Request(environ, None)
+                req.args['comment'] = msg
+                req.authname = chgset.author
+                for manipulator in tm.ticket_manipulators:
+                    manipulator.validate_ticket(req, ticket)
+                msg = req.args['comment']
+
                 ticket.save_changes(chgset.author, msg, now, db, cnum+1)
                 db.commit()
                 
                 tn.notify(ticket, newticket=0, modtime=now)
 
             except Exception, e:
-                # import traceback
-                # traceback.print_exc(file=sys.stderr)
                 print>>sys.stderr, 'Unexpected error while processing ticket ' \
-                                   'ID %s: %s' % (tkt_id, e)
+                                   'ID %s: %s' % (tkt_id, repr(e))
             
 
     def _cmdClose(self, ticket):
 from setuptools import find_packages, setup
 
-version='0.1'
+version='0.1.1'
 
 setup(name='RepositoryHookSystem',
       version=version,