Skip to content

Commit 41b2432

Browse files
authored
Merge pull request #219 from Neradoc/get-all-merged-and-authors
Statistics: retrieve all merged commits and authors
2 parents a6c2669 + 5cc4f13 commit 41b2432

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

adabot/lib/circuitpython_library_validators.py

+36-30
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,37 @@ def validate_core_driver_page(self, repo):
925925
return []
926926

927927

928+
def github_get_all_pages(self, url, params):
929+
results = []
930+
response = github.get(url, params=params)
931+
932+
if not response.ok:
933+
# set error message and return ERROR_OUTPUT_HANDLER
934+
# the caller must test and forward to the outside
935+
self.output_file_data.append("Github request failed: {}, {}".format(repo["full_name"], link))
936+
return ERROR_OUTPUT_HANDLER
937+
938+
while response.ok:
939+
results.extend(response.json())
940+
try:
941+
links = response.headers["Link"]
942+
except KeyError:
943+
break
944+
945+
if links:
946+
next_url = None
947+
for link in links.split(","):
948+
link, rel = link.split(";")
949+
link = link.strip(" <>")
950+
rel = rel.strip()
951+
if rel == "rel=\"next\"":
952+
next_url = link
953+
break
954+
if not next_url:
955+
break
956+
response = github.get(link)
957+
return results
958+
928959

929960
def gather_insights(self, repo, insights, since, show_closed_metric=False):
930961
"""Gather analytics about a repository like open and merged pull requests.
@@ -937,14 +968,12 @@ def gather_insights(self, repo, insights, since, show_closed_metric=False):
937968
return []
938969
params = {"sort": "updated",
939970
"state": "all",
971+
"per_page": 100,
940972
"since": since.strftime("%Y-%m-%dT%H:%M:%SZ")}
941-
response = github.get("/repos/" + repo["full_name"] + "/issues", params=params)
942-
if not response.ok:
943-
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
944-
self.output_file_data.append("Insights request failed: {}".format(repo["full_name"]))
973+
issues = self.github_get_all_pages("/repos/" + repo["full_name"] + "/issues", params=params)
974+
if issues == ERROR_OUTPUT_HANDLER:
945975
return [ERROR_OUTPUT_HANDLER]
946976

947-
issues = response.json()
948977
for issue in issues:
949978
created = datetime.datetime.strptime(issue["created_at"], "%Y-%m-%dT%H:%M:%SZ")
950979
if "pull_request" in issue:
@@ -1017,34 +1046,11 @@ def gather_insights(self, repo, insights, since, show_closed_metric=False):
10171046
insights["closed_issues"] += 1
10181047
insights["issue_closers"].add(issue_info["closed_by"]["login"])
10191048

1020-
issues = []
10211049
params = {"state": "open", "per_page": 100}
1022-
response = github.get("/repos/" + repo["full_name"] + "/issues", params=params)
1023-
if not response.ok:
1024-
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
1025-
self.output_file_data.append("Issues request failed: {}".format(repo["full_name"]))
1050+
issues = self.github_get_all_pages("/repos/" + repo["full_name"] + "/issues", params=params)
1051+
if issues == ERROR_OUTPUT_HANDLER:
10261052
return [ERROR_OUTPUT_HANDLER]
10271053

1028-
while response.ok:
1029-
issues.extend(response.json())
1030-
try:
1031-
links = response.headers["Link"]
1032-
except KeyError:
1033-
break
1034-
1035-
if links:
1036-
next_url = None
1037-
for link in links.split(","):
1038-
link, rel = link.split(";")
1039-
link = link.strip(" <>")
1040-
rel = rel.strip()
1041-
if rel == "rel=\"next\"":
1042-
next_url = link
1043-
break
1044-
if not next_url:
1045-
break
1046-
response = requests.get(link, timeout=30)
1047-
10481054
for issue in issues:
10491055
created = datetime.datetime.strptime(issue["created_at"], "%Y-%m-%dT%H:%M:%SZ")
10501056
days_open = datetime.datetime.today() - created

0 commit comments

Comments
 (0)