Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize MD and initiate addition of tests #43

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unit Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: Unit Test
name: Test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it such since we also have Smoke Test. Makes it more explicit on what is the difference between the two.


on:
- push
- pull_request

jobs:
typing:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox

- name: Run tests
run: tox -e py3
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-json
Expand All @@ -10,17 +10,17 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,3 @@ keys (all optional):
- Proposed by: mih (6), jwodder (4), TheChymera (1), mslw (1), jsheunis (1)
- Merged by: mih (6), yarikoptic (4), bpoldrack (1), christian-monch (1), jsheunis (1)
- PR duration quantiles (days): [0.0, 0.0, 5.0]

4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ install_requires =
PyGithub ~= 2.0
ruamel.yaml ~= 0.15

[options.extras_require]
test =
pytest

[options.packages.find]
where = src

Expand Down
16 changes: 12 additions & 4 deletions src/solidation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
f" [{i.repository.full_name}]\n"
)

Expand All @@ -271,7 +271,10 @@ def to_markdown(self) -> str:
if untriaged_issues:
s += f"##### Untriaged issues of the last {dayscovered} days\n"
for i in sorted(untriaged_issues, key=lambda x: x.created_at):
s += f"- [{i.title}]({i.html_url}) [{i.repository.full_name}]\n"
s += (
f"- [{sanitize_md(i.title)}]({i.html_url}) "
+ f"[{i.repository.full_name}]\n"
)

s += (
f"##### Max {self.config.num_oldest_prs} oldest, open, non-draft"
Expand All @@ -281,7 +284,7 @@ def to_markdown(self) -> str:
(p for p in self.open_prs if not p.draft), key=lambda x: x.created_at
)[: self.config.num_oldest_prs]:
age = now - ensure_aware(pr.created_at)
s += f"- [{pr.title}]({pr.html_url}) ({age.days} days)\n"
s += f"- [{sanitize_md(pr.title)}]({pr.html_url}) ({age.days} days)\n"

n_random_ip = min(self.config.max_random_issues, len(self.open_ip))
if n_random_ip:
Expand All @@ -297,7 +300,7 @@ def to_markdown(self) -> str:
# issue, which slows things down considerably.
continue
age = now - ensure_aware(i.created_at) # type: ignore[unreachable]
s += f"- [{i.title}]({i.html_url}) ({age.days} days old)\n"
s += f"- [{sanitize_md(i.title)}]({i.html_url}) ({age.days} days old)\n"
n_random_ip -= 1
if n_random_ip == 0:
break
Expand Down Expand Up @@ -437,6 +440,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"([\\\[\]])", r"\\\1", s)


@click.command()
@click.option(
"-c",
Expand Down
7 changes: 7 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from solidation.__main__ import sanitize_md


def test_sanitize_md() -> None:
assert (
sanitize_md(r"[gh-actions](deps): Fix \n") == r"\[gh-actions\](deps): Fix \\n"
)
11 changes: 8 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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} tests

[testenv:lint]
skip_install = True
deps =
Expand All @@ -11,13 +16,13 @@ deps =
flake8-builtins
flake8-unused-arguments
commands =
flake8 src
flake8 src tests

[testenv:typing]
deps =
mypy
commands =
mypy src
mypy src tests

[flake8]
doctests = True
Expand Down