Skip to content

Commit

Permalink
Merge pull request #219 from Neradoc/get-all-merged-and-authors
Browse files Browse the repository at this point in the history
Statistics: retrieve all merged commits and authors
  • Loading branch information
tannewt authored Apr 7, 2021
2 parents a6c2669 + 5cc4f13 commit 41b2432
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions adabot/lib/circuitpython_library_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,37 @@ def validate_core_driver_page(self, repo):
return []


def github_get_all_pages(self, url, params):
results = []
response = github.get(url, params=params)

if not response.ok:
# set error message and return ERROR_OUTPUT_HANDLER
# the caller must test and forward to the outside
self.output_file_data.append("Github request failed: {}, {}".format(repo["full_name"], link))
return ERROR_OUTPUT_HANDLER

while response.ok:
results.extend(response.json())
try:
links = response.headers["Link"]
except KeyError:
break

if links:
next_url = None
for link in links.split(","):
link, rel = link.split(";")
link = link.strip(" <>")
rel = rel.strip()
if rel == "rel=\"next\"":
next_url = link
break
if not next_url:
break
response = github.get(link)
return results


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

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

issues = []
params = {"state": "open", "per_page": 100}
response = github.get("/repos/" + repo["full_name"] + "/issues", params=params)
if not response.ok:
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
self.output_file_data.append("Issues request failed: {}".format(repo["full_name"]))
issues = self.github_get_all_pages("/repos/" + repo["full_name"] + "/issues", params=params)
if issues == ERROR_OUTPUT_HANDLER:
return [ERROR_OUTPUT_HANDLER]

while response.ok:
issues.extend(response.json())
try:
links = response.headers["Link"]
except KeyError:
break

if links:
next_url = None
for link in links.split(","):
link, rel = link.split(";")
link = link.strip(" <>")
rel = rel.strip()
if rel == "rel=\"next\"":
next_url = link
break
if not next_url:
break
response = requests.get(link, timeout=30)

for issue in issues:
created = datetime.datetime.strptime(issue["created_at"], "%Y-%m-%dT%H:%M:%SZ")
days_open = datetime.datetime.today() - created
Expand Down

0 comments on commit 41b2432

Please sign in to comment.