tags:

views:

116

answers:

2

I am looking for a way to add a post-commit or pre-commit hook to my VCS that will allow me to both create and close a trac ticket in one go.

The use-case is for when a bug has been found, and corrected, but a single developer who wants to make sure the project manager can see the fix has been done, when it was done and what milestone the fix has been done in.

We have a default milestone in trac when creating a ticket, so reflecting that information would be good too.

A: 

Create a post-commit hook. Notice how the trac post-commit hooks work and copy this functionality to control this action (creation + closing ticket). The creation + closing are two separate http requests that can happen with wget, you can intercept the ticket creation form's post, look at how the existing trac integration works, or hack it some other way. Have fun. I wish this could be more specific but it really does depend on what you're trying to do.

cheater
since there's the problem of actually logging into trac, you can use one of two ways:1. manual and easy: log in with firefox and use the cookie with wget:http://hack2live.blogspot.com/2009/01/exporting-firefox-cookies-for-wget.html>Install the Export Cookies 1.0 firefox plugin >(https://addons.mozilla.org/en-US/firefox/addon/8154)>>and download with wget :>wget --load-cookies=./cookies.txt -i url.list2. automatic and more difficult:http://drupal.org/node/118759also shows a working example on how to do post with wget.
cheater
+1  A: 

I recommend extending TracTicketChangesetsPlugin to do this.

You would adjust the way it detects the command in the commit message (see http://trac-hacks.org/browser/tracticketchangesetsplugin/trunk/ticketchangesets/commit_updater.py?rev=8114#L154), as you would not have a ticket number to refer to yet.

See http://trac-hacks.org/browser/tracticketchangesetsplugin/trunk/ticketchangesets/commit_updater.py?rev=8114#L215 for where it actually does the parsing. You would have to return some new token to represent "new ticket."

The code that actually changes the tickets is at http://trac-hacks.org/browser/tracticketchangesetsplugin/trunk/ticketchangesets/commit_updater.py?rev=8114#L234 , so here would you create NEW ticket, then close it straight away. To create a new ticket, call Ticket(self.env) and then save it with Ticket.insert() (see http://trac.edgewall.org/browser/trunk/trac/ticket/model.py?rev=9692#L174 ).

If you do this, I recommend attaching your patch to a new ticket at Trac Hacks.

Nick
(Again, can't edit due to being new!)Note that this Trac plugin was "derived from" http://trac.edgewall.org/browser/trunk/tracopt/ticket/commit_updater.py?rev=9936 so if you didn't want to use the plugin you could start by editing that code instead. However, the plugin is very good and the extra features are nice to have (such as listing commits in the ticket in a dedicated area.)Either way, you need to add a post-commmit-hook to your subversion repository which runs trac-admin's changeset command.(The instructions for TracTicketChangesetsPlugin go through that in some detail.)
Nick