From 654803650779d5a6c24d346a693f9c3929f5eee1 2015-01-30 21:11:02 From: Min RK Date: 2015-01-30 21:11:02 Subject: [PATCH] tweaks to GitHub stats script - unicode / py3 fixes - don't build GitHub links unless `--links` is given (link to milestone page, instead) --- diff --git a/tools/github_stats.py b/tools/github_stats.py index 75604d9..a122b3f 100755 --- a/tools/github_stats.py +++ b/tools/github_stats.py @@ -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' @@ -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 @@ -131,6 +130,9 @@ if __name__ == "__main__": 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 @@ -140,9 +142,9 @@ if __name__ == "__main__": 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:]) @@ -208,17 +210,23 @@ if __name__ == "__main__": 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 `" + % (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)