1515LOGGER = logging .getLogger (__name__ )
1616
1717
18- def calculate_monthly_stat (year_month_file : Path ) -> tuple [int , int , int ]:
18+ def calculate_monthly_stat (
19+ year_month_file : Path , year_month_date : datetime .date
20+ ) -> tuple [int , int , int ]:
1921 year_month_file_content = year_month_file .read_text ()
2022
2123 builds = sum (
@@ -25,20 +27,15 @@ def calculate_monthly_stat(year_month_file: Path) -> tuple[int, int, int]:
2527
2628 images = year_month_file_content .count ("Build manifest" )
2729
28- year_month = year_month_file .stem
29- current_month = datetime .date (
30- year = int (year_month [:4 ]), month = int (year_month [5 :]), day = 1
31- )
32- next_month = current_month + relativedelta .relativedelta (months = 1 )
3330 with plumbum .local .env (TZ = "UTC" ):
3431 future = (
3532 git [
3633 "log" ,
3734 "--oneline" ,
3835 "--since" ,
39- f"{ current_month } .midnight" ,
36+ f"{ year_month_date } .midnight" ,
4037 "--until" ,
41- f"{ next_month } .midnight" ,
38+ f"{ year_month_date + relativedelta . relativedelta ( months = 1 ) } .midnight" ,
4239 "--first-parent" ,
4340 ]
4441 & plumbum .BG
@@ -63,22 +60,39 @@ def regenerate_home_wiki_page(wiki_dir: Path) -> None:
6360 YEAR_TABLE_HEADER = """\
6461 ## {year}
6562
66- | Month | Builds | Images | Commits |
67- | ---------------------- | ------ | ------ | ------- |
63+ | Month | Builds | Images | Commits |
64+ | ---------------------- | ------ | ------ | ----------------------------------------------------------------------------------------------- |
6865"""
6966
67+ GITHUB_COMMITS_URL = (
68+ "[{}](https://github.com/jupyter/docker-stacks/commits/main/?since={}&until={})"
69+ )
70+
7071 for year_dir in sorted ((wiki_dir / "monthly-files" ).glob ("*" ), reverse = True ):
7172 wiki_home_content += "\n " + YEAR_TABLE_HEADER .format (year = year_dir .name )
7273 year_builds , year_images , year_commits = 0 , 0 , 0
7374 for year_month_file in sorted (year_dir .glob ("*.md" ), reverse = True ):
74- builds , images , commits = calculate_monthly_stat (year_month_file )
75+ year_month = year_month_file .stem
76+ year_month_date = datetime .date (
77+ year = int (year_month [:4 ]), month = int (year_month [5 :]), day = 1
78+ )
79+ builds , images , commits = calculate_monthly_stat (
80+ year_month_file , year_month_date
81+ )
7582 year_builds += builds
7683 year_images += images
7784 year_commits += commits
78- year_month = year_month_file .stem
79- monthly_line = f"| [`{ year_month } `](./{ year_month } ) | { builds : <6} | { images : <6} | { commits : <7} |\n "
85+ commits_url = GITHUB_COMMITS_URL .format (
86+ commits ,
87+ year_month_date ,
88+ year_month_date + relativedelta .relativedelta (day = 31 ),
89+ )
90+ monthly_line = f"| [`{ year_month } `](./{ year_month } ) | { builds : <6} | { images : <6} | { commits_url : <95} |\n "
8091 wiki_home_content += monthly_line
81- year_total_line = f"| **Total** | { year_builds : <6} | { year_images : <6} | { year_commits : <7} |\n "
92+ year_commits_url = GITHUB_COMMITS_URL .format (
93+ year_commits , f"{ year_dir .name } -01-01" , f"{ year_dir .name } -12-31"
94+ )
95+ year_total_line = f"| **Total** | { year_builds : <6} | { year_images : <6} | { year_commits_url : <95} |\n "
8296 wiki_home_content += year_total_line
8397
8498 wiki_home_file .write_text (wiki_home_content )
0 commit comments