Edgewall Software

Ticket #7300: reassignment.patch

File reassignment.patch, 4.2 KB (added by ian@…, 4 years ago)

Patch to support reassignment in trac-post-commit-hook

  • trac-post-commit-hook

    old new  
    22 
    33# trac-post-commit-hook 
    44# ---------------------------------------------------------------------------- 
    5 # Copyright (c) 2004 Stephen Hansen  
     5# Copyright (c) 2004 Stephen Hansen 
     6# Portions copyright (c) 2008 Digg, LLC. 
    67# 
    78# Permission is hereby granted, free of charge, to any person obtaining a copy 
    89# of this software and associated documentation files (the "Software"), to 
     
    3940# (all the other arguments are now deprecated and not needed anymore) 
    4041# 
    4142# It searches commit messages for text in the form of: 
    42 #   command #1 
    43 #   command #1, #2 
    44 #   command #1 & #2  
    45 #   command #1 and #2 
     43#   command #1 [to user] 
     44#   command #1, #2 [to user] 
     45#   command #1 & #2 [to user] 
     46#   command #1 and #2 [to user] 
    4647# 
    4748# Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.: 
    4849#   command ticket:1 
     
    6263#     commit message being added to it.  
    6364#   references, refs, addresses, re, see  
    6465#     The specified issue numbers are left in their current status, but  
    65 #     the contents of this commit message are added to their notes.  
     66#     the contents of this commit message are added to their notes. 
     67#   reassign, reassigns, assign, assigns 
     68#     Behaves the same as references, above, and reassigns the ticket to the 
     69#     specified user. Example: reassign #1 to otheruser 
     70#     The "to" is optional; this also works: reassign #1 otheruser 
    6671# 
    6772# A fairly complicated example of what you can do is with a commit message 
    6873# of: 
     
    111116 
    112117 
    113118ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)' 
     119ticket_suffix = '(?:(?: +to +)?(?P<owner>[a-z]+))?' 
    114120ticket_reference = ticket_prefix + '[0-9]+' 
    115121ticket_command =  (r'(?P<action>[A-Za-z]*).?' 
    116                    '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)' % 
    117                    (ticket_reference, ticket_reference)) 
     122                   '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)%s' % 
     123                   (ticket_reference, ticket_reference, ticket_suffix)) 
    118124 
    119125if options.envelope: 
    120126    ticket_command = r'\%s%s\%s' % (options.envelope[0], ticket_command, 
     
    134140                       're':         '_cmdRefs', 
    135141                       'references': '_cmdRefs', 
    136142                       'refs':       '_cmdRefs', 
    137                        'see':        '_cmdRefs'} 
     143                       'see':        '_cmdRefs', 
     144                       'reassign':   '_cmdAssign', 
     145                       'reassigns':  '_cmdAssign', 
     146                       'assign':     '_cmdAssign', 
     147                       'assigns':    '_cmdAssign'} 
    138148 
    139149    def __init__(self, project=options.project, author=options.user, 
    140150                 rev=options.rev, url=options.url): 
     
    156166        cmd_groups = command_re.findall(self.msg) 
    157167 
    158168        tickets = {} 
    159         for cmd, tkts in cmd_groups: 
     169        owners = {} 
     170        for cmd, tkts, owner in cmd_groups: 
    160171            funcname = CommitHook._supported_cmds.get(cmd.lower(), '') 
    161172            if funcname: 
    162173                for tkt_id in ticket_re.findall(tkts): 
    163174                    func = getattr(self, funcname) 
    164175                    tickets.setdefault(tkt_id, []).append(func) 
     176                    owners[tkt_id] = owner or self.author 
    165177 
    166178        for tkt_id, cmds in tickets.iteritems(): 
    167179            try: 
     
    169181                 
    170182                ticket = Ticket(self.env, int(tkt_id), db) 
    171183                for cmd in cmds: 
    172                     cmd(ticket) 
     184                    cmd(ticket, owners[tkt_id]) 
    173185 
    174186                # determine sequence number...  
    175187                cnum = 0 
     
    190202                                   'ID %s: %s' % (tkt_id, e) 
    191203             
    192204 
    193     def _cmdClose(self, ticket): 
     205    def _cmdClose(self, ticket, owner = ''): 
    194206        ticket['status'] = 'closed' 
    195207        ticket['resolution'] = 'fixed' 
    196208 
    197     def _cmdRefs(self, ticket): 
     209    def _cmdRefs(self, ticket, owner = ''): 
    198210        pass 
    199211 
     212    def _cmdAssign(self, ticket, owner): 
     213        if ticket['cc'].find(ticket['owner']) == -1: 
     214            ticket['cc'] += ", " + ticket['owner'] 
     215        ticket['owner'] = owner 
     216 
    200217 
    201218if __name__ == "__main__": 
    202219    if len(sys.argv) < 5: