Search code examples
trac

How can I create trac tickets from an svn commit?


I'm looking for a way to create (not update) a trac ticket in response to a commit message like "Hack code to not kill your dog (TODO: fix this properly to avoid chasing kittens instead)".

I want the trac system to react on the "TODO" keyword and create a ticket with the content of the commit message, the owner set to the committer and the opening commit already referenced.

While searching on SO I found Open and close trac tickets with a single commit which basically says how I could roll my own solution. Which I'd do if there isn't a pre-made one available. So - is there?


Solution

  • I would suggest looking at the official Trac package for python: http://pypi.python.org/pypi/Trac/0.11.4 and docs http://www.edgewall.org/docs/tags-trac-0.11.7/epydoc/trac-module.html

    This is what we use to create tickets in Trac from a python script and I think it's fairly simple to use. You could run this python script as a post commit hook for your VCS.

    You can start up a trac environment using your project settings and then new up tickets and save them. There's probably a little more to it for you, but this should give you a good idea:

    from trac.env import Environment
    from trac.ticket import Ticket
    
    env = Environment(projectSettings, create=0)
    tkt = Ticket(env)
    tkt['summary'] = 'first line of commit message'
    tkt['description'] = 'full commit message'
    tkt.save_changes(commitAuthor, '')