From 65ba4e8608b1d53d7e0b602d2aaad5d005c95cbd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 21 Aug 2024 09:07:39 -0400 Subject: [PATCH] Sanitize MD and initiate addition of tests dependabot sends PRs with `[]()` in the title eg [gh-actions](deps): Bump actions/setup-python from 4 to 5 making it not legitimate markdown - [[gh-actions](deps): Bump actions/setup-python from 4 to 5](https://github.com/dandi/zarr_checksum/pull/42) (253 days) so with this change we just remove any of the [] symbols, making it a legit - [gh-actions(deps): Bump actions/setup-python from 4 to 5](https://github.com/dandi/zarr_checksum/pull/42) (253 days) --- setup.cfg | 6 ++++++ src/solidation/__main__.py | 7 ++++++- src/solidation/tests/__init__.py | 0 src/solidation/tests/test_main.py | 5 +++++ tox.ini | 7 ++++++- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/solidation/tests/__init__.py create mode 100644 src/solidation/tests/test_main.py diff --git a/setup.cfg b/setup.cfg index d5ca746..fec5c85 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,12 @@ install_requires = PyGithub ~= 2.0 ruamel.yaml ~= 0.15 +[options.extras_require] +test = + mypy + pytest + pytest-cov + [options.packages.find] where = src diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index 37e550e..6bf0e52 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -250,7 +250,7 @@ def to_markdown(self) -> str: if user is None: user = i.user.login s += ( - f"- [{i.title}]({i.html_url}) by {user}" + f"- [{sanitize_md(i.title)}]({i.html_url}) by {user}" f" [{i.repository.full_name}]\n" ) @@ -437,6 +437,11 @@ def ensure_aware(dt: datetime) -> datetime: return dt.replace(tzinfo=timezone.utc) if dt.tzinfo is None else dt +def sanitize_md(s: str) -> str: + # Remove `[]` symbols to ensure correct markdown in the references + return re.sub(r'[\[\]]', '', s) + + @click.command() @click.option( "-c", diff --git a/src/solidation/tests/__init__.py b/src/solidation/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/solidation/tests/test_main.py b/src/solidation/tests/test_main.py new file mode 100644 index 0000000..59dd5cc --- /dev/null +++ b/src/solidation/tests/test_main.py @@ -0,0 +1,5 @@ +from ..__main__ import sanitize_md + + +def test_sanitize_md() -> None: + assert sanitize_md("[gh-actions](deps): Bump") == "gh-actions(deps): Bump" diff --git a/tox.ini b/tox.ini index 740b591..a49816e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,13 @@ [tox] -envlist = lint,typing +envlist = lint,typing,py3 isolated_build = True minversion = 3.3.0 +[testenv] +extras = test +commands = + python -m pytest -v {posargs} src + [testenv:lint] skip_install = True deps =