-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (53 loc) · 1.85 KB
/
main.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
from datetime import datetime, timedelta, timezone
import typer
from gitlab.v4.objects import ProjectIssue
from gitlab_burndown.config import get_config
from gitlab_burndown.discovery import (
get_issues_for_project,
search_project_id_by_project_name,
)
from gitlab_burndown.plotting import draw_plot, prepare_burndown_data
from gitlab_burndown.transformer import TimeInfo, transform_issue_to_time_info
app = typer.Typer()
def parse_duration(duration_str: str) -> datetime:
"""Parse a string like '30d', '2m' and return a timezone-aware datetime object."""
now = datetime.now(timezone.utc) # Use timezone-aware datetime (UTC)
if duration_str.endswith("d"):
days = int(duration_str[:-1])
return now - timedelta(days=days)
elif duration_str.endswith("m"):
months = int(duration_str[:-1])
return now - timedelta(days=months * 30)
else:
raise ValueError(
"Invalid duration format. Use 'Xd' for days or 'Xm' for months."
)
@app.command()
def burndown(
duration: str = typer.Argument(
"30d", help="Duration string like '30d' for 30 days, '2m' for 2 months."
),
):
"""Main function to run the burndown chart generation."""
project_id: int = search_project_id_by_project_name(
get_config().GITLAB_PROJECT_NAME
)
issues: list[ProjectIssue] = get_issues_for_project(project_id)
time_info: list[TimeInfo] = [
transform_issue_to_time_info(issue) for issue in issues
]
start_date = parse_duration(duration)
(
dates,
remaining_estimates,
remaining_estimates_hours,
total_time_estimate,
) = prepare_burndown_data(time_info, start_date)
draw_plot(
dates,
remaining_estimates,
remaining_estimates_hours,
total_time_estimate,
)
if __name__ == "__main__":
app()