Skip to content

Instantly share code, notes, and snippets.

@joestump
Last active September 27, 2018 15:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joestump/27ddfef50dcb54a7f013 to your computer and use it in GitHub Desktop.
Save joestump/27ddfef50dcb54a7f013 to your computer and use it in GitHub Desktop.
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
Copy link
Author

  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
Copy link

Thanks Joe!

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