Skip to content

Commit

Permalink
Merge pull request #46 from ryancheley/v0.10.1
Browse files Browse the repository at this point in the history
V0.10.1
  • Loading branch information
ryancheley authored Dec 19, 2021
2 parents c963b34 + 929e1b9 commit 3084a09
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 86 deletions.
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.10.0"
VERSION = "0.10.1"


def get_long_description():
Expand Down
181 changes: 96 additions & 85 deletions src/the_well_maintained_test/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from . import utils
from .console import console
from .headers import headers
from .helpers import SORRY_MESSAGE
from .styles import (
answer_link_style,
answer_padding_style,
Expand Down Expand Up @@ -100,34 +101,40 @@ def questions(name: str, question: str) -> None: # pragma: no cover
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)
)
question_link_verbiage = f'See {questions.get("question").get(question).get("question_link")} for the original source.'
console.print(question_link_verbiage, style=answer_link_style)
if name:
question_function = (
f"[bold green]function_name[/bold green]: {questions.get('question').get(question).get('question_function')}"
try:
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
)
)
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))

question_link_verbiage = (
f'See {questions.get("question").get(question).get("question_link")} for the original source.'
)
console.print(question_link_verbiage, style=answer_link_style)
if name:
question_function = (
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))
except (AttributeError, TypeError):
console.print(SORRY_MESSAGE)
else:
for _, v in questions.get("question").items():
console.print(v.get("question_text"), style=question_style)
Expand Down Expand Up @@ -209,76 +216,80 @@ def package(package: str, branch: str, progress: bool, output: str) -> None: #
Args:\n
name (str): The name of the Package from PyPi
"""
pypi_url = f"https://pypi.org/pypi/{package}/json"
url = _get_package_github_url(package)[1]

"url to a github repository you'd like to check"
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"
tree_url = f"https://api.github.com/repos/{author}/{package}/git/trees/{default_branch}?recursive=1"
try:
pypi_url = f"https://pypi.org/pypi/{package}/json"
url = _get_package_github_url(package)[1]

"url to a github repository you'd like to check"
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"
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()

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.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("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("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("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("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("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("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("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("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("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("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("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))

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 == "html":
console.save_html("output.html")
if output == "txt":
console.save_text("output.txt")

if output == "txt":
console.save_text("output.txt")
except (AttributeError, TypeError):
console.print(SORRY_MESSAGE)
Empty file.
8 changes: 8 additions & 0 deletions src/the_well_maintained_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

import requests

SORRY_MESSAGE = """
This package does not have project_urls defined. You may want to contact them or raise an issue with them to include it.
Documentation for project_urls can be found here:
https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#project-urls
"""


def _get_bug_comment_list(url: str, headers: dict) -> list:
BugComments = namedtuple("BugComments", ["text", "create_date"])
Expand Down

0 comments on commit 3084a09

Please sign in to comment.