Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version checking fix, tweak lists #357

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Debian/Ubuntu Dependencies

sudo apt-get update # make sure you have the latest packages
sudo apt-get upgrade # make sure already installed packages are latest
sudo apt-get install git python3 python3-venv python3-pip screen
sudo apt-get install git python3 python3-venv python3-pip screen celery

Adabot
++++++++++
Expand Down
99 changes: 78 additions & 21 deletions adabot/arduino_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import sys
import traceback

import semver
import requests

from adabot import github_requests as gh_reqs
Expand Down Expand Up @@ -125,23 +125,22 @@ def validate_library_properties(repo):
lines = lib_prop_file.text.split("\n")
for line in lines:
if "version" in line:
lib_version = line[len("version=") :]
lib_version = str(line[len("version=") :]).strip()
break

get_latest_release = gh_reqs.get(
"/repos/adafruit/" + repo["name"] + "/releases/latest"
)
release_tag = "None"
if get_latest_release.ok:
response = get_latest_release.json()
if "tag_name" in response:
release_tag = response["tag_name"]
if "message" in response:
if response["message"] == "Not Found":
release_tag = "None"
else:
if response["message"] != "Not Found":
release_tag = "Unknown"

if lib_version and release_tag:
if lib_version:
return [release_tag, lib_version]

return None
Expand Down Expand Up @@ -205,6 +204,7 @@ def validate_example(repo):


# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
def run_arduino_lib_checks():
"""Run necessary functions and outout the results."""
logger.info("Running Arduino Library Checks")
Expand All @@ -217,38 +217,81 @@ def run_arduino_lib_checks():
[" ----", "-----------", "--------------------------"],
]
needs_release_list = [
[" Repo", "Latest Release", "Commits Behind"],
[" ----", "--------------", "--------------"],
[" Repo", "Latest Release", "Commits Behind", "Comparison"],
[" ----", "--------------", "--------------", "----------"],
]
needs_registration_list = [
[" Repo", "Latest Changes"],
[" ----", "--------------"],
]
needs_registration_list = [[" Repo"], [" ----"]]
missing_actions_list = [[" Repo"], [" ----"]]
missing_library_properties_list = [[" Repo"], [" ----"]]
missing_library_properties_list = [
[" Repo", "Latest Changes"],
[" ----", "--------------"],
]

no_examples = [
[" Repo", "Latest Changes"],
[" ----", "--------------"],
]

for repo in repo_list:
have_examples = validate_example(repo)
if not have_examples:
# not a library
# not a library, probably worth rechecking that it's got no library.properties file
no_examples.append(
[" " + str(repo["name"] or repo["clone_url"]), repo["updated_at"]]
)
continue

entry = {"name": repo["name"]}

lib_check = validate_library_properties(repo)
if not lib_check:
missing_library_properties_list.append([" " + str(repo["name"])])
missing_library_properties_list.append(
[" " + str(repo["name"]), repo["updated_at"]]
)
continue

if lib_check[0] in ("None", "Unknown"):
compare_url = (
str(repo["html_url"]) + "/compare/" + repo["default_branch"] + "...HEAD"
)
needs_release_list.append(
[" " + str(repo["name"]), "*None*", repo["updated_at"], compare_url]
)
continue

if lib_check[0] != lib_check[1]:
failed_lib_prop.append(
[
" " + str((repo["name"] or repo["clone_url"])),
lib_check[0],
lib_check[1],
]
)
continue

# print(repo['clone_url'])
needs_registration = False
for lib in adafruit_library_index:
if (repo["clone_url"] == lib["repository"]) or (
repo["html_url"] == lib["website"]
):
entry["arduino_version"] = lib["version"] # found it!
break
else:
needs_registration = True
if needs_registration:
needs_registration_list.append([" " + str(repo["name"])])
if ( # pylint: disable=too-many-boolean-expressions
"arduino_version" not in entry
or not entry["arduino_version"]
or (
entry["arduino_version"]
and semver.parse(entry["arduino_version"])
and semver.parse(lib["version"])
and semver.compare(entry["arduino_version"], lib["version"]) < 0
)
):
entry["arduino_version"] = lib["version"]

if "arduino_version" not in entry or not entry["arduino_version"]:
needs_registration_list.append(
[" " + str(repo["name"]), repo["updated_at"]]
)

entry["release"] = lib_check[0]
entry["version"] = lib_check[1]
Expand All @@ -257,8 +300,16 @@ def run_arduino_lib_checks():
needs_release = validate_release_state(repo)
entry["needs_release"] = needs_release
if needs_release:
compare_url = (
str(repo["html_url"]) + "/compare/" + needs_release[0] + "...HEAD"
)
needs_release_list.append(
[" " + str(repo["name"]), needs_release[0], needs_release[1]]
[
" " + str(repo["name"]),
needs_release[0],
needs_release[1],
compare_url,
]
)

missing_actions = not validate_actions(repo)
Expand All @@ -271,6 +322,12 @@ def run_arduino_lib_checks():
for entry in all_libraries:
logging.info(entry)

if len(no_examples) > 2:
print_list_output(
"Repos with no examples (considered non-libraries): ({})",
no_examples,
)

if len(failed_lib_prop) > 2:
print_list_output(
"Libraries Have Mismatched Release Tag and library.properties Version: ({})",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ PyGithub==1.57
typing-extensions~=4.0
google-auth~=2.13
google-cloud-bigquery~=3.3
semver