39
39
verbosity = 1
40
40
file_data = []
41
41
42
+ all_libraries = []
43
+
42
44
def list_repos ():
43
45
""" Return a list of all Adafruit repositories with 'Arduino' in either the
44
46
name, description, or readme. Each list item is a dictionary of GitHub API
45
47
repository state.
46
48
"""
47
49
repos = []
48
50
result = github .get ("/search/repositories" ,
49
- params = {"q" :"Arduino in:name in:description in:readme fork:true user:adafruit archived:false" ,
51
+ params = {"q" :"Arduino in:name in:description in:readme fork:true user:adafruit archived:false AND NOT PCB in:name AND NOT CircuitPython in:name " ,
50
52
"per_page" : 100 ,
51
53
"sort" : "updated" ,
52
54
"order" : "asc" })
53
55
while result .ok :
54
- links = result .headers ["Link" ]
55
56
repos .extend (result .json ()["items" ]) # uncomment and comment below, to include all forks
56
57
58
+ try :
59
+ links = result .headers ["Link" ]
60
+ except KeyError :
61
+ break
62
+
57
63
if links :
58
64
next_url = None
59
65
for link in links .split ("," ):
@@ -67,18 +73,14 @@ def list_repos():
67
73
break
68
74
# Subsequent links have our access token already so we use requests directly.
69
75
result = requests .get (link , timeout = 30 )
70
-
71
76
return repos
72
77
73
78
def is_arduino_library (repo ):
74
79
""" Returns if the repo is an Arduino library, as determined by the existence of
75
80
the 'library.properties' file.
76
81
"""
77
- has_lib_prop = github .get ("/repos/adafruit/" + repo ["name" ] + "/contents" )
78
- if has_lib_prop .ok :
79
- return ("library.properties" in has_lib_prop .text )
80
- else :
81
- return False
82
+ lib_prop_file = requests .get ("https://raw.githubusercontent.com/adafruit/" + repo ["name" ] + "/master/library.properties" )
83
+ return lib_prop_file .ok
82
84
83
85
def print_list_output (title , coll ):
84
86
""
@@ -105,67 +107,52 @@ def validate_library_properties(repo):
105
107
lib_prop_file = None
106
108
lib_version = None
107
109
release_tag = None
108
- has_lib_prop = github .get ("/repos/adafruit/" + repo ["name" ] + "/contents" )
109
- if has_lib_prop .ok :
110
- if "library.properties" not in has_lib_prop .text :
111
- return False
112
- for file in has_lib_prop .json ():
113
- if file ["name" ] == "library.properties" :
114
- lib_prop_file = requests .get (file ["download_url" ], timeout = 30 )
115
- if lib_prop_file .ok :
116
- lines = lib_prop_file .text .split ("\n " )
117
- for line in lines :
118
- if "version" in line :
119
- lib_version = line [len ("version=" ):]
120
- break
121
-
122
- get_latest_release = github .get ("/repos/adafruit/" + repo ["name" ] + "/releases/latest" )
123
- if get_latest_release .ok :
124
- response = get_latest_release .json ()
125
- if "tag_name" in response :
126
- release_tag = response ["tag_name" ]
127
- if "message" in response :
128
- if response ["message" ] == "Not Found" :
129
- release_tag = "None"
130
- else :
131
- release_tag = "Unknown"
132
-
133
- if lib_version and release_tag :
110
+ lib_prop_file = requests .get ("https://raw.githubusercontent.com/adafruit/" + repo ["name" ] + "/master/library.properties" )
111
+ if not lib_prop_file .ok :
112
+ print ("{} skipped" .format (repo ["name" ]))
113
+ return None # no library properties file!
114
+
115
+ lines = lib_prop_file .text .split ("\n " )
116
+ for line in lines :
117
+ if "version" in line :
118
+ lib_version = line [len ("version=" ):]
119
+ break
120
+
121
+ get_latest_release = github .get ("/repos/adafruit/" + repo ["name" ] + "/releases/latest" )
122
+ if get_latest_release .ok :
123
+ response = get_latest_release .json ()
124
+ if "tag_name" in response :
125
+ release_tag = response ["tag_name" ]
126
+ if "message" in response :
127
+ if response ["message" ] == "Not Found" :
128
+ release_tag = "None"
129
+ else :
130
+ release_tag = "Unknown"
131
+
132
+ if lib_version and release_tag :
134
133
return [release_tag , lib_version ]
135
134
136
- #print("{} skipped".format(repo["name"]))
137
- return
135
+ return None
138
136
139
137
def validate_release_state (repo ):
140
138
"""Validate if a repo 1) has a release, and 2) if there have been commits
141
139
since the last release. Returns a list of string error messages for the
142
140
repository.
143
141
"""
144
-
145
142
if not is_arduino_library (repo ):
146
143
return
147
- repo_last_release = github .get ("/repos/" + repo ["full_name" ] + "/releases/latest" )
148
- if not repo_last_release .ok :
149
- return
150
- repo_release_json = repo_last_release .json ()
151
- if "tag_name" in repo_release_json :
152
- tag_name = repo_release_json ["tag_name" ]
153
- elif "message" in repo_release_json :
154
- output_handler ("Error: retrieving latest release information failed on '{0}'. Information Received: {1}" .format (
155
- repo ["name" ], repo_release_json ["message" ]))
156
- return
157
144
158
- compare_tags = github .get ("/repos/" + repo ["full_name" ] + "/compare/master..." + tag_name )
145
+ compare_tags = github .get ("/repos/" + repo ["full_name" ] + "/compare/master..." + repo [ ' tag_name' ] )
159
146
if not compare_tags .ok :
160
- output_handler ("Error: failed to compare {0} 'master' to tag '{1}'" .format (repo ["name" ], tag_name ))
147
+ output_handler ("Error: failed to compare {0} 'master' to tag '{1}'" .format (repo ["name" ], repo [ ' tag_name' ] ))
161
148
return
162
149
compare_tags_json = compare_tags .json ()
163
150
if "status" in compare_tags_json :
164
151
if compare_tags .json ()["status" ] != "identical" :
165
152
#print("Compare {4} status: {0} \n Ahead: {1} \t Behind: {2} \t Commits: {3}".format(
166
153
# compare_tags_json["status"], compare_tags_json["ahead_by"],
167
154
# compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
168
- return [tag_name , compare_tags_json ["behind_by" ]]
155
+ return [repo [ ' tag_name' ] , compare_tags_json ["behind_by" ]]
169
156
elif "errors" in compare_tags_json :
170
157
output_handler ("Error: comparing latest release to 'master' failed on '{0}'. Error Message: {1}" .format (
171
158
repo ["name" ], compare_tags_json ["message" ]))
@@ -175,18 +162,14 @@ def validate_release_state(repo):
175
162
def validate_travis (repo ):
176
163
"""Validate if a repo has .travis.yml.
177
164
"""
178
- repo_has_travis = github .get ("/repos/" + repo ["full_name" ] + "/contents/.travis.yml" )
179
- if repo_has_travis .ok :
180
- return True
165
+ repo_has_travis = requests .get ("https://raw.githubusercontent.com/adafruit/" + repo ["name" ] + "/master/.travis.yml" )
166
+ return repo_has_travis .ok
181
167
182
168
def validate_example (repo ):
183
169
"""Validate if a repo has any files in examples directory
184
170
"""
185
171
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
172
+ return repo_has_ino .ok and len (repo_has_ino .json ())
190
173
191
174
def run_arduino_lib_checks ():
192
175
output_handler ("Running Arduino Library Checks" )
@@ -200,24 +183,36 @@ def run_arduino_lib_checks():
200
183
missing_library_properties_list = [[" Repo" ], [" ----" ]]
201
184
202
185
for repo in repo_list :
186
+ have_examples = validate_example (repo )
187
+ if not have_examples :
188
+ # not a library
189
+ continue
190
+
191
+ entry = {'name' : repo ["name" ]}
192
+
203
193
lib_check = validate_library_properties (repo )
204
- if lib_check :
205
- if lib_check [ 0 ] != lib_check [ 1 ]:
206
- failed_lib_prop . append ([ " " + str ( repo [ "name" ]), lib_check [ 0 ], lib_check [ 1 ]])
194
+ if not lib_check :
195
+ missing_library_properties_list . append ([ " " + str ( repo [ "name" ])])
196
+ continue
207
197
208
- 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
198
+ entry ['release' ] = lib_check [0 ]
199
+ entry ['version' ] = lib_check [1 ]
200
+ repo ['tag_name' ] = lib_check [0 ]
212
201
202
+ needs_release = validate_release_state (repo )
203
+ entry ['needs_release' ] = needs_release
213
204
if needs_release :
214
205
needs_release_list .append ([" " + str (repo ["name" ]), needs_release [0 ], needs_release [1 ]])
215
206
216
- if missing_travis and have_ino :
207
+ missing_travis = not validate_travis (repo )
208
+ entry ['needs_travis' ] = missing_travis
209
+ if missing_travis :
217
210
missing_travis_list .append ([" " + str (repo ["name" ])])
218
211
219
- if missing_library_properties and have_ino :
220
- missing_library_properties_list .append ([" " + str (repo ["name" ])])
212
+ all_libraries .append (entry )
213
+
214
+ for entry in all_libraries :
215
+ print (entry )
221
216
222
217
if len (failed_lib_prop ) > 2 :
223
218
print_list_output ("Libraries Have Mismatched Release Tag and library.properties Version: ({})" , failed_lib_prop )
@@ -226,10 +221,10 @@ def run_arduino_lib_checks():
226
221
print_list_output ("Libraries have commits since last release: ({})" , needs_release_list );
227
222
228
223
if len (missing_travis_list ) > 2 :
229
- print_list_output ("Libraries that is not configured with Travis (but have *.ino files) : ({})" , missing_travis_list )
224
+ print_list_output ("Libraries that is not configured with Travis: ({})" , missing_travis_list )
230
225
231
226
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 )
227
+ print_list_output ("Libraries that is missing library.properties file: ({})" , missing_library_properties_list )
233
228
234
229
235
230
if __name__ == "__main__" :
0 commit comments