Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find all the closed unmerged PRs for a given repository and count their total lines of code
# For a given repository this script iterates over all closed PRs
# and sums up the total number of lines of code from unmerged PRs
# that had been proposed to be added and deleted.
# This script requires installing a dependency: pip install PyGithub
from github import Github
import time
import sys
# Visual progress bar since this script takes ~1 second per PR to run
def progress(count, total):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percent = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s\r' % (bar, percent, '%'))
sys.stdout.flush()
# Authenticate and query for closed PRs in a given repository
g = Github("yourGithubTokenGoesHere")
repo = g.get_repo("bitcoin/bitcoin")
pulls = repo.get_pulls(state='closed', base='master')
# Variables for which we want to keep track
count = 0
totalCount = pulls.totalCount
unmergedPRCount = 0
totalAdditions = 0
totalDeletions = 0
for pr in pulls:
if (pr.merged == False):
unmergedPRCount += 1
totalAdditions += pr.additions
totalDeletions += pr.deletions
# Slow down if we are approaching the hourly query limit
if (int(pr._headers["x-ratelimit-remaining"]) < 600):
time.sleep(6)
count += 1
progress(count, totalCount)
print("Found " + str(unmergedPRCount) + " unmerged closed PRs")
print(str(totalAdditions) + " total added lines of code")
print(str(totalDeletions) + " total deleted lines of code")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.