@@ -69,6 +69,16 @@ def list_repos():
69
69
70
70
return repos
71
71
72
+ def is_arduino_library (repo ):
73
+ """ Returns if the repo is an Arduino library, as determined by the existence of
74
+ the 'library.properties' file.
75
+ """
76
+ has_lib_prop = github .get ("/repos/adafruit/" + repo ["name" ] + "/contents" )
77
+ if has_lib_prop .ok :
78
+ return ("library.properties" in has_lib_prop .text )
79
+ else :
80
+ return False
81
+
72
82
def output_handler (message = "" , quiet = False ):
73
83
"""Handles message output to prompt/file for print_*() functions."""
74
84
if output_filename is not None :
@@ -115,23 +125,76 @@ def validate_library_properties(repo):
115
125
#print("{} skipped".format(repo["name"]))
116
126
return
117
127
128
+ def validate_release_state (repo ):
129
+ """Validate if a repo 1) has a release, and 2) if there have been commits
130
+ since the last release. Returns a list of string error messages for the
131
+ repository.
132
+ """
133
+
134
+ if not is_arduino_library (repo ):
135
+ return
136
+ repo_last_release = github .get ("/repos/" + repo ["full_name" ] + "/releases/latest" )
137
+ if not repo_last_release .ok :
138
+ return
139
+ repo_release_json = repo_last_release .json ()
140
+ if "tag_name" in repo_release_json :
141
+ tag_name = repo_release_json ["tag_name" ]
142
+ elif "message" in repo_release_json :
143
+ output_handler ("Error: retrieving latest release information failed on '{0}'. Information Received: {1}" .format (
144
+ repo ["name" ], repo_release_json ["message" ]))
145
+ return
146
+
147
+ compare_tags = github .get ("/repos/" + repo ["full_name" ] + "/compare/master..." + tag_name )
148
+ if not compare_tags .ok :
149
+ output_handler ("Error: failed to compare {0} 'master' to tag '{1}'" .format (repo ["name" ], tag_name ))
150
+ return
151
+ compare_tags_json = compare_tags .json ()
152
+ if "status" in compare_tags_json :
153
+ if compare_tags .json ()["status" ] != "identical" :
154
+ #print("Compare {4} status: {0} \n Ahead: {1} \t Behind: {2} \t Commits: {3}".format(
155
+ # compare_tags_json["status"], compare_tags_json["ahead_by"],
156
+ # compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
157
+ return [tag_name , compare_tags_json ["behind_by" ]]
158
+ elif "errors" in compare_tags_json :
159
+ output_handler ("Error: comparing latest release to 'master' failed on '{0}'. Error Message: {1}" .format (
160
+ repo ["name" ], compare_tags_json ["message" ]))
161
+
162
+ return
163
+
118
164
def run_arduino_lib_checks ():
119
165
output_handler ("Running Arduino Library Checks" )
166
+ output_handler ("Getting list of libraries to check..." )
120
167
121
168
repo_list = list_repos ()
169
+ output_handler ("Found {} Arduino libraries to check\n " .format (len (repo_list )))
122
170
failed_lib_prop = [[" Repo" , "Release Tag" , "library.properties Version" ], [" ----" , "-----------" , "--------------------------" ]]
171
+ needs_release_list = [[" Repo" , "Latest Release" , "Commits Behind" ], [" ----" , "--------------" , "--------------" ]]
123
172
for repo in repo_list :
124
173
lib_check = validate_library_properties (repo )
125
174
if lib_check :
126
175
if lib_check [0 ] != lib_check [1 ]:
127
176
failed_lib_prop .append ([" " + str (repo ["name" ]), lib_check [0 ], lib_check [1 ]])
128
177
129
- output_handler ("Libraries Have Mismatched Release Tag and library.properties Version: ({})" .format (len (failed_lib_prop )))
130
- long_col = [(max ([len (str (row [i ])) for row in failed_lib_prop ]) + 3 )
131
- for i in range (len (failed_lib_prop [0 ]))]
132
- row_format = "" .join (["{:<" + str (this_col ) + "}" for this_col in long_col ])
133
- for lib in failed_lib_prop :
134
- print (row_format .format (* lib ))
178
+ needs_release = validate_release_state (repo )
179
+ if needs_release :
180
+ needs_release_list .append ([" " + str (repo ["name" ]), needs_release [0 ], needs_release [1 ]])
181
+
182
+ if len (failed_lib_prop ) > 2 :
183
+ output_handler ("Libraries Have Mismatched Release Tag and library.properties Version: ({})" .format (len (failed_lib_prop )))
184
+ long_col = [(max ([len (str (row [i ])) for row in failed_lib_prop ]) + 3 )
185
+ for i in range (len (failed_lib_prop [0 ]))]
186
+ row_format = "" .join (["{:<" + str (this_col ) + "}" for this_col in long_col ])
187
+ for lib in failed_lib_prop :
188
+ output_handler (row_format .format (* lib ))
189
+
190
+ if len (needs_release_list ) > 2 :
191
+ output_handler ()
192
+ output_handler ("Libraries have commits since last release: ({})" .format (len (needs_release_list )))
193
+ long_col = [(max ([len (str (row [i ])) for row in needs_release_list ]) + 3 )
194
+ for i in range (len (needs_release_list [0 ]))]
195
+ row_format = "" .join (["{:<" + str (this_col ) + "}" for this_col in long_col ])
196
+ for lib in needs_release_list :
197
+ output_handler (row_format .format (* lib ))
135
198
136
199
if __name__ == "__main__" :
137
200
cmd_line_args = cmd_line_parser .parse_args ()
0 commit comments