import requests import time import json from datetime import datetime # Replace with your GitHub token and repository details token = '*********' owner = 'theorchard' repo = 'orchard' # Set the headers with the correct API version headers = { 'Authorization': f'token {token}', 'Accept': 'application/vnd.github+json', 'X-GitHub-API-Version': '2022-11-28' } # Make a request to get repository commit activity url = f'https://api.github.com/repos/{owner}/{repo}/stats/commit_activity' while True: response = requests.get(url, headers=headers) if response.status_code == 200: stats = response.json() total_commits = 0 monthly_commits = {} for entry in stats: week_start = datetime.utcfromtimestamp(entry['week']).strftime('%B %Y') total_commits += entry['total'] if week_start in monthly_commits: monthly_commits[week_start] += entry['total'] else: monthly_commits[week_start] = entry['total'] print(f"Summary Report for Repository: {repo}") print(f"Total Commits: {total_commits}") print("Monthly Commits:") for month, commits in monthly_commits.items(): print(f"{month}: {commits} commits") break elif response.status_code == 202: print("Statistics are being computed. Retrying in 10 seconds...") time.sleep(10) else: print(f"Error: {response.status_code}") print(response.json()) break