Skip to content

Instantly share code, notes, and snippets.

@macterra
Created July 27, 2017 17:34
Show Gist options
  • Save macterra/83ec4a7ada5a5810c58d1457df48d002 to your computer and use it in GitHub Desktop.
Save macterra/83ec4a7ada5a5810c58d1457df48d002 to your computer and use it in GitHub Desktop.
from jira import JIRA
from datetime import timedelta, date
import dateutil.parser
def daterange(startDate, endDate):
for n in range(int ((endDate - startDate).days)):
yield startDate + timedelta(n)
jira = JIRA('https://jira.synaptivemedical.com', basic_auth=('davidmcfadzean', '[redacted]'))
def getStatusTransitions(key, date):
bug = jira.issue(key, expand='changelog')
transitions = []
for entry in bug.changelog.histories:
entryDate = dateutil.parser.parse(entry.created).strftime("%Y/%m/%d")
if entryDate == date:
for item in entry.items:
if item.field == 'status':
transitions.append(item)
return transitions
startDate = date(2017, 5, 1)
endDate = date(2017, 7, 30)
filter = "Drive - must fix bugs"
statusList = ["Open", "In Progress", "Reopened", "In Review", "Resolved", "Closed"]
print "date, open, reopened, in progress, in review, resolved, closed, total"
for singleDate in daterange(startDate, endDate):
counts = {}
date = singleDate.strftime("%Y/%m/%d")
for status in statusList:
query = 'filter = "%s" AND status was in ("%s") on "%s"' % (filter, status, date)
bugs = jira.search_issues(query, maxResults=1000)
counts[status] = len(bugs)
query = 'filter = "%s" AND status changed on "%s"' % (filter, date)
bugs = jira.search_issues(query, maxResults=1000)
for bug in bugs:
transitions = getStatusTransitions(bug.key, date)
for transition in transitions:
status = transition.fromString
counts[status] = counts[status] - 1
total = sum(counts.values())
print "%s, %d, %d, %d, %d, %d, %d, %d" % (date, counts['Open'], counts['Reopened'], counts['In Progress'], counts['In Review'], counts['Resolved'], counts['Closed'], total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment