Created
December 21, 2023 07:34
-
-
Save koji/d7ac27d8e7e028bfc014718f913f94f0 to your computer and use it in GitHub Desktop.
count the prs you merged in 2023
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 json | |
import subprocess | |
# This script requires gh command if you don't have it, you need to install. | |
# Run the gh command and get the output | |
user_id = input('Enter your github id: ') | |
repo_owner = input('Enter repo owner: ') | |
repo = input('Enter repo name: ') | |
limit = input('Enter limit num: ') | |
limit = int(limit) | |
gh_command = f'gh pr list --repo {repo_owner}/{repo} --author {user_id} --state merged --json url,number,title,createdAt,additions,deletions --search "created:2023-01-01..2023-12-31" --limit {limit}' | |
gh_output = subprocess.check_output(gh_command, shell=True) | |
# Parse the JSON output | |
pr_data = json.loads(gh_output) | |
# Filter PRs by year and sort by additions | |
filtered_prs = [pr for pr in pr_data if pr['createdAt'].startswith('2023')] | |
sorted_prs = sorted(filtered_prs, key=lambda pr: pr['additions'], reverse=True) | |
# Calculate total additions and deletions | |
total_additions = sum(pr['additions'] for pr in sorted_prs) | |
total_deletions = sum(pr['deletions'] for pr in sorted_prs) | |
# Print the sorted PRs | |
# print(json.dumps(sorted_prs, indent=2)) | |
# Print the top 5 PRs with the most additions | |
print() | |
print(f'Your top 5 PR additions {repo_owner}/{repo}') | |
for i, pr in enumerate(sorted_prs[:5]): | |
print(f'PR #{i+1}:') | |
print(f'URL: {pr["url"]}') | |
print(f'Number: {pr["number"]}') | |
print(f'Title: {pr["title"]}') | |
print(f'Created at: {pr["createdAt"]}') | |
print(f'Additions: {pr["additions"]}') | |
print(f'Deletions: {pr["deletions"]}') | |
print() | |
# Print total additions and deletions | |
print(f'Total additions: {total_additions}') | |
print(f'Total deletions: {total_deletions}') | |
# Print total number of merged PRs | |
print(f'Total merged PRs: {len(sorted_prs)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment