Skip to content

Commit

Permalink
bug: fixed #39
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancheley committed Dec 12, 2021
1 parent e37e05e commit a99c891
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/the_well_maintained_test/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ def package(package: str, branch: str, progress: bool, output: str) -> None: #
name (str): The name of the Package from PyPi
"""
pypi_url = f"https://pypi.org/pypi/{package}/json"
project_urls = requests.get(pypi_url).json().get("info").get("project_urls")
for _, v in project_urls.items():
if urlparse(v).netloc == "github.com" and len(urlparse(v).path.split("/")) == 3:
url = v
url = _get_package_github_url(package)[1]

"url to a github repository you'd like to check"
if url[-1] == "/":
Expand Down
4 changes: 4 additions & 0 deletions src/the_well_maintained_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ def _get_package_github_url(package: str) -> tuple:
for k, v in project_urls.items():
if urlparse(v).netloc == "github.com" and len(urlparse(v).path.split("/")) == 3:
value = (package, v)
elif urlparse(v).netloc == "github.com" and len(urlparse(v).path.split("/")) == 4:
p = urlparse(v).path.split("/")[1]
a = urlparse(v).path.split("/")[2]
value = (package, f"https://www.github.com/{p}/{a}")
return value
15 changes: 15 additions & 0 deletions tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,18 @@ def json():
}
}
}


class MockResponseNonGitHubHomePage:
@staticmethod
def json():
return {
"info": {
"project_urls": {
"CI": "https://github.com/author/package/actions",
"Changelog": "https://github.com/author/package/releases",
"Homepage": "https://www.package.com",
"Issues": "https://github.com/author/package/issues",
}
}
}
13 changes: 13 additions & 0 deletions tests/test_the_well_maintained_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
MockResponseFrameworkCheck,
MockResponseGitHubRateLimit,
MockResponseLanguageCheck,
MockResponseNonGitHubHomePage,
MockResponseProductionReadyNo,
MockResponseProductionReadyYes,
MockResponseProjectURLs,
Expand All @@ -48,6 +49,7 @@
from the_well_maintained_test.cli import cli
from the_well_maintained_test.helpers import (
_check_verb_agreement,
_get_package_github_url,
_get_requirements_txt_file,
)
from the_well_maintained_test.utils import (
Expand Down Expand Up @@ -841,3 +843,14 @@ def mock_get(*args, **kwargs):
actual = get_vulnerabilities(url)
expected = 0
assert actual == expected


def test__get_package_github_url_non_github_homepage(monkeypatch):
def mock_get(*args, **kwargs):
return MockResponseNonGitHubHomePage()

monkeypatch.setattr(requests, "get", mock_get)
url = "https://fakeurl"
actual = _get_package_github_url(url)[1]
expected = "https://www.github.com/author/package"
assert actual == expected

0 comments on commit a99c891

Please sign in to comment.