Ticket #7300: reassignment.patch
| File reassignment.patch, 4.2 KB (added by ian@…, 4 years ago) |
|---|
-
trac-post-commit-hook
old new 2 2 3 3 # trac-post-commit-hook 4 4 # ---------------------------------------------------------------------------- 5 # Copyright (c) 2004 Stephen Hansen 5 # Copyright (c) 2004 Stephen Hansen 6 # Portions copyright (c) 2008 Digg, LLC. 6 7 # 7 8 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 9 # of this software and associated documentation files (the "Software"), to … … 39 40 # (all the other arguments are now deprecated and not needed anymore) 40 41 # 41 42 # 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] 46 47 # 47 48 # Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.: 48 49 # command ticket:1 … … 62 63 # commit message being added to it. 63 64 # references, refs, addresses, re, see 64 65 # 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 66 71 # 67 72 # A fairly complicated example of what you can do is with a commit message 68 73 # of: … … 111 116 112 117 113 118 ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)' 119 ticket_suffix = '(?:(?: +to +)?(?P<owner>[a-z]+))?' 114 120 ticket_reference = ticket_prefix + '[0-9]+' 115 121 ticket_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)) 118 124 119 125 if options.envelope: 120 126 ticket_command = r'\%s%s\%s' % (options.envelope[0], ticket_command, … … 134 140 're': '_cmdRefs', 135 141 'references': '_cmdRefs', 136 142 'refs': '_cmdRefs', 137 'see': '_cmdRefs'} 143 'see': '_cmdRefs', 144 'reassign': '_cmdAssign', 145 'reassigns': '_cmdAssign', 146 'assign': '_cmdAssign', 147 'assigns': '_cmdAssign'} 138 148 139 149 def __init__(self, project=options.project, author=options.user, 140 150 rev=options.rev, url=options.url): … … 156 166 cmd_groups = command_re.findall(self.msg) 157 167 158 168 tickets = {} 159 for cmd, tkts in cmd_groups: 169 owners = {} 170 for cmd, tkts, owner in cmd_groups: 160 171 funcname = CommitHook._supported_cmds.get(cmd.lower(), '') 161 172 if funcname: 162 173 for tkt_id in ticket_re.findall(tkts): 163 174 func = getattr(self, funcname) 164 175 tickets.setdefault(tkt_id, []).append(func) 176 owners[tkt_id] = owner or self.author 165 177 166 178 for tkt_id, cmds in tickets.iteritems(): 167 179 try: … … 169 181 170 182 ticket = Ticket(self.env, int(tkt_id), db) 171 183 for cmd in cmds: 172 cmd(ticket )184 cmd(ticket, owners[tkt_id]) 173 185 174 186 # determine sequence number... 175 187 cnum = 0 … … 190 202 'ID %s: %s' % (tkt_id, e) 191 203 192 204 193 def _cmdClose(self, ticket ):205 def _cmdClose(self, ticket, owner = ''): 194 206 ticket['status'] = 'closed' 195 207 ticket['resolution'] = 'fixed' 196 208 197 def _cmdRefs(self, ticket ):209 def _cmdRefs(self, ticket, owner = ''): 198 210 pass 199 211 212 def _cmdAssign(self, ticket, owner): 213 if ticket['cc'].find(ticket['owner']) == -1: 214 ticket['cc'] += ", " + ticket['owner'] 215 ticket['owner'] = owner 216 200 217 201 218 if __name__ == "__main__": 202 219 if len(sys.argv) < 5:
