Skip to content

Commit 695f1dc

Browse files
authored
Merge pull request #94 from sommersoft/lib_report_new_updated
Add List of New & Updated Libraries To Library Report
2 parents c75c29b + ef5aeef commit 695f1dc

File tree

3 files changed

+75
-55
lines changed

3 files changed

+75
-55
lines changed

adabot/circuitpython_libraries.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from adabot import travis_requests as travis
3535
from adabot import pypi_requests as pypi
3636
from adabot.lib import circuitpython_library_validators as cirpy_lib_vals
37-
from adabot.lib.common_funcs import *
37+
from adabot.lib import common_funcs
3838

3939
# Setup ArgumentParser
4040
cmd_line_parser = argparse.ArgumentParser(
@@ -107,9 +107,9 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
107107
latest_pylint = pylint_info.json()["info"]["version"]
108108
output_handler("Latest pylint is: {}".format(latest_pylint))
109109

110-
repos = list_repos()
110+
repos = common_funcs.list_repos()
111111
output_handler("Found {} repos to check.".format(len(repos)))
112-
bundle_submodules = get_bundle_submodules()
112+
bundle_submodules = common_funcs.get_bundle_submodules()
113113
output_handler("Found {} submodules in the bundle.".format(len(bundle_submodules)))
114114
github_user = github.get("/user").json()
115115
output_handler("Running GitHub checks as " + github_user["login"])
@@ -142,6 +142,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
142142
repo_needs_work = []
143143
since = datetime.datetime.now() - datetime.timedelta(days=7)
144144
repos_by_error = {}
145+
new_libs = {}
146+
updated_libs = {}
145147

146148
validator = cirpy_lib_vals.library_validator(validators,
147149
bundle_submodules,
@@ -183,6 +185,14 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
183185
output_handler(", ".join(validator.output_file_data))
184186
validator.output_file_data.clear()
185187

188+
# get a list of new & updated libraries for the last week
189+
if repo["name"] != "Adafruit_CircuitPython_Bundle":
190+
check_releases = common_funcs.is_new_or_updated(repo)
191+
if check_releases == "new":
192+
new_libs[repo["name"]] = repo["html_url"]
193+
elif check_releases == "updated":
194+
updated_libs[repo["name"]] = repo["html_url"]
195+
186196
output_handler()
187197
output_handler("State of CircuitPython + Libraries")
188198

@@ -218,6 +228,15 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
218228
print_issue_overview(lib_insights)
219229
output_handler("* {} open issues".format(len(lib_insights["open_issues"])))
220230
output_handler(" * https://circuitpython.org/libraries/contributing")
231+
output_handler("Library updates in the last seven days:")
232+
if len(new_libs) != 0:
233+
output_handler("**New Libraries**")
234+
for new in new_libs:
235+
output_handler(" * [{}]({})".format(new, new_libs[new]))
236+
if len(updated_libs) != 0:
237+
output_handler("**Updated Libraries**")
238+
for updated in updated_libs:
239+
output_handler(" * [{}]({})".format(updated, updated_libs[updated]))
221240

222241
if len(validators) != 0:
223242
lib_repos = []
@@ -408,22 +427,22 @@ def print_issue_overview(*insights):
408427
]
409428
cmd_line_args = cmd_line_parser.parse_args()
410429

411-
error_depth = cmd_line_args.error_depth
412-
startup_message.append(" - Depth for listing libraries with errors: {}".format(error_depth))
413-
414430
verbosity = cmd_line_args.verbose
415431

416-
github_token = cmd_line_args.gh_token
417-
validator_kwarg_list["github_token"] = github_token
418-
startup_message.append(" - Prompts for the GitHub Token are {}.".format(("enabled" if github_token else "disabled")))
419-
420432
if cmd_line_args.output_file:
421433
output_filename = cmd_line_args.output_file
422434
startup_message.append(" - Report output will be saved to: {}".format(output_filename))
423435

424436
validators = []
425437
validator_names = []
426438
if cmd_line_args.validator:
439+
error_depth = cmd_line_args.error_depth
440+
startup_message.append(" - Depth for listing libraries with errors: {}".format(error_depth))
441+
442+
github_token = cmd_line_args.gh_token
443+
validator_kwarg_list["github_token"] = github_token
444+
startup_message.append(" - Prompts for the GitHub Token are {}.".format(("enabled" if github_token else "disabled")))
445+
427446
if cmd_line_args.validator != "all":
428447
validators = []
429448
for func in cmd_line_args.validator.split(","):

adabot/lib/common_funcs.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# GitHub API Serch has stopped returning the core repo for some reason. Tried several
2424
# different search params, and came up emtpy. Hardcoding it as a failsafe.
2525

26+
import datetime
2627
import re
2728
import requests
2829
from adabot import github_requests as github
@@ -200,3 +201,47 @@ def repo_is_on_pypi(repo):
200201
is_on = True
201202

202203
return is_on
204+
205+
def is_new_or_updated(repo):
206+
""" Check the repo for new release(s) within the last week. Then determine
207+
if all releases are within the last week to decide if this is a newly
208+
released library, or an updated library.
209+
"""
210+
211+
today_minus_seven = datetime.datetime.today() - datetime.timedelta(days=7)
212+
213+
# first, check the latest release to see if within the last 7 days
214+
result = github.get("/repos/adafruit/" + repo["name"] + "/releases/latest")
215+
if not result.ok:
216+
return
217+
release_info = result.json()
218+
if "published_at" not in release_info:
219+
return
220+
else:
221+
release_date = datetime.datetime.strptime(
222+
release_info["published_at"],
223+
"%Y-%m-%dT%H:%M:%SZ"
224+
)
225+
if release_date < today_minus_seven:
226+
return
227+
228+
# we have a release within the last 7 days. now check if its a newly
229+
# released library within the last week, or if its just an update
230+
result = github.get("/repos/adafruit/" + repo["name"] + "/releases")
231+
if not result.ok:
232+
return
233+
234+
new_releases = 0
235+
releases = result.json()
236+
for release in releases:
237+
release_date = datetime.datetime.strptime(
238+
release["published_at"],
239+
"%Y-%m-%dT%H:%M:%SZ"
240+
)
241+
if not release_date < today_minus_seven:
242+
new_releases += 1
243+
244+
if new_releases == len(releases):
245+
return "new"
246+
else:
247+
return "updated"

adabot/update_cp_org_libraries.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,6 @@
4545
dest="output_file"
4646
)
4747

48-
def is_new_or_updated(repo):
49-
""" Check the repo for new release(s) within the last week. Then determine
50-
if all releases are within the last week to decide if this is a newly
51-
released library, or an updated library.
52-
"""
53-
54-
today_minus_seven = datetime.datetime.today() - datetime.timedelta(days=7)
55-
56-
# first, check the latest release to see if within the last 7 days
57-
result = github.get("/repos/adafruit/" + repo["name"] + "/releases/latest")
58-
if not result.ok:
59-
return
60-
release_info = result.json()
61-
if "published_at" not in release_info:
62-
return
63-
else:
64-
release_date = datetime.datetime.strptime(
65-
release_info["published_at"],
66-
"%Y-%m-%dT%H:%M:%SZ"
67-
)
68-
if release_date < today_minus_seven:
69-
return
70-
71-
# we have a release within the last 7 days. now check if its a newly
72-
# released library within the last week, or if its just an update
73-
result = github.get("/repos/adafruit/" + repo["name"] + "/releases")
74-
if not result.ok:
75-
return
76-
77-
new_releases = 0
78-
releases = result.json()
79-
for release in releases:
80-
release_date = datetime.datetime.strptime(
81-
release["published_at"],
82-
"%Y-%m-%dT%H:%M:%SZ"
83-
)
84-
if not release_date < today_minus_seven:
85-
new_releases += 1
86-
87-
if new_releases == len(releases):
88-
return "new"
89-
else:
90-
return "updated"
91-
9248
def get_open_issues_and_prs(repo):
9349
""" Retreive all of the open issues (minus pull requests) for the repo.
9450
"""
@@ -243,7 +199,7 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
243199
repo_name = repo["name"]
244200

245201
# get a list of new & updated libraries for the last week
246-
check_releases = is_new_or_updated(repo)
202+
check_releases = common_funcs.is_new_or_updated(repo)
247203
if check_releases == "new":
248204
new_libs[repo_name] = repo["html_url"]
249205
elif check_releases == "updated":

0 commit comments

Comments
 (0)