Skip to content

Instantly share code, notes, and snippets.

@joestump
Last active Sep 27, 2018
Embed
What would you like to do?
TICKET_PREFIX = '(?:#|(?:ticket|issue|item|defect|bug)[: ]?)'
TICKET_RE = re.compile(TICKET_PREFIX + '([0-9]+)', re.I | re.UNICODE)
class CommitParser(object):
_ticket_reference = TICKET_PREFIX + '[0-9]+'
_ticket_command = (r'(?P<action>[A-Za-z]*) ?(task|issue|defect|bug|item|ticket|:)?.?'
'(?P<ticket>%s(?:(?:[, &]*|[ ,]+?and[ ]?)%s)*)' %
(_ticket_reference, _ticket_reference))
_command_re = re.compile(_ticket_command, re.I | re.UNICODE)
_ticket_re = re.compile(TICKET_PREFIX + '([0-9]+)', re.I | re.UNICODE)
_item_cmds = {'close': 'close_ticket',
'closed': 'close_ticket',
'closes': 'close_ticket',
'finish': 'close_ticket',
'finished': 'close_ticket',
'finishes': 'close_ticket',
'fix': 'close_ticket',
'fixed': 'close_ticket',
'fixes': 'close_ticket',
'breaks': 'reopen_ticket',
'unfixes': 'reopen_ticket',
'reopen': 'reopen_ticket',
'reopens': 'reopen_ticket',
're-open': 'reopen_ticket',
're-opens': 'reopen_ticket',
'addresses': 'reference_ticket',
're': 'reference_ticket',
'ref': 'reference_ticket',
'references': 'reference_ticket',
'refs': 'reference_ticket',
'start': 'reference_ticket',
'starts': 'reference_ticket',
'see': 'reference_ticket'}
@joestump

This comment has been minimized.

Copy link
Owner Author

@joestump joestump commented Mar 18, 2014

  1. We use the _command_re to find all instances of _item_cmds referencing something that looks like a ticket.
  2. We then use TICKET_RE to find all instances of a ticket.

I should mention this is some of the oldest code in Sprint.ly so it's probably a bit crufty in some places. That being said, it's also pretty well tested and generally picks up what it should and leaves what it shouldn't.

@maxbeatty

This comment has been minimized.

Copy link

@maxbeatty maxbeatty commented Mar 19, 2014

Thanks Joe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment