Skip to content

Commit

Permalink
Fix crash when release title is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Mar 9, 2024
1 parent b89acad commit 331466d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sphinx_github_changelog/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def extract_pypi_package_name(url: Optional[str]) -> Optional[str]:

return stripped_url[len(prefix) :] # noqa

def get_release_title(title: Optional[str], tag: str):
if not title:
return tag
return title if tag in title else f"{tag}: {title}"

def node_for_release(
release: Dict[str, Any], pypi_name: Optional[str] = None
Expand All @@ -109,7 +113,7 @@ def node_for_release(
tag = release["tagName"]
title = release["name"]
date = release["publishedAt"][:10]
title = title if tag in title else f"{tag}: {title}"
title = get_release_title(title=title, tag=tag)

# Section
id_section = nodes.make_id("release-" + tag)
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def test_node_for_release_title_tag(release_dict):
changelog.node_for_release(release=release_dict, pypi_name=None)
)

def test_node_for_release_none_title(release_dict):

release_dict["name"] = None
assert "<title>1.0.0</title>" in node_to_string(
changelog.node_for_release(release=release_dict, pypi_name=None)
)


def test_node_for_release_title_pypy(release_dict):
value = node_to_string(
Expand Down Expand Up @@ -239,3 +246,15 @@ def test_github_call_http_error_connection(requests_mock):
changelog.github_call(url=url, token="token", query="")

assert str(exc_info.value) == "Could not retrieve changelog from github: bar"

@pytest.mark.parametrize(
"title, tag, expected",
[
("Foo", "1.0.0", "1.0.0: Foo"),
("1.0.0: Foo", "1.0.0", "1.0.0: Foo"),
("Fix 1.0.0", "1.0.1", "1.0.1: Fix 1.0.0"),
(None, "1.0.0", "1.0.0"),
],
)
def test_get_release_title(title, tag, expected):
assert changelog.get_release_title(title=title, tag=tag) == expected

0 comments on commit 331466d

Please sign in to comment.