Skip to content

Commit e079eef

Browse files
authored
Dynamic calculation of how many years (#134)
1 parent 8d93713 commit e079eef

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

gitstats/report_creator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import datetime
99
import time
10+
import math
1011
from gitstats import load_config, GNUPLOT_COMMON, WEEKDAYS
1112
from gitstats.utils import (
1213
get_version,
@@ -134,7 +135,16 @@ def create_activity_html(self, data, path):
134135
# f.write('<h2>Last 12 months</h2>')
135136

136137
# Yearly activity
137-
YEARS = 5
138+
first_commit_timestamp = get_pipe_output(
139+
["git log --reverse --pretty=format:%ct | head -n 1"], quiet=True
140+
)
141+
if first_commit_timestamp:
142+
repo_age_years = (
143+
time.time() - int(first_commit_timestamp)
144+
) / 31536000 # 365 days
145+
YEARS = max(5, int(math.ceil(repo_age_years / 5.0)) * 5)
146+
else:
147+
YEARS = 5
138148
f.write(html_header(2, "Yearly activity"))
139149
f.write("<p>Last %d years</p>" % YEARS)
140150

0 commit comments

Comments
 (0)