21
21
# THE SOFTWARE.
22
22
23
23
import argparse
24
- import base64
25
24
import datetime
26
25
import inspect
27
26
import json
28
27
import os
29
28
import re
30
- import sh
31
- from sh .contrib import git
32
- import sys
33
29
34
30
from adabot .lib import common_funcs
35
31
from adabot .lib import circuitpython_library_validators as cpy_vals
49
45
50
46
sort_re = re .compile ("(?<=\(Open\s)(.+)(?=\sdays)" )
51
47
48
+
52
49
def get_open_issues_and_prs (repo ):
53
50
""" Retreive all of the open issues (minus pull requests) for the repo.
54
51
"""
@@ -86,6 +83,7 @@ def get_open_issues_and_prs(repo):
86
83
87
84
return open_issues , open_pull_requests
88
85
86
+
89
87
def get_contributors (repo ):
90
88
contributors = []
91
89
reviewers = []
@@ -125,74 +123,6 @@ def get_contributors(repo):
125
123
126
124
return contributors , reviewers , merged_pr_count
127
125
128
- def update_json_file (json_string ):
129
- """ Uses GitHub API to do the following:
130
- - Creates branch on fork 'adafruit-adabot/circuipython-org'
131
- - Updates '_data/libraries.json'
132
- - Creates pull request from fork to upstream
133
-
134
- Note: adapted from Scott Shawcroft's code found here
135
- https://github.com/adafruit/circuitpython/blob/master/tools/build_board_info.py
136
- """
137
- master_url = "/repos/adafruit/circuitpython-org/"
138
- fork_url = "/repos/adafruit-adabot/circuitpython-org/"
139
- commit_date = datetime .date .today ()
140
- branch_name = "libraries_update_" + commit_date .strftime ("%d-%b-%y" )
141
-
142
- response = github .get (master_url + "git/refs/heads/master" )
143
- if not response .ok :
144
- raise RuntimeError (
145
- "Failed to retrieve master sha:\n {}" .format (response .text )
146
- )
147
- commit_sha = response .json ()["object" ]["sha" ]
148
-
149
- response = github .get (
150
- master_url + "contents/_data/libraries.json?ref=" + commit_sha
151
- )
152
- if not response .ok :
153
- raise RuntimeError (
154
- "Failed to retrieve libraries.json sha:\n {}" .format (response .text )
155
- )
156
- blob_sha = response .json ()["sha" ]
157
-
158
- branch_info = {
159
- "ref" : "refs/heads/" + branch_name ,
160
- "sha" : commit_sha
161
- }
162
- response = github .post (fork_url + "git/refs" , json = branch_info )
163
- if not response .ok and response .json ()["message" ] != "Reference already exists" :
164
- raise RuntimeError (
165
- "Failed to create branch:\n {}" .format (response .text )
166
- )
167
-
168
- commit_msg = "Automated Libraries update for {}" .format (commit_date .strftime ("%d-%b-%y" ))
169
- content = json_string .encode ("utf-8" ) + b"\n "
170
- update_json = {
171
- "message" : commit_msg ,
172
- "content" : base64 .b64encode (content ).decode ("utf-8" ),
173
- "sha" : blob_sha ,
174
- "branch" : branch_name
175
- }
176
- response = github .put (fork_url + "contents/_data/libraries.json" ,
177
- json = update_json )
178
- if not response .ok :
179
- raise RuntimeError (
180
- "Failed to update libraries.json:\n {}" .format (response .text )
181
- )
182
-
183
- pr_info = {
184
- "title" : commit_msg ,
185
- "head" : "adafruit-adabot:" + branch_name ,
186
- "base" : "master" ,
187
- "body" : commit_msg ,
188
- "maintainer_can_modify" : True
189
- }
190
- response = github .post (master_url + "pulls" , json = pr_info )
191
- if not response .ok :
192
- raise RuntimeError (
193
- "Failed to create pull request:\n {}" .format (response .text )
194
- )
195
-
196
126
197
127
if __name__ == "__main__" :
198
128
cmd_line_args = cmd_line_parser .parse_args ()
@@ -202,7 +132,6 @@ def update_json_file(json_string):
202
132
run_time = datetime .datetime .now ()
203
133
204
134
working_directory = os .path .abspath (os .getcwd ())
205
- #cp_org_dir = os.path.join(working_directory, ".cp_org")
206
135
207
136
startup_message = [
208
137
"Run Date: {}" .format (run_time .strftime ("%d %B %Y, %I:%M%p" ))
@@ -320,7 +249,6 @@ def update_json_file(json_string):
320
249
}
321
250
json_obj = json .dumps (build_json , indent = 2 )
322
251
323
- #update_json_file(json_obj)
324
252
if local_file_output :
325
253
with open (output_filename , "w" ) as json_file :
326
254
json .dump (build_json , json_file , indent = 2 )
0 commit comments