Skip to content

Commit

Permalink
Add version checking fix, tweak lists, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Sep 26, 2023
1 parent 8a8115b commit 82e448c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 22 deletions.
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

0 comments on commit 82e448c

Please sign in to comment.