Skip to content

Instantly share code, notes, and snippets.

@mattfenwick
Last active September 11, 2015 20:49
Show Gist options
  • Save mattfenwick/509d43f5fef043ad277a to your computer and use it in GitHub Desktop.
Save mattfenwick/509d43f5fef043ad277a to your computer and use it in GitHub Desktop.
extract tickets from git history using commit messages
import subprocess
import re
import sys
if len(sys.argv) != 3:
print "incorrect args"
print sys.argv
sys.exit(1)
versions_arg = "{0}..{1}".format(sys.argv[1], sys.argv[2])
p = subprocess.Popen(['git', 'log', '--no-merges', '--grep=[a-zA-Z]\\{4\\}-[0-9]', '--format=%s', versions_arg],
shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
lines = p.stdout.readlines()
def extract(lines):
tickets = {}
pattern = re.compile('([a-zA-Z]{4})-(\d+)')
for line in lines:
for (squad, number) in re.findall(pattern, line):
normalized = (squad.upper(), int(number))
if normalized not in tickets:
tickets[normalized] = []
tickets[normalized].append(line)
return tickets
def print_with_messages(tickets):
for ((squad, number), messages) in sorted(tickets.items(), key=lambda x: x[0]):
print squad, '-', number
for message in messages:
print ' ', message
tickets = extract(lines)
#print tickets
print_with_messages(tickets)
import subprocess
import re
import sys
if len(sys.argv) != 3:
print "incorrect args"
print sys.argv
sys.exit(1)
versions_arg = "{0}..{1}".format(sys.argv[1], sys.argv[2])
p = subprocess.Popen(['git', 'log', '--no-merges', '--grep=[a-zA-Z]\\{3,4\\}-[0-9]', '--format=%s', versions_arg],
shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
lines = p.stdout.readlines()
def extract(lines):
tickets = {}
pattern = re.compile('([a-zA-Z]{3,4})-(\d+)')
for line in lines:
for (squad, number) in re.findall(pattern, line):
normalized = (squad.upper(), int(number))
if normalized not in tickets:
tickets[normalized] = []
tickets[normalized].append(line)
return tickets
def print_with_messages(tickets):
for ((squad, number), messages) in sorted(tickets.items(), key=lambda x: x[0]):
print squad, '-', number
for message in messages:
print ' ', message
def print_tickets(tickets):
for ((squad, number), messages) in sorted(tickets.items(), key=lambda x: x[0]):
print squad, '-', number
tickets = extract(lines)
#print_tickets(tickets)
print_with_messages(tickets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment