Modify

Opened 15 years ago

Last modified 9 years ago

#7033 new enhancement

SVN Pre-Commit Hook to ensure Trac ID in Comment

Reported by: Olemis Lang Owned by: Olemis Lang
Priority: high Component: RepositoryHookSystemPlugin
Severity: normal Keywords: vcs multi-projects svn
Cc: Trac Release: 0.11

Description

Based on a support request posted by Marjory L. Mackes to trac-users ML

Implement the pre-commit hook /apps/trac/var/svn/hooks/pre-commit.pl , which requires the user to enter the Trac ID number to check in the source to associate the change set with the ticket.

Besides , when multiple environments share a single repository, check whether filters are applied in order to execute hook subscribers only if the target changeset touches the project folder .

Attachments (0)

Change History (2)

comment:1 Changed 10 years ago by diego

Ticket status via trac admin They say that they don't want to implement it -> trac:#561 I do not like the sql solution, that is why added the following hack into trac-admin:

../trac/ticket/admin.py

class TicketAdmin(Component):
    ...    
    def get_admin_commands(self):
        ...
        yield ('ticket status', '<number> [...]',
               'Status of a ticket',
               None, self._do_ticket_status)
    def _do_ticket_status(self, number, *comment):
        try:
            number = int(number)
        except ValueError:
            raise AdminCommandError(_('<number> must be a number'))
        ticket = model.Ticket(self.env, number)
        printout(_('%(t)s',
                   t=ticket.values.get('status')))

Now you can request the status of a ticket via trac-admin %env% ticket status %ticketNo%

pre-commit Here my pre-commit script for svn. I have to following folder structure:
../trac/project1
../trac/project2
../svn/project1
../svn/project2
That is why i am doing tracEnv = repos.replace("svn", "trac") to find the trac environment path. (Can be optimized and enhanced for multiple environments which share a single repository). To commit to a ticket i use the following comment layout #7033 - SVN Pre-Commit Hook to ensure Trac ID in Comment

#!/usr/bin/env python

import os, sys

repos = sys.argv[1]
txn = sys.argv[2]

svnlook = "/usr/bin/svnlook log -t %s %s" % (txn, repos)
text = os.popen(svnlook).read()
text = text.split(" ")[0]

ticketNo = text.replace("#","")
ticketNo = ticketNo.replace("\n","")

if (ticketNo.isdigit() == False):
    sys.stderr.write("This %s is not a number. Please insert a valid ticket number and description in the comment before you commit." %ticketNo)
    sys.exit(1)

#trac environemnt
tracEnv = repos.replace("svn", "trac")

ticketStatusRequest = "trac-admin %s ticket status %s" % (tracEnv, ticketNo)
ticketStatus = os.popen(ticketStatusRequest).read()
ticketStatus = ticketStatus.replace("\n","")

if (ticketStatus == "new" or ticketStatus == "reopened"):
    sys.exit(0)
else:
    if (ticketStatus == ""):
        sys.stderr.write("Ticket %s does not exist." % ticketNo)
    else:
        sys.stderr.write("Ticket %s is closed. TicketStatus=%s" % (ticketNo, ticketStatus))
    sys.exit(1)
Last edited 10 years ago by Ryan J Ollos (previous) (diff)

comment:2 Changed 9 years ago by Cinc-th

Keywords: multi-projects added; multiproject removed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Olemis Lang.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.