Skip to content

Commit

Permalink
Merge pull request #326 from tekktrik/dev/announce-commbund-updates
Browse files Browse the repository at this point in the history
Announce community bundle updates
  • Loading branch information
tekktrik committed Dec 12, 2022
2 parents 7333694 + 6ccf359 commit 43c5dc5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
14 changes: 14 additions & 0 deletions adabot/circuitpython_libraries.py
Expand Up @@ -23,6 +23,7 @@
from adabot.lib import common_funcs
from adabot.lib import assign_hacktober_label as hacktober
from adabot.lib import blinka_funcs
from adabot.lib import community_bundle_announcer
from adabot import circuitpython_library_download_stats as dl_stats

GH_INTERFACE = pygithub.Github(os.environ.get("ADABOT_GITHUB_ACCESS_TOKEN"))
Expand Down Expand Up @@ -342,6 +343,19 @@ def run_library_checks(validators, kw_args, error_depth):
for title, link in updated_libs.items():
logger.info(" * [%s](%s)", title, link)

(
new_community_libs,
updated_community_libs,
) = community_bundle_announcer.get_community_bundle_updates()
if len(new_community_libs) != 0:
logger.info("* **New Community Libraries**")
for title, link in new_community_libs:
logger.info(" * [%s](%s)", title, link)
if len(updated_community_libs) != 0:
logger.info("* **Updated Community Libraries**")
for title, link in updated_community_libs:
logger.info(" * [%s](%s)", title, link)

if len(validators) != 0:
lib_repos = []
for repo in repos:
Expand Down
88 changes: 88 additions & 0 deletions adabot/lib/community_bundle_announcer.py
@@ -0,0 +1,88 @@
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Checks for the latest releases in the Community bundle based
on the automated release.
* Author(s): Alec Delaney
"""

import datetime
import logging
import os
import time
from typing import Tuple, Set
from typing_extensions import TypeAlias

import github as pygithub
import parse

GH_INTERFACE = pygithub.Github(os.environ.get("ADABOT_GITHUB_ACCESS_TOKEN"))

RepoResult: TypeAlias = Tuple[str, str]
"""(Submodule Name, Full Repo Name)"""


def get_community_bundle_updates() -> Tuple[Set[RepoResult], Set[RepoResult]]:
"""
Get the updates to the Community Bundle.
Returns new and updated libraries
"""
while True:
try:
repository = GH_INTERFACE.get_repo(
"adafruit/CircuitPython_Community_Bundle"
)
seven_days_ago = datetime.datetime.now() - datetime.timedelta(days=7)
recent_releases = [
release
for release in repository.get_releases()
if release.created_at > seven_days_ago
]
new_libs = set()
updated_libs = set()
for recent_release in recent_releases:
relevant_lines = [
line
for line in recent_release.body.split("\n")
if line.startswith("Updated libraries")
or line.startswith("New libraries:")
]
for relevant_line in relevant_lines:
lib_components = [
x.strip(",") for x in relevant_line.split(" ")[2:]
]
for lib in lib_components:
comps = parse.parse("[{name:S}]({link_comp:S})", lib)
link: str = parse.search(
"{link:S}/releases", comps["link_comp"]
)["link"]
full_name = parse.search(
"https://github.com/{full_name:S}", link
)["full_name"]
if relevant_line.startswith("Updated libraries"):
updated_libs.add((full_name, link))
else:
new_libs.add((full_name, link))
return (new_libs, updated_libs)

except pygithub.RateLimitExceededException:
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
sleep_time = core_rate_limit_reset - datetime.datetime.now()
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
time.sleep(sleep_time.seconds)
continue
except pygithub.GithubException:
# Secrets may not be available or error occurred - just skip
return (set(), set())


if __name__ == "__main__":
results = get_community_bundle_updates()
for new_lib in results[0]:
print(f"New libraries: {new_lib[0]} { {new_lib[1]} }")
for updated_lib in results[1]:
print(f"New libraries: {updated_lib[0]} { {updated_lib[1]} }")

0 comments on commit 43c5dc5

Please sign in to comment.