Skip to content

Commit 43c5dc5

Browse files
authored
Merge pull request #326 from tekktrik/dev/announce-commbund-updates
Announce community bundle updates
2 parents 7333694 + 6ccf359 commit 43c5dc5

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

adabot/circuitpython_libraries.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from adabot.lib import common_funcs
2424
from adabot.lib import assign_hacktober_label as hacktober
2525
from adabot.lib import blinka_funcs
26+
from adabot.lib import community_bundle_announcer
2627
from adabot import circuitpython_library_download_stats as dl_stats
2728

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

346+
(
347+
new_community_libs,
348+
updated_community_libs,
349+
) = community_bundle_announcer.get_community_bundle_updates()
350+
if len(new_community_libs) != 0:
351+
logger.info("* **New Community Libraries**")
352+
for title, link in new_community_libs:
353+
logger.info(" * [%s](%s)", title, link)
354+
if len(updated_community_libs) != 0:
355+
logger.info("* **Updated Community Libraries**")
356+
for title, link in updated_community_libs:
357+
logger.info(" * [%s](%s)", title, link)
358+
345359
if len(validators) != 0:
346360
lib_repos = []
347361
for repo in repos:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Checks for the latest releases in the Community bundle based
7+
on the automated release.
8+
9+
* Author(s): Alec Delaney
10+
"""
11+
12+
import datetime
13+
import logging
14+
import os
15+
import time
16+
from typing import Tuple, Set
17+
from typing_extensions import TypeAlias
18+
19+
import github as pygithub
20+
import parse
21+
22+
GH_INTERFACE = pygithub.Github(os.environ.get("ADABOT_GITHUB_ACCESS_TOKEN"))
23+
24+
RepoResult: TypeAlias = Tuple[str, str]
25+
"""(Submodule Name, Full Repo Name)"""
26+
27+
28+
def get_community_bundle_updates() -> Tuple[Set[RepoResult], Set[RepoResult]]:
29+
"""
30+
Get the updates to the Community Bundle.
31+
32+
Returns new and updated libraries
33+
"""
34+
while True:
35+
try:
36+
repository = GH_INTERFACE.get_repo(
37+
"adafruit/CircuitPython_Community_Bundle"
38+
)
39+
seven_days_ago = datetime.datetime.now() - datetime.timedelta(days=7)
40+
recent_releases = [
41+
release
42+
for release in repository.get_releases()
43+
if release.created_at > seven_days_ago
44+
]
45+
new_libs = set()
46+
updated_libs = set()
47+
for recent_release in recent_releases:
48+
relevant_lines = [
49+
line
50+
for line in recent_release.body.split("\n")
51+
if line.startswith("Updated libraries")
52+
or line.startswith("New libraries:")
53+
]
54+
for relevant_line in relevant_lines:
55+
lib_components = [
56+
x.strip(",") for x in relevant_line.split(" ")[2:]
57+
]
58+
for lib in lib_components:
59+
comps = parse.parse("[{name:S}]({link_comp:S})", lib)
60+
link: str = parse.search(
61+
"{link:S}/releases", comps["link_comp"]
62+
)["link"]
63+
full_name = parse.search(
64+
"https://github.com/{full_name:S}", link
65+
)["full_name"]
66+
if relevant_line.startswith("Updated libraries"):
67+
updated_libs.add((full_name, link))
68+
else:
69+
new_libs.add((full_name, link))
70+
return (new_libs, updated_libs)
71+
72+
except pygithub.RateLimitExceededException:
73+
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
74+
sleep_time = core_rate_limit_reset - datetime.datetime.now()
75+
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
76+
time.sleep(sleep_time.seconds)
77+
continue
78+
except pygithub.GithubException:
79+
# Secrets may not be available or error occurred - just skip
80+
return (set(), set())
81+
82+
83+
if __name__ == "__main__":
84+
results = get_community_bundle_updates()
85+
for new_lib in results[0]:
86+
print(f"New libraries: {new_lib[0]} { {new_lib[1]} }")
87+
for updated_lib in results[1]:
88+
print(f"New libraries: {updated_lib[0]} { {updated_lib[1]} }")

0 commit comments

Comments
 (0)