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

[BUILD-960] fix: Tag-to-slug conversion with number later in tag part #1064

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: flake8

- repo: https://github.com/hadialqattan/pycln
rev: v2.2.1
rev: v2.5.0
hooks:
- id: pycln

Expand Down
10 changes: 6 additions & 4 deletions ankihub/main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,15 @@ def mh_tag_to_resource_title_and_slug(tag: str) -> Optional[Tuple[str, str]]:
path_parts = path_parts[:-1]

path_parts = [part.lower() for part in path_parts]
content_numbers = [str(int(re.sub(r"\D", "", part))) for part in path_parts]
cleaned_path_parts = [re.sub(r"\d+_", "", part) for part in path_parts]
content_numbers = [
str(int(re.match(r"\d+", part).group(0))) for part in path_parts
]
slug = f"step{step}-{resource_slug_str}-{'-'.join(content_numbers)}"

title = cleaned_path_parts[-1].replace("_", " ")
title = re.sub(r"\d+_", "", path_parts[-1])
title = title.replace("_", " ")
title = " ".join([word.capitalize() for word in title.split()])
except (KeyError, AttributeError, IndexError):
except (KeyError, AttributeError, IndexError, ValueError):
# We want to ignore any tags that don't match the expected format
return None

Expand Down
12 changes: 12 additions & 0 deletions tests/addon/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3091,8 +3091,20 @@ def test_send_daily_review_summaries_without_data(mocker):
"Beta-blockers",
"step1-fa-5-2-15",
),
# With number later in tag part
(
"#AK_Step1_v12::#FirstAid::01_Biochem::03_Laboratory_Techniques::02_CRISPR/Cas9",
"Crispr/cas9",
"step1-fa-1-3-2",
),
# With invalid tag
("invalid_tag", None, None),
# With invalid tag (core tag part doesn't start with number)
(
"#AK_Step1_v12::#FirstAid::Biochem::03_Laboratory_Techniques::CRISPR/Cas9",
None,
None,
),
],
)
def test_mh_tag_to_resource_title_and_slug(
Expand Down
Loading