From dd644cecc04e650ac14e2fe5c864e6b01cfc7faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Tue, 17 Jan 2023 10:53:43 +0100 Subject: [PATCH] Skip archived repo & add GitHub badge --- conf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/conf.py b/conf.py index d9672d5..d65635a 100644 --- a/conf.py +++ b/conf.py @@ -17,6 +17,7 @@ # List all organization extensions import os import pathlib +import re import recommonmark import requests from datetime import datetime @@ -25,6 +26,7 @@ HERE = pathlib.Path(__file__).parent GET_REPOS = "https://api.github.com/orgs/jupyterlab-contrib/repos" GET_REPO = "https://api.github.com/repos/jupyterlab-contrib/" +REPO_BADGE = "[![GitHub Repo stars](https://img.shields.io/github/stars/jupyterlab-contrib/{name}?style=social)]({html_url})" TOKEN = os.getenv("GITHUB_TOKEN") footer = (HERE / "extensions.tpl").read_text() @@ -51,8 +53,8 @@ if isinstance(repo, str): raise ValueError(data["message"]) - if "github" in repo["name"]: - continue # Skip special repositories + if "github" in repo["name"] or repo["archived"]: + continue # Skip special repositories and archived ones try: response = requests.get( @@ -69,7 +71,9 @@ }, ) filename = repo["name"] - (HERE / (filename + ".md")).write_text(readme.text) + badge = REPO_BADGE.format(name=repo["name"], html_url=repo["html_url"]) + readme_content = re.sub(r"\n\n", f"\n\n{badge}", readme.text, count=1) + (HERE / (filename + ".md")).write_text(readme_content) extensions += f"\n* [{filename.replace('_', ' ')}]({filename}.md): {description}" except BaseException as err: print(err)