Skip to content

Commit 9869a7c

Browse files
authored
Merge pull request #100 from hoffmannjan/master
missing travis + has ino + has library.properties + github delay hotfix
2 parents 26eb86d + ad9353c commit 9869a7c

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

adabot/arduino_libraries.py

+49-14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def is_arduino_library(repo):
8080
else:
8181
return False
8282

83+
def print_list_output(title, coll):
84+
""
85+
output_handler()
86+
output_handler(title.format(len(coll)))
87+
long_col = [(max([len(str(row[i])) for row in coll]) + 3)
88+
for i in range(len(coll[0]))]
89+
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
90+
for lib in coll:
91+
output_handler(row_format.format(*lib))
92+
8393
def output_handler(message="", quiet=False):
8494
"""Handles message output to prompt/file for print_*() functions."""
8595
if output_filename is not None:
@@ -98,7 +108,7 @@ def validate_library_properties(repo):
98108
has_lib_prop = github.get("/repos/adafruit/" + repo["name"] + "/contents")
99109
if has_lib_prop.ok:
100110
if "library.properties" not in has_lib_prop.text:
101-
return
111+
return False
102112
for file in has_lib_prop.json():
103113
if file["name"] == "library.properties":
104114
lib_prop_file = requests.get(file["download_url"], timeout=30)
@@ -162,6 +172,22 @@ def validate_release_state(repo):
162172

163173
return
164174

175+
def validate_travis(repo):
176+
"""Validate if a repo has .travis.yml.
177+
"""
178+
repo_has_travis = github.get("/repos/" + repo["full_name"] + "/contents/.travis.yml")
179+
if repo_has_travis.ok:
180+
return True
181+
182+
def validate_example(repo):
183+
"""Validate if a repo has any files in examples directory
184+
"""
185+
repo_has_ino = github.get("/repos/adafruit/" + repo["name"] + "/contents/examples")
186+
if repo_has_ino.ok and len(repo_has_ino.json()):
187+
return True
188+
else:
189+
return False
190+
165191
def run_arduino_lib_checks():
166192
output_handler("Running Arduino Library Checks")
167193
output_handler("Getting list of libraries to check...")
@@ -170,32 +196,41 @@ def run_arduino_lib_checks():
170196
output_handler("Found {} Arduino libraries to check\n".format(len(repo_list)))
171197
failed_lib_prop = [[" Repo", "Release Tag", "library.properties Version"], [" ----", "-----------", "--------------------------"]]
172198
needs_release_list = [[" Repo", "Latest Release", "Commits Behind"], [" ----", "--------------", "--------------"]]
199+
missing_travis_list = [[" Repo"], [" ----"]]
200+
missing_library_properties_list = [[" Repo"], [" ----"]]
201+
173202
for repo in repo_list:
174203
lib_check = validate_library_properties(repo)
175204
if lib_check:
176205
if lib_check[0] != lib_check[1]:
177206
failed_lib_prop.append([" " + str(repo["name"]), lib_check[0], lib_check[1]])
178207

179208
needs_release = validate_release_state(repo)
209+
missing_travis = not validate_travis(repo)
210+
have_ino = validate_example(repo)
211+
missing_library_properties = lib_check == False
212+
180213
if needs_release:
181214
needs_release_list.append([" " + str(repo["name"]), needs_release[0], needs_release[1]])
182215

216+
if missing_travis and have_ino:
217+
missing_travis_list.append([" " + str(repo["name"])])
218+
219+
if missing_library_properties and have_ino:
220+
missing_library_properties_list.append([" " + str(repo["name"])])
221+
183222
if len(failed_lib_prop) > 2:
184-
output_handler("Libraries Have Mismatched Release Tag and library.properties Version: ({})".format(len(failed_lib_prop)))
185-
long_col = [(max([len(str(row[i])) for row in failed_lib_prop]) + 3)
186-
for i in range(len(failed_lib_prop[0]))]
187-
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
188-
for lib in failed_lib_prop:
189-
output_handler(row_format.format(*lib))
223+
print_list_output("Libraries Have Mismatched Release Tag and library.properties Version: ({})", failed_lib_prop)
190224

191225
if len(needs_release_list) > 2:
192-
output_handler()
193-
output_handler("Libraries have commits since last release: ({})".format(len(needs_release_list)))
194-
long_col = [(max([len(str(row[i])) for row in needs_release_list]) + 3)
195-
for i in range(len(needs_release_list[0]))]
196-
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
197-
for lib in needs_release_list:
198-
output_handler(row_format.format(*lib))
226+
print_list_output("Libraries have commits since last release: ({})", needs_release_list);
227+
228+
if len(missing_travis_list) > 2:
229+
print_list_output("Libraries that is not configured with Travis (but have *.ino files): ({})", missing_travis_list)
230+
231+
if len(missing_library_properties_list) > 2:
232+
print_list_output("Libraries that is missing library.properties file (but have *.ino files): ({})", missing_library_properties_list)
233+
199234

200235
if __name__ == "__main__":
201236
cmd_line_args = cmd_line_parser.parse_args()

adabot/github_requests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def get(url, **kwargs):
8484
time.sleep(300)
8585
else:
8686
reset_diff = rate_limit_reset - datetime.datetime.now()
87+
8788
print("Sleeping {} seconds".format(reset_diff.seconds))
88-
time.sleep(reset_diff.seconds)
89+
time.sleep(reset_diff.seconds + 1)
8990
if remaining % 100 == 0:
9091
print(remaining, "requests remaining this hour")
9192
return response

0 commit comments

Comments
 (0)