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
"""
@@ -70,12 +67,23 @@ def get_open_issues_and_prs(repo):
70
67
issue_title = "{0} (Open {1} days)" .format (issue ["title" ],
71
68
days_open .days )
72
69
if "pull_request" not in issue : # ignore pull requests
73
- open_issues .append ({issue ["html_url" ]: issue_title })
70
+ issue_labels = ["None" ]
71
+ if len (issue ["labels" ]) != 0 :
72
+ issue_labels = [label ["name" ] for label in issue ["labels" ]]
73
+
74
+ issue_dict = {
75
+ "title" : issue_title ,
76
+ "url" : issue ["html_url" ],
77
+ "labels" : issue_labels ,
78
+ }
79
+
80
+ open_issues .append (issue_dict )
74
81
else :
75
82
open_pull_requests .append ({issue ["html_url" ]: issue_title })
76
83
77
84
return open_issues , open_pull_requests
78
85
86
+
79
87
def get_contributors (repo ):
80
88
contributors = []
81
89
reviewers = []
@@ -115,74 +123,6 @@ def get_contributors(repo):
115
123
116
124
return contributors , reviewers , merged_pr_count
117
125
118
- def update_json_file (json_string ):
119
- """ Uses GitHub API to do the following:
120
- - Creates branch on fork 'adafruit-adabot/circuipython-org'
121
- - Updates '_data/libraries.json'
122
- - Creates pull request from fork to upstream
123
-
124
- Note: adapted from Scott Shawcroft's code found here
125
- https://github.com/adafruit/circuitpython/blob/master/tools/build_board_info.py
126
- """
127
- master_url = "/repos/adafruit/circuitpython-org/"
128
- fork_url = "/repos/adafruit-adabot/circuitpython-org/"
129
- commit_date = datetime .date .today ()
130
- branch_name = "libraries_update_" + commit_date .strftime ("%d-%b-%y" )
131
-
132
- response = github .get (master_url + "git/refs/heads/master" )
133
- if not response .ok :
134
- raise RuntimeError (
135
- "Failed to retrieve master sha:\n {}" .format (response .text )
136
- )
137
- commit_sha = response .json ()["object" ]["sha" ]
138
-
139
- response = github .get (
140
- master_url + "contents/_data/libraries.json?ref=" + commit_sha
141
- )
142
- if not response .ok :
143
- raise RuntimeError (
144
- "Failed to retrieve libraries.json sha:\n {}" .format (response .text )
145
- )
146
- blob_sha = response .json ()["sha" ]
147
-
148
- branch_info = {
149
- "ref" : "refs/heads/" + branch_name ,
150
- "sha" : commit_sha
151
- }
152
- response = github .post (fork_url + "git/refs" , json = branch_info )
153
- if not response .ok and response .json ()["message" ] != "Reference already exists" :
154
- raise RuntimeError (
155
- "Failed to create branch:\n {}" .format (response .text )
156
- )
157
-
158
- commit_msg = "Automated Libraries update for {}" .format (commit_date .strftime ("%d-%b-%y" ))
159
- content = json_string .encode ("utf-8" ) + b"\n "
160
- update_json = {
161
- "message" : commit_msg ,
162
- "content" : base64 .b64encode (content ).decode ("utf-8" ),
163
- "sha" : blob_sha ,
164
- "branch" : branch_name
165
- }
166
- response = github .put (fork_url + "contents/_data/libraries.json" ,
167
- json = update_json )
168
- if not response .ok :
169
- raise RuntimeError (
170
- "Failed to update libraries.json:\n {}" .format (response .text )
171
- )
172
-
173
- pr_info = {
174
- "title" : commit_msg ,
175
- "head" : "adafruit-adabot:" + branch_name ,
176
- "base" : "master" ,
177
- "body" : commit_msg ,
178
- "maintainer_can_modify" : True
179
- }
180
- response = github .post (master_url + "pulls" , json = pr_info )
181
- if not response .ok :
182
- raise RuntimeError (
183
- "Failed to create pull request:\n {}" .format (response .text )
184
- )
185
-
186
126
187
127
if __name__ == "__main__" :
188
128
cmd_line_args = cmd_line_parser .parse_args ()
@@ -192,7 +132,6 @@ def update_json_file(json_string):
192
132
run_time = datetime .datetime .now ()
193
133
194
134
working_directory = os .path .abspath (os .getcwd ())
195
- #cp_org_dir = os.path.join(working_directory, ".cp_org")
196
135
197
136
startup_message = [
198
137
"Run Date: {}" .format (run_time .strftime ("%d %B %Y, %I:%M%p" ))
@@ -310,7 +249,6 @@ def update_json_file(json_string):
310
249
}
311
250
json_obj = json .dumps (build_json , indent = 2 )
312
251
313
- #update_json_file(json_obj)
314
252
if local_file_output :
315
253
with open (output_filename , "w" ) as json_file :
316
254
json .dump (build_json , json_file , indent = 2 )
0 commit comments