Skip to content

Commit

Permalink
tweaks to GitHub stats script
Browse files Browse the repository at this point in the history
- unicode / py3 fixes
- don't build GitHub links unless `--links` is given
  (link to milestone page, instead)
  • Loading branch information
minrk committed Jan 30, 2015
1 parent bebab47 commit 6548036
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tools/github_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def sorted_by_field(issues, field='closed_at', reverse=False):


def report(issues, show_urls=False):
"""Summary report about a list of issues, printing number and title.
"""
# titles may have unicode in them, so we must encode everything below
"""Summary report about a list of issues, printing number and title."""
if show_urls:
for i in issues:
role = 'ghpull' if 'merged_at' in i else 'ghissue'
Expand All @@ -113,7 +111,8 @@ def report(issues, show_urls=False):

if __name__ == "__main__":
# deal with unicode
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
if sys.version_info < (3,):
sys.stdout = codecs.getwriter('utf8')(sys.stdout)

# Whether to add reST urls for all issues in printout.
show_urls = True
Expand All @@ -131,6 +130,9 @@ def report(issues, show_urls=False):
parser.add_argument('--project', type=str, default="ipython/ipython",
help="The project to summarize."
)
parser.add_argument('--links', action='store_true', default=False,
help="Include links to all closed Issues and PRs in the output."
)

opts = parser.parse_args()
tag = opts.since_tag
Expand All @@ -140,9 +142,9 @@ def report(issues, show_urls=False):
since = datetime.utcnow() - timedelta(days=opts.days)
else:
if not tag:
tag = check_output(['git', 'describe', '--abbrev=0']).strip()
tag = check_output(['git', 'describe', '--abbrev=0']).strip().decode('utf8')
cmd = ['git', 'log', '-1', '--format=%ai', tag]
tagday, tz = check_output(cmd).strip().rsplit(' ', 1)
tagday, tz = check_output(cmd).strip().decode('utf8').rsplit(' ', 1)
since = datetime.strptime(tagday, "%Y-%m-%d %H:%M:%S")
h = int(tz[1:3])
m = int(tz[3:])
Expand Down Expand Up @@ -208,17 +210,23 @@ def report(issues, show_urls=False):
all_authors.extend([ u'* ' + a.split(' <')[0] for a in with_email ])
unique_authors = sorted(set(all_authors), key=lambda s: s.lower())

print("We closed %d issues and merged %d pull requests." % (n_pulls, n_issues))
if milestone:
print("The full list can be seen `on GitHub <https://github.com/%s/milestone/%s>`"
% (project, milestone)
)

print()
print("The following %i authors contributed %i commits." % (len(unique_authors), ncommits))
print()
print('\n'.join(unique_authors))

print()
print("We closed %d issues and merged %d pull requests;\n"
"this is the full list (generated with the script \n"
":file:`tools/github_stats.py`):" % (n_pulls, n_issues))
print()
print('Pull Requests (%d):\n' % n_pulls)
report(pulls, show_urls)
print()
print('Issues (%d):\n' % n_issues)
report(issues, show_urls)
if opts.links:
print()
print("GitHub issues and pull requests:")
print()
print('Pull Requests (%d):\n' % n_pulls)
report(pulls, show_urls)
print()
print('Issues (%d):\n' % n_issues)
report(issues, show_urls)

0 comments on commit 6548036

Please sign in to comment.