Commit 5424b55e authored by Thomas Lotze's avatar Thomas Lotze

refactoring: separate details of collecting issue time from filter logic

parent 91b7da5d
......@@ -45,39 +45,14 @@ def fetch(url, token, filter):
issues = project.issues.list(all=True)
for issue in issues:
# Time tracking in Gitlab works like this: For each comment (note)
# containing a time tracking directive, an additional system note
# is created at that time, which either adds or subtracts time for
# an arbitrary date, or removes any previous time spent. Removal
# invalidates any tracking notes prior to its creation. Tracking
# done after the latest removal always applies, regardless of the
# date it applies to. Thus, we need to consider any and all time
# tracking done after the latest removal, 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 note.
notes = issue.notes.list(
all=True, order_by='created_at', sort='desc')
entries = defaultdict(float)
for note in notes:
if not note.system:
continue
if note.body == 'removed time spent':
break
if filter['username'] not in (note.author['username'], None):
for author, date, seconds in fetch_issue(issue):
if filter['username'] not in (author, None):
continue
sep = ' of time spent at '
action, _, date = note.body.partition(sep)
if _ != sep:
continue
if not date.startswith(filter['month'] or ''):
continue
seconds = parse_action(action)
entries[note.author['username'], date] += seconds
entries[author, date] += seconds
for (author, date), seconds in entries.items():
yield dict(
......@@ -87,3 +62,33 @@ def fetch(url, token, filter):
date=date,
hours=round(seconds/3600, 2),
)
def fetch_issue(issue):
# 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
# arbitrary date, or removes any previous time spent. Removal invalidates
# any tracking notes prior to its creation. Tracking done after the latest
# removal always applies, regardless of the date it applies to. Thus, we
# need to consider any and all time tracking done after the latest
# removal, 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 note.
notes = issue.notes.list(
all=True, order_by='created_at', sort='desc')
for note in notes:
if not note.system:
continue
if note.body == 'removed time spent':
break
sep = ' of time spent at '
action, _, date = note.body.partition(sep)
if _ != sep:
continue
seconds = parse_action(action)
yield note.author['username'], date, seconds
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