-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_reports.py
71 lines (54 loc) · 2.06 KB
/
user_reports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
from datetime import date
from collections import defaultdict
from types import SimpleNamespace
from argparse import ArgumentParser, Namespace
from helpers.generic import (
make_skip_days,
load_config,
connect,
get_worklogs,
reverse_workdays,
)
def main(args: Namespace, config: SimpleNamespace):
## Use settings and arguments
first = config.today.replace(day=1)
last = config.today
skip = make_skip_days(config.skip_days)
## Read JIRA worklogs
client, _ = connect(config)
user_email = args.user or config.jira.api_user
users = client.search_users(query=user_email)
if len(users) != 1:
print("Users matching", user_email)
print(*users, sep=",\n")
raise RuntimeError(f"Expected exactly one user, found {len(users)}")
user = users.pop()
worklogs = get_worklogs(client, user.accountId, first, last)
print("Found worklogs of", user.displayName)
tickets_acc = defaultdict(float)
hours_acc = 0.0
print("* Daily summary *")
for day in reverse_workdays(first, last, skip):
day_str = day.isoformat()
if day_str in worklogs:
tickets = {log.issue for log in worklogs[day_str]}
hours = sum(log.time_spent for log in worklogs[day_str])
for log in worklogs[day_str]:
tickets_acc[log.issue] += log.time_spent
day_tickets = ", ".join(sorted(tickets))
print(f" - {day_str}: {hours:5.1f} ({day_tickets})")
hours_acc += hours
print("\n", "* Ticket summary *")
for issue, hours in tickets_acc.items():
print(f" - {issue:10}: {hours:>6.1f} h")
print(" -----------")
print(f" (total) {hours_acc:>6.1f} h")
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-u", "--user", type=str)
parser.add_argument("--today", type=date.fromisoformat)
args = parser.parse_args()
config = load_config("project.toml")
config.today = args.today if args.today else date.today()
main(args, config)