Skip to content

Instantly share code, notes, and snippets.

@juandebravo
Created March 26, 2023 20:23
Show Gist options
  • Save juandebravo/d15af79876e23e2c23c45af978004260 to your computer and use it in GitHub Desktop.
Save juandebravo/d15af79876e23e2c23c45af978004260 to your computer and use it in GitHub Desktop.
Chat GPT information about Pull Requests opened in the last 6 months using Pygithub, matplotlib and numpy
from github import Github
import datetime
import matplotlib.pyplot as plt
import numpy as np
# Your GitHub access token
ACCESS_TOKEN = 'your-access-token-here'
# Create a Github instance using an access token
g = Github(ACCESS_TOKEN)
# Get the repository
repo = g.get_repo("owner/repo")
# Get the time 6 months ago
six_months_ago = datetime.datetime.now() - datetime.timedelta(days=180)
# Get the pulls in the last 6 months
pulls = repo.get_pulls(state='all', base='main')
merged_dates = []
merged_hours_list = []
# Iterate over the pulls and calculate the time to merge in hours
for pull in pulls:
if pull.merged_at is not None and pull.created_at > six_months_ago:
merged_time = pull.merged_at - pull.created_at
merged_hours = merged_time.total_seconds() / 3600 # convert seconds to hours
merged_dates.append(pull.created_at.date())
merged_hours_list.append(merged_hours)
# Get the unique dates in the list of merged_dates
date_list = np.unique(merged_dates)
# Create the bar chart
fig, ax = plt.subplots(figsize=(12, 6))
ax.set_xlabel('Date')
ax.set_ylabel('Time to Merge (hours)')
ax.set_title('Time to Merge Pull Requests')
ax.tick_params(axis='x', labelrotation=45)
# Iterate over the unique dates and calculate the mean time to merge for each date
for date in date_list:
filtered_merged_hours_list = [merged_hours for merged_hours, merged_date in zip(merged_hours_list, merged_dates) if merged_date == date]
mean_merged_hours = np.mean(filtered_merged_hours_list) if filtered_merged_hours_list else 0
ax.bar(date, mean_merged_hours, color='blue')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment