3232import requests
3333
3434from adabot import github_requests as github
35- from adabot import travis_requests as travis
3635from adabot import pypi_requests as pypi
3736from adabot .lib import circuitpython_library_validators as cirpy_lib_vals
3837from adabot .lib import common_funcs
6867 default = 5 ,
6968 metavar = "n"
7069)
71- cmd_line_parser .add_argument (
72- "-t" , "--travis-github-token" ,
73- help = "Prompt for the GitHub user's password in order to make a GitHub token to use on Travis." ,
74- dest = "gh_token" ,
75- action = "store_true"
76- )
7770cmd_line_parser .add_argument (
7871 "-v" , "--validator" ,
7972 help = "Run validators with 'all', or only the validator(s) supplied in a string." ,
10396 if vals [0 ].startswith ("validate" )
10497]
10598
106- pr_sort_re = re .compile ("(?<=\(Open\s)(.+)(?=\sdays)" )
99+ pr_sort_re = re .compile (r"(?<=\(Open\s)(.+)(?=\sdays)" )
100+ close_pr_sort_re = re .compile (r"(?<=\(Days\sopen:\s)(.+)(?=\))" )
107101
108102def run_library_checks (validators , bundle_submodules , latest_pylint , kw_args ):
109103 """runs the various library checking functions"""
@@ -112,7 +106,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
112106 latest_pylint = pylint_info .json ()["info" ]["version" ]
113107 output_handler ("Latest pylint is: {}" .format (latest_pylint ))
114108
115- repos = common_funcs .list_repos (include_repos = ('Adafruit_Blinka' ,))
109+ repos = common_funcs .list_repos (include_repos = ('Adafruit_Blinka' ,
110+ 'CircuitPython_Community_Bundle' ))
116111 output_handler ("Found {} repos to check." .format (len (repos )))
117112 bundle_submodules = common_funcs .get_bundle_submodules ()
118113 output_handler ("Found {} submodules in the bundle." .format (len (bundle_submodules )))
@@ -165,7 +160,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
165160 insights = blinka_insights
166161 elif repo ["name" ] == "circuitpython" :
167162 insights = core_insights
168- errors = validator .gather_insights (repo , insights , since )
163+ closed_metric = bool (insights == lib_insights )
164+ errors = validator .gather_insights (repo , insights , since , show_closed_metric = closed_metric )
169165 if errors :
170166 print ("insights error" )
171167 for error in errors :
@@ -182,11 +178,11 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
182178 updated_libs [repo ["name" ]] = repo ["html_url" ]
183179
184180 output_handler ()
185- output_handler ("State of CircuitPython + Libraries" )
181+ output_handler ("State of CircuitPython + Libraries + Blinka " )
186182
187183 output_handler ("Overall" )
188- print_pr_overview (lib_insights , core_insights )
189- print_issue_overview (lib_insights , core_insights )
184+ print_pr_overview (lib_insights , core_insights , blinka_insights )
185+ print_issue_overview (lib_insights , core_insights , blinka_insights )
190186
191187 output_handler ()
192188 output_handler ("Core" )
@@ -208,20 +204,38 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
208204 core_insights ["milestones" ][milestone ]))
209205 output_handler (" * {} issues not assigned a milestone" .format (len (core_insights ["open_issues" ]) - ms_count ))
210206 output_handler ()
211- print_circuitpython_download_stats ()
207+
208+ ## temporarily disabling core download stats:
209+ # - GitHub API has been broken, due to the number of release artifacts
210+ # - Release asset delivery is being moved to AWS CloudFront/S3
211+ #print_circuitpython_download_stats()
212+ output_handler (
213+ "* Core download stats available at https://circuitpython.org/stats"
214+ )
212215
213216 output_handler ()
214217 output_handler ("Libraries" )
215218 print_pr_overview (lib_insights )
216- output_handler ("* {} open pull requests" . format ( len ( lib_insights [ "open_prs" ])) )
217- sorted_prs = sorted (lib_insights ["open_prs " ],
218- key = lambda days : int (pr_sort_re .search (days ).group (1 )),
219+ output_handler (" * Merged pull requests:" )
220+ sorted_prs = sorted (lib_insights ["merged_prs " ],
221+ key = lambda days : int (close_pr_sort_re .search (days ).group (1 )),
219222 reverse = True )
220223 for pr in sorted_prs :
221- output_handler (" * {}" .format (pr ))
224+ output_handler (" * {}" .format (pr ))
222225 print_issue_overview (lib_insights )
223- output_handler ("* {} open issues" .format (len (lib_insights ["open_issues" ])))
224- output_handler (" * https://circuitpython.org/contributing" )
226+ output_handler ("* https://circuitpython.org/contributing" )
227+ output_handler (" * {} open issues" .format (len (lib_insights ["open_issues" ])))
228+ open_pr_days = [
229+ int (pr_sort_re .search (pr ).group (1 )) for pr in lib_insights ["open_prs" ]
230+ if pr_sort_re .search (pr ) is not None
231+ ]
232+ output_handler (
233+ " * {0} open pull requests (Oldest: {1}, Newest: {2})" .format (
234+ len (lib_insights ["open_prs" ]),
235+ max (open_pr_days ),
236+ max ((min (open_pr_days ), 1 )) # ensure the minumum is '1'
237+ )
238+ )
225239 output_handler ("Library updates in the last seven days:" )
226240 if len (new_libs ) != 0 :
227241 output_handler ("**New Libraries**" )
@@ -280,9 +294,25 @@ def output_handler(message="", quiet=False):
280294
281295def print_circuitpython_download_stats ():
282296 """Gather and report analytics on the main CircuitPython repository."""
283- response = github .get ("/repos/adafruit/circuitpython/releases" )
297+
298+ # TODO: with the move of release assets to AWS CloudFront/S3, update
299+ # this to use AWS CloudWatch metrics to gather download stats.
300+ # AWS' Python SDK `boto3` has CloudWatch interfaces which should
301+ # enable this. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html
302+
303+ try :
304+ response = github .get ("/repos/adafruit/circuitpython/releases" )
305+ except (ValueError , RuntimeError ):
306+ output_handler (
307+ "Core CircuitPython GitHub download statistics request failed."
308+ )
309+ return
310+
284311 if not response .ok :
285- output_handler ("Core CircuitPython GitHub analytics request failed." )
312+ output_handler (
313+ "Core CircuitPython GitHub download statistics request failed."
314+ )
315+ return
286316 releases = response .json ()
287317
288318 found_unstable = False
@@ -416,7 +446,7 @@ def print_circuitpython_download_stats():
416446 output_handler ()
417447
418448def print_pr_overview (* insights ):
419- merged_prs = sum ([x ["merged_prs" ] for x in insights ])
449+ merged_prs = sum ([len ( x ["merged_prs" ]) for x in insights ])
420450 authors = set ().union (* [x ["pr_merged_authors" ] for x in insights ])
421451 reviewers = set ().union (* [x ["pr_reviewers" ] for x in insights ])
422452
@@ -467,10 +497,6 @@ def print_issue_overview(*insights):
467497 error_depth = cmd_line_args .error_depth
468498 startup_message .append (" - Depth for listing libraries with errors: {}" .format (error_depth ))
469499
470- github_token = cmd_line_args .gh_token
471- validator_kwarg_list ["github_token" ] = github_token
472- startup_message .append (" - Prompts for the GitHub Token are {}." .format (("enabled" if github_token else "disabled" )))
473-
474500 if cmd_line_args .validator != "all" :
475501 validators = []
476502 for func in cmd_line_args .validator .split ("," ):
0 commit comments