Skip to content
Open
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
13 changes: 11 additions & 2 deletions src/readme2demo/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@ def _verified_line(verified: bool, base_image: str, commit_sha: str | None) -> s


def _repo_name(repo_url: str) -> str:
"""`https://github.com/owner/repo` → `owner/repo` (best effort)."""
parts = repo_url.rstrip("/").removesuffix(".git").split("/")
"""`https://github.com/owner/repo` → `owner/repo` (best effort).

Git also accepts scp-style URLs such as
``git@github.com:owner/repo.git``. Normalize the host/path separator
before extracting the final owner/repository pair so those URLs produce
the same name as their HTTPS equivalents.
"""
value = repo_url.rstrip("/").removesuffix(".git")
if "://" not in value and ":" in value:
value = value.rsplit(":", 1)[-1]
parts = value.split("/")
return "/".join(parts[-2:]) if len(parts) >= 2 else repo_url


Expand Down
15 changes: 15 additions & 0 deletions tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,21 @@ def test_seo_title_and_description():
assert len(seo_description("x" * 400)) <= 160


@pytest.mark.parametrize(
("repo_url", "expected"),
[
("https://github.com/owner/repo", "owner/repo"),
("https://github.com/owner/repo.git", "owner/repo"),
("https://github.com/owner/repo/", "owner/repo"),
("git@github.com:owner/repo.git", "owner/repo"),
],
)
def test_repo_name_normalizes_git_url_forms(repo_url, expected):
from readme2demo.tutorial import _repo_name

assert _repo_name(repo_url) == expected


def test_tutorial_md_front_matter_and_provenance(tmp_path, monkeypatch):
import json as _json

Expand Down