Skip to content

Commit 159c0bb

Browse files
authored
Merge pull request #124 from ewjoachim/fixes
2 parents b89acad + 4927fef commit 159c0bb

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

.readthedocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build:
1313
tools:
1414
python: "3.10"
1515
jobs:
16+
post_create_environment:
17+
- pip install poetry
1618
post_install:
17-
- pip install -U poetry
18-
- poetry config virtualenvs.create false
19-
- poetry install --with docs
19+
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs

sphinx_github_changelog/changelog.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def compute_changelog(
4141
token: Optional[str], options: Dict[str, str]
4242
) -> List[nodes.Node]:
4343
if not token:
44-
return no_token(changelog_url=options["changelog-url"])
44+
return no_token(changelog_url=options.get("changelog-url"))
4545

4646
owner_repo = extract_github_repo_name(url=options["github"])
4747
releases = extract_releases(owner_repo=owner_repo, token=token)
@@ -60,7 +60,7 @@ def no_token(changelog_url: Optional[str]) -> List[nodes.Node]:
6060
par += nodes.Text("Changelog was not built because ")
6161
par += nodes.literal("", "sphinx_github_changelog_token")
6262
par += nodes.Text(" parameter is missing in the documentation configuration.")
63-
result = [nodes.warning("", par)]
63+
result: List[nodes.Node] = [nodes.warning("", par)]
6464

6565
if changelog_url:
6666
par2 = nodes.paragraph()
@@ -100,6 +100,12 @@ def extract_pypi_package_name(url: Optional[str]) -> Optional[str]:
100100
return stripped_url[len(prefix) :] # noqa
101101

102102

103+
def get_release_title(title: Optional[str], tag: str):
104+
if not title:
105+
return tag
106+
return title if tag in title else f"{tag}: {title}"
107+
108+
103109
def node_for_release(
104110
release: Dict[str, Any], pypi_name: Optional[str] = None
105111
) -> Optional[nodes.Node]:
@@ -109,7 +115,7 @@ def node_for_release(
109115
tag = release["tagName"]
110116
title = release["name"]
111117
date = release["publishedAt"][:10]
112-
title = title if tag in title else f"{tag}: {title}"
118+
title = get_release_title(title=title, tag=tag)
113119

114120
# Section
115121
id_section = nodes.make_id("release-" + tag)

tests/unit/test_changelog.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ def extract_releases(mocker, release_dict):
1515
)
1616

1717

18-
@pytest.fixture
19-
def options():
20-
def _(kwargs):
21-
return {"changelog-url": None, "github": None, "pypi": None, **kwargs}
22-
23-
return _
24-
25-
2618
def node_to_string(node):
2719
if isinstance(node, list):
2820
return canonicalize(
@@ -49,16 +41,16 @@ def canonicalize(value):
4941
)
5042

5143

52-
def test_compute_changelog_no_token(options):
53-
nodes = changelog.compute_changelog(token=None, options=options({}))
44+
def test_compute_changelog_no_token():
45+
nodes = changelog.compute_changelog(token=None, options={})
5446
assert len(nodes) == 1
5547

5648
assert "Changelog was not built" in node_to_string(nodes[0])
5749

5850

59-
def test_compute_changelog_token(options, extract_releases):
51+
def test_compute_changelog_token(extract_releases):
6052
nodes = changelog.compute_changelog(
61-
token="token", options=options({"github": "https://github.com/a/b/releases"})
53+
token="token", options={"github": "https://github.com/a/b/releases"}
6254
)
6355
assert "1.0.0: A new hope" in node_to_string(nodes[0])
6456

@@ -156,6 +148,13 @@ def test_node_for_release_title_tag(release_dict):
156148
)
157149

158150

151+
def test_node_for_release_none_title(release_dict):
152+
release_dict["name"] = None
153+
assert "<title>1.0.0</title>" in node_to_string(
154+
changelog.node_for_release(release=release_dict, pypi_name=None)
155+
)
156+
157+
159158
def test_node_for_release_title_pypy(release_dict):
160159
value = node_to_string(
161160
changelog.node_for_release(release=release_dict, pypi_name="foo")
@@ -239,3 +238,16 @@ def test_github_call_http_error_connection(requests_mock):
239238
changelog.github_call(url=url, token="token", query="")
240239

241240
assert str(exc_info.value) == "Could not retrieve changelog from github: bar"
241+
242+
243+
@pytest.mark.parametrize(
244+
"title, tag, expected",
245+
[
246+
("Foo", "1.0.0", "1.0.0: Foo"),
247+
("1.0.0: Foo", "1.0.0", "1.0.0: Foo"),
248+
("Fix 1.0.0", "1.0.1", "1.0.1: Fix 1.0.0"),
249+
(None, "1.0.0", "1.0.0"),
250+
],
251+
)
252+
def test_get_release_title(title, tag, expected):
253+
assert changelog.get_release_title(title=title, tag=tag) == expected

0 commit comments

Comments
 (0)