Skip to content

Commit af0493a

Browse files
committed
Add number of commits to wiki home page
1 parent 9ffeb23 commit af0493a

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

tagging/update_wiki.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,51 @@
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
44
import argparse
5+
import datetime
56
import logging
67
import shutil
78
from pathlib import Path
89

9-
LOGGER = logging.getLogger(__name__)
10+
import plumbum
11+
from dateutil import relativedelta
1012

13+
git = plumbum.local["git"]
1114

12-
def regenerate_home_wiki_page(wiki_dir: Path) -> None:
13-
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n"
15+
LOGGER = logging.getLogger(__name__)
1416

15-
YEAR_TABLE_HEADER = """\
17+
YEAR_TABLE_HEADER = """\
1618
## {year}
1719
18-
| Month | Builds | Images |
19-
| ---------------------- | ------ | ------ |
20+
| Month | Builds | Images | Commits |
21+
| ---------------------- | ------ | ------ | ------- |
2022
"""
2123

24+
25+
def build_monthly_table_line(year_month_file: Path) -> str:
26+
year_month_file_content = year_month_file.read_text()
27+
images = year_month_file_content.count("Build manifest")
28+
builds = sum(
29+
"jupyter/base-notebook" in line and "aarch64" not in line
30+
for line in year_month_file_content.split("\n")
31+
)
32+
year_month = year_month_file.stem
33+
current_month = datetime.date(
34+
year=int(year_month[:4]), month=int(year_month[5:]), day=1
35+
)
36+
next_month = current_month + relativedelta.relativedelta(months=1)
37+
future = (
38+
git["log", "--oneline", "--since", current_month, "--until", next_month]
39+
& plumbum.BG
40+
)
41+
future.wait()
42+
commits = len(future.stdout.splitlines())
43+
44+
return f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} | {commits: <7} |\n"
45+
46+
47+
def regenerate_home_wiki_page(wiki_dir: Path) -> None:
48+
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n"
49+
2250
wiki_home_file = wiki_dir / "Home.md"
2351
wiki_home_content = wiki_home_file.read_text()
2452

@@ -27,22 +55,10 @@ def regenerate_home_wiki_page(wiki_dir: Path) -> None:
2755
: wiki_home_content.find(YEAR_MONTHLY_TABLES) + len(YEAR_MONTHLY_TABLES)
2856
]
2957

30-
all_year_dirs = sorted((wiki_dir / "monthly-files").glob("*"), reverse=True)
31-
for year_dir in all_year_dirs:
58+
for year_dir in sorted((wiki_dir / "monthly-files").glob("*"), reverse=True):
3259
wiki_home_content += "\n" + YEAR_TABLE_HEADER.format(year=year_dir.name)
33-
34-
all_year_month_files = sorted(year_dir.glob("*.md"), reverse=True)
35-
for year_month_file in all_year_month_files:
36-
year_month_file_content = year_month_file.read_text()
37-
images = year_month_file_content.count("Build manifest")
38-
builds = sum(
39-
"jupyter/base-notebook" in line and "aarch64" not in line
40-
for line in year_month_file_content.split("\n")
41-
)
42-
year_month = year_month_file.stem
43-
wiki_home_content += (
44-
f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} |\n"
45-
)
60+
for year_month_file in sorted(year_dir.glob("*.md"), reverse=True):
61+
wiki_home_content += build_monthly_table_line(year_month_file)
4662

4763
wiki_home_file.write_text(wiki_home_content)
4864
LOGGER.info("Updated Home page")

0 commit comments

Comments
 (0)