Commit f2fbe1c6 authored by Thomas Lotze's avatar Thomas Lotze

add unfiltered querying of Gitlab

parent cff6f608
......@@ -14,9 +14,58 @@
]
},
"default": {
"certifi": {
"hashes": [
"sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3",
"sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"
],
"version": "==2020.6.20"
},
"chardet": {
"hashes": [
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
],
"version": "==3.0.4"
},
"click": {
"hashes": [
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
],
"version": "==7.1.2"
},
"gitlabtime": {
"editable": true,
"path": "."
},
"idna": {
"hashes": [
"sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
"sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
],
"version": "==2.10"
},
"python-gitlab": {
"hashes": [
"sha256:6461e0662cacceb795fb3ffd225391133cc11e0e760d0caf1c998c7ba955c771",
"sha256:e240b5c371d9e98c46c980d878c3f03cd83f3da6cda01d533db27fa3e0dd474f"
],
"version": "==2.4.0"
},
"requests": {
"hashes": [
"sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b",
"sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"
],
"version": "==2.24.0"
},
"urllib3": {
"hashes": [
"sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a",
"sha256:e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461"
],
"version": "==1.25.10"
}
},
"develop": {}
......
......@@ -7,3 +7,12 @@ Create reports from gitlab time tracking.
* Free software: MIT license
Usage
=====
See `$ gitlabtime --help`.
Options can be pre-specified as environment variables, e.g. the default value
of `--url` is taken from `GITLABTIME_URL`.
......@@ -22,6 +22,8 @@ gitlabtime=gitlabtime.cli:main
"""
INSTALL_REQUIRES = """\
click
python-gitlab
"""
......
from gitlabtime.fetch import fetch
import click
@click.command()
@click.option(
'--url',
help='Gitlab URL',
prompt='Gitlab URL',
)
@click.option(
'--token',
help='Access token',
prompt='Access token',
)
def cli(url, token):
entries = fetch(url, token)
for entry in entries:
print(entry)
def main():
return cli(auto_envvar_prefix='GITLABTIME')
from collections import defaultdict
from gitlab import Gitlab
def parse_action(action):
op, time_str = action.split()
sign = dict(added=1, subtracted=-1)[op]
ulen = 2 if time_str.endswith('mo') else 1
value_str, unit_str = time_str[:-ulen], time_str[-ulen:]
unit = dict(
mo=576000,
w=144000,
d=28800,
h=3600,
m=60,
s=1,
)[unit_str]
return sign * float(value_str) * unit
def fetch(url, token):
gitlab = Gitlab(url, token)
projects = gitlab.projects.list(all=True)
for project in projects:
issues = project.issues.list(all=True)
for issue in issues:
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
sep = ' of time spent at '
action, _, date = note.body.partition(sep)
if _ != sep:
continue
seconds = parse_action(action)
entries[note.author['username'], date] += seconds
for (author, date), seconds in entries.items():
yield dict(
project=project,
issue=issue,
author=author,
date=date,
hours=round(seconds/3600, 2),
)
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