Skip to content

Commit

Permalink
Add number of commits to wiki home page
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbunnyru committed Dec 30, 2024
1 parent 9ffeb23 commit af0493a
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions tagging/update_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,51 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import argparse
import datetime
import logging
import shutil
from pathlib import Path

LOGGER = logging.getLogger(__name__)
import plumbum
from dateutil import relativedelta

git = plumbum.local["git"]

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

YEAR_TABLE_HEADER = """\
YEAR_TABLE_HEADER = """\
## {year}
| Month | Builds | Images |
| ---------------------- | ------ | ------ |
| Month | Builds | Images | Commits |
| ---------------------- | ------ | ------ | ------- |
"""


def build_monthly_table_line(year_month_file: Path) -> str:
year_month_file_content = year_month_file.read_text()
images = year_month_file_content.count("Build manifest")
builds = sum(
"jupyter/base-notebook" in line and "aarch64" not in line
for line in year_month_file_content.split("\n")
)
year_month = year_month_file.stem
current_month = datetime.date(
year=int(year_month[:4]), month=int(year_month[5:]), day=1
)
next_month = current_month + relativedelta.relativedelta(months=1)
future = (
git["log", "--oneline", "--since", current_month, "--until", next_month]
& plumbum.BG
)
future.wait()
commits = len(future.stdout.splitlines())

return f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} | {commits: <7} |\n"


def regenerate_home_wiki_page(wiki_dir: Path) -> None:
YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n"

wiki_home_file = wiki_dir / "Home.md"
wiki_home_content = wiki_home_file.read_text()

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

all_year_dirs = sorted((wiki_dir / "monthly-files").glob("*"), reverse=True)
for year_dir in all_year_dirs:
for year_dir in sorted((wiki_dir / "monthly-files").glob("*"), reverse=True):
wiki_home_content += "\n" + YEAR_TABLE_HEADER.format(year=year_dir.name)

all_year_month_files = sorted(year_dir.glob("*.md"), reverse=True)
for year_month_file in all_year_month_files:
year_month_file_content = year_month_file.read_text()
images = year_month_file_content.count("Build manifest")
builds = sum(
"jupyter/base-notebook" in line and "aarch64" not in line
for line in year_month_file_content.split("\n")
)
year_month = year_month_file.stem
wiki_home_content += (
f"| [`{year_month}`](./{year_month}) | {builds: <6} | {images: <6} |\n"
)
for year_month_file in sorted(year_dir.glob("*.md"), reverse=True):
wiki_home_content += build_monthly_table_line(year_month_file)

wiki_home_file.write_text(wiki_home_content)
LOGGER.info("Updated Home page")
Expand Down

0 comments on commit af0493a

Please sign in to comment.