Last active
May 26, 2023 17:08
-
-
Save mmusich/49977ad92dcfdecabff43da9b8ac5c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
import json | |
# Set the GitHub API endpoint and headers | |
api_url = "https://api.github.com" | |
headers = { | |
"Accept": "application/vnd.github.v3+json" | |
} | |
# Set the repository owner and name | |
repo_owner = "cms-sw" | |
repo_name = "cmssw" | |
# Set the label and the username of the "dqm" user | |
label = "dqm-approved" | |
dqm_user = "dqm_user" | |
# Set the start and end dates for the time range | |
start_date = datetime.datetime(2023, 1, 1) # Specify your desired start date | |
end_date = datetime.datetime(2023, 12, 31) # Specify your desired end date | |
# Construct the search query for PRs with the "dqm" label within the time range | |
search_query = f"repo:{repo_owner}/{repo_name} is:pr label:{label} is:closed created:{start_date.date()}..{end_date.date()}" | |
# Make the API request to search for matching PRs | |
page = 1 | |
pr_list = [] | |
while True: | |
response = requests.get(f"{api_url}/search/issues", params={"q": search_query, "page": page}, headers=headers) | |
data = response.json() | |
if "items" not in data: | |
break | |
pr_list.extend(data["items"]) | |
page += 1 | |
# Process the PRs and calculate the time to first sign by "dqm" | |
for pr in pr_list: | |
pr_number = pr["number"] | |
creation_time = datetime.datetime.strptime(pr["created_at"], "%Y-%m-%dT%H:%M:%SZ") | |
closure_time = datetime.datetime.strptime(pr["closed_at"], "%Y-%m-%dT%H:%M:%SZ") | |
#print(creation_time) | |
#print(closure_time) | |
print(f"PR #{pr_number}",pr["title"],"from",pr["user"]["login"]," took: ", closure_time-creation_time) | |
#print(f"PR #{pr_number}",pr["title"],"from",pr["user"]["login"]) | |
#pretty_json = json.dumps(pr, indent=4) | |
#print(pretty_json) | |
# Make the API request to get the PR details | |
#pr_response = requests.get(f"{api_url}/repos/{repo_owner}/{repo_name}/pulls/{pr_number}", headers=headers) | |
#pr_data = pr_response.json() | |
#print(pr_data) | |
# # Get the list of reviews for the PR | |
# reviews_response = requests.get(f"{api_url}/repos/{repo_owner}/{repo_name}/pulls/{pr_number}/reviews", headers=headers) | |
# reviews_data = reviews_response.json() | |
# # Find the first review from "dqm" and calculate the time to first sign | |
# first_sign_time = None | |
# for review in reviews_data: | |
# if review["user"]["login"] == dqm_user: | |
# first_sign_time = datetime.datetime.strptime(review["submitted_at"], "%Y-%m-%dT%H:%M:%SZ") | |
# break | |
# if first_sign_time: | |
# time_to_sign = first_sign_time - datetime.datetime.strptime(pr_data["created_at"], "%Y-%m-%dT%H:%M:%SZ") | |
# print(f"PR #{pr_number}: Time to first sign by 'dqm': {time_to_sign}") | |
# else: | |
# print(f"PR #{pr_number}: Not signed by 'dqm'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
import json | |
import matplotlib.pyplot as plt | |
def fill_time_histogram(listOfTimes, start_time, end_time): | |
# Calculate the time duration in minutes | |
time_delta = end_time - start_time | |
total_hours = time_delta.total_seconds() / (60 * 60) | |
print("took:",total_hours,"hours") | |
# Fill the histogram with the time duration | |
listOfTimes.append(total_hours) | |
# Set the GitHub API endpoint and headers | |
api_url = "https://api.github.com" | |
headers = { | |
"Accept": "application/vnd.github.v3+json" | |
} | |
# Set the repository owner and name | |
repo_owner = "cms-sw" | |
repo_name = "cmssw" | |
# Set the label and the username of the "dqm" user | |
label = "dqm-approved" | |
dqm_user = "dqm_user" | |
# Set the start and end dates for the time range | |
start_date = datetime.datetime(2023, 1, 1) # Specify your desired start date | |
end_date = datetime.datetime(2023, 12, 31) # Specify your desired end date | |
# Construct the search query for PRs with the "dqm" label within the time range | |
search_query = f"repo:{repo_owner}/{repo_name} is:pr label:{label} is:closed created:{start_date.date()}..{end_date.date()}" | |
# Make the API request to search for matching PRs | |
page = 1 | |
pr_list = [] | |
listOfTimes=[] | |
while True: | |
response = requests.get(f"{api_url}/search/issues", params={"q": search_query, "page": page}, headers=headers) | |
data = response.json() | |
if "items" not in data: | |
break | |
pr_list.extend(data["items"]) | |
page += 1 | |
# Process the PRs and calculate the time to first sign by "dqm" | |
for pr in pr_list: | |
pr_number = pr["number"] | |
creation_time = datetime.datetime.strptime(pr["created_at"], "%Y-%m-%dT%H:%M:%SZ") | |
closure_time = datetime.datetime.strptime(pr["closed_at"], "%Y-%m-%dT%H:%M:%SZ") | |
#print(creation_time) | |
#print(closure_time) | |
print(f"PR #{pr_number}",pr["title"],"from",pr["user"]["login"]," took: ", closure_time-creation_time) | |
# Fill the histogram with the time duration | |
fill_time_histogram(listOfTimes, creation_time, closure_time) | |
#print(f"PR #{pr_number}",pr["title"],"from",pr["user"]["login"]) | |
#pretty_json = json.dumps(pr, indent=4) | |
#print(pretty_json) | |
# Make the API request to get the PR details | |
#pr_response = requests.get(f"{api_url}/repos/{repo_owner}/{repo_name}/pulls/{pr_number}", headers=headers) | |
#pr_data = pr_response.json() | |
#print(pr_data) | |
# # Get the list of reviews for the PR | |
# reviews_response = requests.get(f"{api_url}/repos/{repo_owner}/{repo_name}/pulls/{pr_number}/reviews", headers=headers) | |
# reviews_data = reviews_response.json() | |
# # Find the first review from "dqm" and calculate the time to first sign | |
# first_sign_time = None | |
# for review in reviews_data: | |
# if review["user"]["login"] == dqm_user: | |
# first_sign_time = datetime.datetime.strptime(review["submitted_at"], "%Y-%m-%dT%H:%M:%SZ") | |
# break | |
# if first_sign_time: | |
# time_to_sign = first_sign_time - datetime.datetime.strptime(pr_data["created_at"], "%Y-%m-%dT%H:%M:%SZ") | |
# print(f"PR #{pr_number}: Time to first sign by 'dqm': {time_to_sign}") | |
# else: | |
# print(f"PR #{pr_number}: Not signed by 'dqm'") | |
# Display the histogram | |
# Create a histogram with suitable range and binning | |
hist, bins, _ = plt.hist(listOfTimes, bins=100, range=(0, 400)) | |
plt.xlabel('Time (hours)') | |
plt.ylabel('PR number') | |
plt.title('Time Duration Histogram') | |
# Save the figure as a PNG file | |
plt.savefig('histogram.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment