Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create changelog for a new Cepheid version based on git log and fogbugz data
#! /usr/bin/python
from fogbugz import FogBugz
from datetime import datetime, timedelta
from itertools import groupby
import subprocess
import re
import sys
url = 'https://instedd.fogbugz.com/'
email = 'FB_EMAIL'
password = 'FB_PASS'
path = 'PATH_TO_REPOS'
def main(v1, v2):
fb = fbcases()
logs = gitcases(v1, v2)
def getid(entry):
match = re.search('\d{4}', entry)
return match.group() if match else None
logsbyid = groupby(sorted(logs, key=getid), getid)
print "FogBugz ID, Title, TeamTrack ID, Comments, Commits"
for caseid, logentries in logsbyid:
if caseid:
case = fb[caseid]
print "{0}, \"{1}\", {2},, \"{3}\"".format(case.ixbug.string, case.stitle.string.encode('UTF-8'), case.teamtrackxid.string, '; '.join(logentries))
else:
for logentry in logentries:
print ",,,,\"{0}\"".format(logentry)
def fbcases():
fb = FogBugz(url)
fb.logon(email, password)
fb.setCurrentFilter(sFilter=132)
response = fb.search(cols="ixBug,sTitle,TeamTrackxID")
cases = dict([(case.ixbug.string, case)for case in response.cases.childGenerator()])
return cases
def gitcases(v1, v2):
repos = ['reporter', 'receiver', 'web']
logs = sum([subprocess.check_output(["git", '--git-dir={0}/cepheid-{1}/.git'.format(path, repo), 'log', '{0}..{1}'.format(v1,v2), '--format=format:%s'], stderr=subprocess.STDOUT).split("\n") for repo in repos], [])
return logs
if __name__ == "__main__":
if len(sys.argv) < 3: print "Usage: changelog FROM_VERSION TO_VERSION"
else: main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment