Skip to content

Instantly share code, notes, and snippets.

@juandebravo
Last active March 26, 2023 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandebravo/abef866d259d610d987a9f3e08551210 to your computer and use it in GitHub Desktop.
Save juandebravo/abef866d259d610d987a9f3e08551210 to your computer and use it in GitHub Desktop.
Chat GPT answer when I asked it to plot daily information about Pull Requests opened in a github repo
from github import Github
import datetime
import matplotlib.pyplot as plt
# Access the GitHub API using a personal access token
g = Github("<personal_access_token>")
# Replace <repository_owner> and <repository_name> with the owner and name of the repository
repo = g.get_repo("<repository_owner>/<repository_name>")
# Set the date to filter pull requests by
date_to_filter = datetime.datetime(2023, 3, 25) # Replace with the date you want to filter by
# Get all pull requests created on the specified date
pull_requests = repo.get_pulls(state='all',
sort='created',
direction='desc',
base='master',
since=date_to_filter,
until=date_to_filter + datetime.timedelta(days=1))
# Create lists to hold the pull request numbers and their corresponding times to merge
pull_request_numbers = []
times_to_merge = []
# Iterate over each pull request and calculate the time to merge
for pull_request in pull_requests:
if pull_request.merged:
# Get the date and time the pull request was opened
pr_created_at = pull_request.created_at
# Get the date and time the pull request was merged
pr_merged_at = pull_request.merged_at
# Calculate the time between the pull request being opened and it being merged
time_to_merge = (pr_merged_at - pr_created_at).total_seconds() / 3600 # convert to hours
# Append the pull request number and time to merge to the corresponding lists
pull_request_numbers.append(pull_request.number)
times_to_merge.append(time_to_merge)
else:
print("Pull Request #{} - Not merged yet".format(pull_request.number))
# Plot the times to merge as a bar chart
fig, ax = plt.subplots()
ax.bar(pull_request_numbers, times_to_merge)
# Set the x-axis and y-axis labels
ax.set_xlabel('Pull Request Number')
ax.set_ylabel('Time to Merge (hours)')
# Set the chart title
ax.set_title('Time to Merge for Pull Requests Opened on {}'.format(date_to_filter.date()))
# Show the chart
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment