Skip to content

Commit

Permalink
Fix crash when no token is provided and there's no changelog url
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Mar 9, 2024
1 parent 331466d commit 5921df6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sphinx_github_changelog/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def compute_changelog(
token: Optional[str], options: Dict[str, str]
) -> List[nodes.Node]:
if not token:
return no_token(changelog_url=options["changelog-url"])
return no_token(changelog_url=options.get("changelog-url"))

owner_repo = extract_github_repo_name(url=options["github"])
releases = extract_releases(owner_repo=owner_repo, token=token)
Expand Down
16 changes: 4 additions & 12 deletions tests/unit/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ def extract_releases(mocker, release_dict):
)


@pytest.fixture
def options():
def _(kwargs):
return {"changelog-url": None, "github": None, "pypi": None, **kwargs}

return _


def node_to_string(node):
if isinstance(node, list):
return canonicalize(
Expand All @@ -49,16 +41,16 @@ def canonicalize(value):
)


def test_compute_changelog_no_token(options):
nodes = changelog.compute_changelog(token=None, options=options({}))
def test_compute_changelog_no_token():
nodes = changelog.compute_changelog(token=None, options={})
assert len(nodes) == 1

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


def test_compute_changelog_token(options, extract_releases):
def test_compute_changelog_token(extract_releases):
nodes = changelog.compute_changelog(
token="token", options=options({"github": "https://github.com/a/b/releases"})
token="token", options={"github": "https://github.com/a/b/releases"}
)
assert "1.0.0: A new hope" in node_to_string(nodes[0])

Expand Down

0 comments on commit 5921df6

Please sign in to comment.