Skip to content

Commit

Permalink
Merge pull request #44 from ryancheley/v0.10
Browse files Browse the repository at this point in the history
V0.10.0
  • Loading branch information
ryancheley authored Dec 12, 2021
2 parents 96d2173 + b9feb1d commit c963b34
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 168 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ Usage: the-well-maintained-test [OPTIONS] COMMAND [ARGS]...
the-well-maintained-test package the-well-maintained-test
URL is a url to a github repository you'd like to check, for example:
the-well-maintained-test url 'https://github.com/ryancheley/the-well-
maintained-test'
Note: URL was deprecated and replaced with package starting in v0.9.0
Options:
--version Show the version and exit.
--help Show this message and exit.
Expand All @@ -69,7 +62,6 @@ Commands:
package Name of a package on PyPi you'd like to check
questions List of questions tested
requirements Loop over a requirements.txt file
url URL to a github repository you'd like to check.
```
<!-- [[[end]]] -->
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

VERSION = "0.9.0"
VERSION = "0.10.0"


def get_long_description():
Expand Down
129 changes: 1 addition & 128 deletions src/the_well_maintained_test/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from os import system
from pathlib import Path
from urllib.parse import urlparse
Expand Down Expand Up @@ -55,12 +54,6 @@ def cli(): # pragma: no cover
the-well-maintained-test package the-well-maintained-test
URL is a url to a github repository you'd like to check, for example:
the-well-maintained-test url 'https://github.com/ryancheley/the-well-maintained-test'
Note: URL was deprecated and replaced with package starting in v0.9.0
"""
pass

Expand All @@ -83,123 +76,6 @@ def auth(auth: str) -> None: # pragma: no cover
save_auth(auth)


@cli.command()
@click.option(
"-u",
"--url",
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
help="GitHub URL to use",
)
@click.option(
"-b",
"--branch",
type=click.STRING,
help="Branch to check",
)
@click.option(
"-p",
"--progress",
type=click.BOOL,
default=True,
help="Show progress on test check",
)
@click.option(
"-o",
"--output",
type=click.Choice(["html", "txt"]),
help="Show progress on test check",
)
def url(url: str, branch: str, progress: bool, output: str) -> None: # pragma: no cover
"URL to a github repository you'd like to check. This method will be deprecated in v0.9.0"
if url[-1] == "/":
url = url.strip("/")

with open(Path(pkg_resources.resource_filename(__name__, str(Path("data").joinpath("questions.toml"))))) as file:
questions = toml.load(file)

parse_object = urlparse(url)
author = parse_object.path.split("/")[-2]
package = parse_object.path.split("/")[-1]
api_url = f"https://api.github.com/repos/{author}/{package}"
if not branch:
default_branch = requests.get(api_url).json().get("default_branch")
else:
default_branch = branch
commits_url = f"https://api.github.com/repos/{author}/{package}/commits/{default_branch}"
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"
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"

vulnerabilities = get_vulnerabilities(pypi_url)
if vulnerabilities > 0:
console.rule("[bold red]Vulnerabilities detected!!!")
console.print(
Padding(f"There are {vulnerabilities} vulnerabilities in this package", answer_padding_style, style=warning_style)
)
console.rule()

console.rule()

console.print(
Padding(
"""
This method has been deprecated in v0.9.0.
It is now an optional.
Please use --name instead.
""",
answer_padding_style,
style=warning_style,
)
)

console.rule()
time.sleep(3)

console.print(questions.get("question").get("1").get("question_text"), style=question_style)
console.print(Padding(production_ready_check(pypi_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("2").get("question_text"), style=question_style)
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(pypi_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))

console.print(questions.get("question").get("5").get("question_text"), style=question_style)
console.print(Padding(check_tests(tree_url, headers, progress), special_answer_padding_style, style=answer_style))

console.print(questions.get("question").get("6").get("question_text"), style=question_style)
console.print(Padding(language_check(pypi_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("7").get("question_text"), style=question_style)
console.print(Padding(framework_check(pypi_url), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("8").get("question_text"), style=question_style)
console.print(Padding(ci_setup(workflows_url, headers), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("9").get("question_text"), style=question_style)
console.print(Padding(ci_passing(ci_status_url, headers), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("10").get("question_text"), style=question_style)
console.print(Padding(well_used(api_url, headers), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("11").get("question_text"), style=question_style)
console.print(Padding(commit_in_last_year(commits_url, headers), answer_padding_style, style=answer_style))

console.print(questions.get("question").get("12").get("question_text"), style=question_style)
console.print(Padding(release_in_last_year(pypi_url), answer_padding_style, style=answer_style))

if output == "html":
console.save_html("output.html")

if output == "txt":
console.save_text("output.txt")


@cli.command()
@click.option(
"-n",
Expand Down Expand Up @@ -334,10 +210,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
23 changes: 10 additions & 13 deletions src/the_well_maintained_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
def _get_bug_comment_list(url: str, headers: dict) -> list:
BugComments = namedtuple("BugComments", ["text", "create_date"])
bug_comment_list = []
timeline = requests.get(url, headers=headers).json()[-1]
if timeline.get("event") == "commented":
bug_comment = timeline.get("body")
bug_comment_date = datetime.strptime(timeline.get("created_at"), "%Y-%m-%dT%H:%M:%SZ")
bug_comment_list.append(BugComments(bug_comment, bug_comment_date))
timeline = requests.get(url, headers=headers).json()
for t in timeline:
if t.get("event") == "commented":
bug_comment = t.get("body")
bug_comment_date = datetime.strptime(t.get("created_at"), "%Y-%m-%dT%H:%M:%SZ")
bug_comment_list.append(BugComments(bug_comment, bug_comment_date))
return bug_comment_list


Expand Down Expand Up @@ -59,14 +60,6 @@ def _get_release_date(release: dict) -> List:
return releases


def _check_verb_agreement(count: int) -> str:
if count == 1:
verb = "is"
else:
verb = "are"
return verb


def _get_requirements_txt_file(requirements_file: Path) -> List:
with open(requirements_file) as f:
requirements = f.readlines()
Expand All @@ -84,4 +77,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
8 changes: 4 additions & 4 deletions src/the_well_maintained_test/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import re
from datetime import datetime
from gettext import ngettext
from operator import attrgetter
from pathlib import Path
from time import localtime, strftime
Expand All @@ -11,7 +12,6 @@

from the_well_maintained_test.console import console
from the_well_maintained_test.helpers import (
_check_verb_agreement,
_get_bug_comment_list,
_get_content,
_get_release_date,
Expand Down Expand Up @@ -81,7 +81,7 @@ def bug_responding(bugs_url: str, headers: dict) -> str:
message2 = f"It has been {days_since_last_bug_comment} days since a comment was made on the bug."
message = f"[green]{message1}\n{message2}"
else:
verb = _check_verb_agreement(open_bug_count)
verb = ngettext("is", "are", open_bug_count)
message = f"[red]There {verb} {open_bug_count} bugs with no comments"
return message

Expand All @@ -106,7 +106,7 @@ def check_tests(tree_url: str, headers: dict, show_progress: bool = True) -> str
if test_files == 0:
message = "[red]There are 0 tests!"
else:
verb = _check_verb_agreement(test_functions)
verb = ngettext("is", "are", test_functions)
message = f"[green]There {verb} {test_functions} tests in {test_files} files:\n"
for test in test_list:
message += f"- {test.get('path')}\n"
Expand Down Expand Up @@ -149,7 +149,7 @@ def ci_setup(workflows_url: str, headers: dict) -> str:
r = requests.get(workflows_url, headers=headers).json()
if r.get("total_count") > 0:
workflow_count = r.get("total_count")
verb = _check_verb_agreement(workflow_count)
verb = ngettext("is", "are", workflow_count)
message = f"[green]There {verb} {workflow_count} workflows\n"
for i in r.get("workflows"):
message += f"[green]- {i.get('name')}\n"
Expand Down
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",
}
}
}
27 changes: 13 additions & 14 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 @@ -47,7 +48,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 @@ -775,19 +776,6 @@ def test__get_release_date_missing():
assert actual == expected


@pytest.mark.parametrize(
"test_input,expected",
[
[0, "are"],
[1, "is"],
[2, "are"],
[-1, "are"],
],
)
def test__check_verb_agreement(test_input, expected):
assert _check_verb_agreement(test_input) == expected


def test__get_requirements_txt_file(tmpdir, monkeypatch):
def mock_get(*args, **kwargs):
return MockResponseProjectURLs()
Expand Down Expand Up @@ -841,3 +829,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 c963b34

Please sign in to comment.