Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
oss
gitlabtime
Commits
5424b55e
Commit
5424b55e
authored
Aug 03, 2002
by
Thomas Lotze
Browse files
refactoring: separate details of collecting issue time from filter logic
parent
91b7da5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/gitlabtime/fetch.py
View file @
5424b55e
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment