@@ -99,48 +99,47 @@ def get_open_issues_and_prs(repo):
99
99
def get_contributors (repo ):
100
100
contributors = []
101
101
reviewers = []
102
+ merged_pr_count = 0
102
103
params = {"state" :"closed" , "sort" :"updated" , "direction" :"desc" }
103
104
result = github .get ("/repos/adafruit/" + repo ["name" ] + "/pulls" , params = params )
104
- if not result .ok :
105
- return [], []
106
-
107
- today_minus_seven = datetime .datetime .today () - datetime .timedelta (days = 7 )
108
- prs = result .json ()
109
- for pr in prs :
110
- merged_at = datetime .datetime .min
111
- if "merged_at" in pr :
112
- if pr ["merged_at" ] is None :
105
+ if result .ok :
106
+ today_minus_seven = datetime .datetime .today () - datetime .timedelta (days = 7 )
107
+ prs = result .json ()
108
+ for pr in prs :
109
+ merged_at = datetime .datetime .min
110
+ if "merged_at" in pr :
111
+ if pr ["merged_at" ] is None :
112
+ continue
113
+ merged_at = datetime .datetime .strptime (pr ["merged_at" ], "%Y-%m-%dT%H:%M:%SZ" )
114
+ else :
113
115
continue
114
- merged_at = datetime .datetime .strptime (pr ["merged_at" ], "%Y-%m-%dT%H:%M:%SZ" )
115
- else :
116
- continue
117
- if merged_at < today_minus_seven :
118
- continue
119
- contributors .append (pr ["user" ]["login" ])
116
+ if merged_at < today_minus_seven :
117
+ continue
118
+ contributors .append (pr ["user" ]["login" ])
119
+ merged_pr_count += 1
120
120
121
- # get reviewers (merged_by, and any others)
122
- single_pr = github .get (pr ["url" ])
123
- if not single_pr .ok :
124
- continue
125
- pr_info = single_pr .json ()
126
- reviewers .append (pr_info ["merged_by" ]["login" ])
127
- pr_reviews = github .get (str (pr_info ["url" ]) + "/reviews" )
128
- if not pr_reviews .ok :
129
- continue
130
- for review in pr_reviews .json ():
131
- if review ["state" ].lower () == "approved" :
132
- reviewers .append (review ["user" ]["login" ])
121
+ # get reviewers (merged_by, and any others)
122
+ single_pr = github .get (pr ["url" ])
123
+ if not single_pr .ok :
124
+ continue
125
+ pr_info = single_pr .json ()
126
+ reviewers .append (pr_info ["merged_by" ]["login" ])
127
+ pr_reviews = github .get (str (pr_info ["url" ]) + "/reviews" )
128
+ if not pr_reviews .ok :
129
+ continue
130
+ for review in pr_reviews .json ():
131
+ if review ["state" ].lower () == "approved" :
132
+ reviewers .append (review ["user" ]["login" ])
133
133
134
- return contributors , reviewers
134
+ return contributors , reviewers , merged_pr_count
135
135
136
136
def update_json_file (working_directory , cp_org_dir , output_filename , json_string ):
137
137
""" Clone the circuitpython-org repo, update libraries.json, and push the updates
138
- in a commit/pull request .
138
+ in a commit.
139
139
"""
140
140
if not os .path .isdir (cp_org_dir ):
141
141
os .makedirs (cp_org_dir , exist_ok = True )
142
142
if "TRAVIS" in os .environ :
143
- #git_url = "https://" + os.environ["ADABOT_GITHUB_ACCESS_TOKEN"] + "@github.com/adafruit-adabot/circuitpython-org.git"
144
143
git_url = "https://" + os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ] + "@github.com/adafruit/circuitpython-org.git"
145
144
git .clone ("-o" , "adafruit" , git_url , cp_org_dir )
146
145
else :
@@ -149,8 +148,6 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
149
148
os .chdir (cp_org_dir )
150
149
git .pull ()
151
150
git .submodule ("update" , "--init" , "--recursive" )
152
- #check_branch = git.branch("-r", "--list")
153
- #print("branch result:", check_branch.split("\n"))
154
151
155
152
with open (output_filename , "w" ) as json_file :
156
153
json .dump (json_string , json_file , indent = 2 )
@@ -159,7 +156,8 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
159
156
commit_day = date .date .strftime (datetime .datetime .today (), "%Y-%m-%d" )
160
157
commit_msg = "adabot: auto-update of libraries.json ({})" .format (commit_day )
161
158
git .commit ("-a" , "-m" , commit_msg )
162
- git .push ()
159
+ git_push = git .push ("adafruit" , "master" )
160
+ print (git_push )
163
161
164
162
if __name__ == "__main__" :
165
163
cmd_line_args = cmd_line_parser .parse_args ()
@@ -193,7 +191,6 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
193
191
local_file_output = False
194
192
if cmd_line_args .output_file :
195
193
output_filename = os .path .abspath (cmd_line_args .output_file )
196
- print (output_filename )
197
194
local_file_output = True
198
195
startup_message .append (" - Output will be saved to: {}" .format (output_filename ))
199
196
@@ -207,6 +204,7 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
207
204
open_prs_by_repo = {}
208
205
contributors = []
209
206
reviewers = []
207
+ merged_pr_count_total = 0
210
208
repos_by_error = {}
211
209
212
210
default_validators = [vals [1 ] for vals in inspect .getmembers (cpy_vals .library_validator ) if vals [0 ].startswith ("validate" )]
@@ -233,11 +231,12 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
233
231
open_prs_by_repo [repo_name ] = check_prs
234
232
235
233
# get the contributors and reviewers for the last week
236
- get_contribs , get_revs = get_contributors (repo )
234
+ get_contribs , get_revs , get_merge_count = get_contributors (repo )
237
235
if get_contribs :
238
236
contributors .extend (get_contribs )
239
237
if get_revs :
240
238
reviewers .extend (get_revs )
239
+ merged_pr_count_total += get_merge_count
241
240
242
241
# run repo validators to check for infrastructure errors
243
242
errors = validator .run_repo_validation (repo )
@@ -282,19 +281,18 @@ def update_json_file(working_directory, cp_org_dir, output_filename, json_string
282
281
"updated_at" : run_time .strftime ("%Y-%m-%dT%H:%M:%SZ" ),
283
282
"contributors" : [contrib for contrib in set (contributors )],
284
283
"reviewers" : [rev for rev in set (reviewers )],
284
+ "merged_pr_count" : str (merged_pr_count_total ),
285
285
"library_updates" : {"new" : sorted_new_list , "updated" : sorted_updated_list },
286
286
"open_issues" : sorted_issues_list ,
287
287
"pull_requests" : sorted_prs_list ,
288
- "repo_infrastructure_errors" : sorted_repos_by_error
288
+ "repo_infrastructure_errors" : sorted_repos_by_error ,
289
289
}
290
290
json_obj = json .dumps (build_json , indent = 2 )
291
291
292
292
if "TRAVIS" in os .environ :
293
- # WIP: will finish after final deployment is determined.
294
- #update_json_file(working_directory, cp_org_dir, output_filename, build_json)
295
- print ()
293
+ update_json_file (working_directory , cp_org_dir , output_filename , build_json )
296
294
else :
297
295
if local_file_output :
298
296
with open (output_filename , "w" ) as json_file :
299
297
json .dump (build_json , json_file , indent = 2 )
300
- print (json .dumps (build_json , indent = 2 ))
298
+ print (json .dumps (build_json , indent = 2 ))
0 commit comments