Modify

Opened 4 years ago

Last modified 10 days ago

#7033 new enhancement

SVN Pre-Commit Hook to ensure Trac ID in Comment

Reported by: olemis Owned by: olemis
Priority: high Component: RepositoryHookSystemPlugin
Severity: normal Keywords: vcs multiproject 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 (1)

comment:1 Changed 11 days 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 days ago by rjollos (previous) (diff)

Add Comment

Modify Ticket

Action
as new .
Author


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

 
Note: See TracTickets for help on using tickets.