Skip to content

Commit 8bf52d0

Browse files
authored
Merge pull request #113 from sommersoft/cporg_issue_labels
Cirpy.org: Add Label Data to Issues
2 parents b2f6591 + fed3de3 commit 8bf52d0

File tree

1 file changed

+13
-75
lines changed

1 file changed

+13
-75
lines changed

adabot/update_cp_org_libraries.py

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121
# THE SOFTWARE.
2222

2323
import argparse
24-
import base64
2524
import datetime
2625
import inspect
2726
import json
2827
import os
2928
import re
30-
import sh
31-
from sh.contrib import git
32-
import sys
3329

3430
from adabot.lib import common_funcs
3531
from adabot.lib import circuitpython_library_validators as cpy_vals
@@ -49,6 +45,7 @@
4945

5046
sort_re = re.compile("(?<=\(Open\s)(.+)(?=\sdays)")
5147

48+
5249
def get_open_issues_and_prs(repo):
5350
""" Retreive all of the open issues (minus pull requests) for the repo.
5451
"""
@@ -70,12 +67,23 @@ def get_open_issues_and_prs(repo):
7067
issue_title = "{0} (Open {1} days)".format(issue["title"],
7168
days_open.days)
7269
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)
7481
else:
7582
open_pull_requests.append({issue["html_url"]: issue_title})
7683

7784
return open_issues, open_pull_requests
7885

86+
7987
def get_contributors(repo):
8088
contributors = []
8189
reviewers = []
@@ -115,74 +123,6 @@ def get_contributors(repo):
115123

116124
return contributors, reviewers, merged_pr_count
117125

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-
186126

187127
if __name__ == "__main__":
188128
cmd_line_args = cmd_line_parser.parse_args()
@@ -192,7 +132,6 @@ def update_json_file(json_string):
192132
run_time = datetime.datetime.now()
193133

194134
working_directory = os.path.abspath(os.getcwd())
195-
#cp_org_dir = os.path.join(working_directory, ".cp_org")
196135

197136
startup_message = [
198137
"Run Date: {}".format(run_time.strftime("%d %B %Y, %I:%M%p"))
@@ -310,7 +249,6 @@ def update_json_file(json_string):
310249
}
311250
json_obj = json.dumps(build_json, indent=2)
312251

313-
#update_json_file(json_obj)
314252
if local_file_output:
315253
with open(output_filename, "w") as json_file:
316254
json.dump(build_json, json_file, indent=2)

0 commit comments

Comments
 (0)