Commit af555b8c authored by Thomas Lotze's avatar Thomas Lotze

re #19: rename issue to item to accomodate other types of time-tracking entities

parent 901f708b
......@@ -44,9 +44,9 @@ def fetch(url, token, filter):
issues = project.issues.list(all=True)
for issue in issues:
for item in issues:
entries = defaultdict(float)
for author, date, seconds in fetch_issue(issue):
for author, date, seconds in fetch_times(item):
if filter['username'] not in (author, None):
continue
if not date.startswith(filter['month'] or ''):
......@@ -57,14 +57,14 @@ def fetch(url, token, filter):
for (author, date), seconds in entries.items():
yield dict(
project=project,
issue=issue,
item=item,
author=author,
date=date,
hours=round(seconds/3600, 2),
)
def fetch_issue(issue):
def fetch_times(item):
# Time tracking in Gitlab works like this: For each comment (note)
# containing a time-tracking quick action, an additional system note is
# created at that time, which either adds or subtracts time for an
......@@ -79,7 +79,7 @@ def fetch_issue(issue):
# latest removal or "move from", which may track time for any date, in any
# order. We do this by iterating through notes backwards by creation date
# until we find a removal or "move from" note.
notes = issue.notes.list(
notes = item.notes.list(
all=True, order_by='created_at', sort='desc')
total = 0
......@@ -101,21 +101,21 @@ def fetch_issue(issue):
yield note.author['username'], date, seconds
else:
# We've now visited all notes up until issue creation. Time may also
# We've now visited all notes up until item creation. Time may also
# have been tracked by a quick action in the original project
# description (but not later edits). In that case, no system note is
# added and if that time tracking was applied to some date, that date
# is lost. We can only infer the amount of time as the difference
# between the total time as given by the issue's time stats and the
# between the total time as given by the item's time stats and the
# total time tracked by notes, and apply it to the creation date of
# the issue.
seconds = issue.time_stats()['total_time_spent'] - total
# the item.
seconds = item.time_stats()['total_time_spent'] - total
if not seconds:
return
# Dates come without time zones and we don't know how Gitlab converts
# from time-zone aware to unaware, so we don't think about time zones
# and hope for the best.
date = issue.created_at.split('T')[0]
date = item.created_at.split('T')[0]
yield issue.author['username'], date, seconds
yield item.author['username'], date, seconds
......@@ -7,24 +7,24 @@ def report(entries):
times = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
totals_by_project = defaultdict(float)
totals_by_issue = defaultdict(float)
totals_by_item = defaultdict(float)
for entry in entries:
project = entry['project'].name
issue = entry['issue']
issue = (issue.iid, issue)
item = entry['item']
item = (item.iid, item)
author = entry['author']
times[project][issue][author].append((entry['date'], entry['hours']))
times[project][item][author].append((entry['date'], entry['hours']))
totals_by_project[project] += entry['hours']
totals_by_issue[issue] += entry['hours']
totals_by_item[item] += entry['hours']
total = sum(totals_by_project.values())
for project, times_by_issue in sorted(times.items()):
for project, times_by_item in sorted(times.items()):
print('{}: {:.2f}'.format(project, totals_by_project[project]))
for (_, issue), times_by_author in sorted(times_by_issue.items()):
for (_, item), times_by_author in sorted(times_by_item.items()):
print('{}#{}: {:.2f} ({})'.format(
4*' ', issue.iid, totals_by_issue[issue], issue.title))
4*' ', item.iid, totals_by_item[item], item.title))
for author, time_log in sorted(times_by_author.items()):
for date, hours in sorted(time_log):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment