1
1
#!/usr/bin/env python
2
2
"""Simple tools to query github.com and gather stats about issues.
3
3
4
- The tool is copied from IPython rev 59f77d02558ed9b42303d04a22c49a230f5c7159
4
+ To generate a report for IPython 2.0, run:
5
5
6
- To generate a report for Matplotlib 1.4.0, run:
7
-
8
- python github_stats.py --since-tag v1.3.0
6
+ python github_stats.py --milestone 2.0 --since-tag rel-1.0.0
9
7
"""
10
8
#-----------------------------------------------------------------------------
11
9
# Imports
@@ -97,25 +95,24 @@ def sorted_by_field(issues, field='closed_at', reverse=False):
97
95
98
96
99
97
def report (issues , show_urls = False ):
100
- """Summary report about a list of issues, printing number and title.
101
- """
102
- # titles may have unicode in them, so we must encode everything below
98
+ """Summary report about a list of issues, printing number and title."""
103
99
if show_urls :
104
100
for i in issues :
105
101
role = 'ghpull' if 'merged_at' in i else 'ghissue'
106
102
print (u'* :%s:`%d`: %s' % (role , i ['number' ],
107
- i ['title' ].replace (u'`' , u'\`' ). replace ( u'*' , u'\*' ). replace ( u'_' , u'\_ ' )))
103
+ i ['title' ].replace (u'`' , u'`` ' )))
108
104
else :
109
105
for i in issues :
110
- print (u'* %d: %s' % (i ['number' ], i ['title' ].replace (u'`' , u'\`' ). replace ( u'*' , u'\*' ). replace ( u'_' , u'\_ ' )))
106
+ print (u'* %d: %s' % (i ['number' ], i ['title' ].replace (u'`' , u'`` ' )))
111
107
112
108
#-----------------------------------------------------------------------------
113
109
# Main script
114
110
#-----------------------------------------------------------------------------
115
111
116
112
if __name__ == "__main__" :
117
113
# deal with unicode
118
- sys .stdout = codecs .getwriter ('utf8' )(sys .stdout )
114
+ if sys .version_info < (3 ,):
115
+ sys .stdout = codecs .getwriter ('utf8' )(sys .stdout )
119
116
120
117
# Whether to add reST urls for all issues in printout.
121
118
show_urls = True
@@ -130,9 +127,12 @@ def report(issues, show_urls=False):
130
127
parser .add_argument ('--days' , type = int ,
131
128
help = "The number of days of data to summarize (use this or --since-tag)."
132
129
)
133
- parser .add_argument ('--project' , type = str , default = "matplotlib/matplotlib " ,
130
+ parser .add_argument ('--project' , type = str , default = "ipython/ipython " ,
134
131
help = "The project to summarize."
135
132
)
133
+ parser .add_argument ('--links' , action = 'store_true' , default = False ,
134
+ help = "Include links to all closed Issues and PRs in the output."
135
+ )
136
136
137
137
opts = parser .parse_args ()
138
138
tag = opts .since_tag
@@ -142,9 +142,9 @@ def report(issues, show_urls=False):
142
142
since = datetime .utcnow () - timedelta (days = opts .days )
143
143
else :
144
144
if not tag :
145
- tag = check_output (['git' , 'describe' , '--abbrev=0' ]).strip ()
145
+ tag = check_output (['git' , 'describe' , '--abbrev=0' ]).strip (). decode ( 'utf8' )
146
146
cmd = ['git' , 'log' , '-1' , '--format=%ai' , tag ]
147
- tagday , tz = check_output (cmd ).strip ().rsplit (' ' , 1 )
147
+ tagday , tz = check_output (cmd ).strip ().decode ( 'utf8' ). rsplit (' ' , 1 )
148
148
since = datetime .strptime (tagday , "%Y-%m-%d %H:%M:%S" )
149
149
h = int (tz [1 :3 ])
150
150
m = int (tz [3 :])
@@ -185,11 +185,6 @@ def report(issues, show_urls=False):
185
185
print ()
186
186
since_day = since .strftime ("%Y/%m/%d" )
187
187
today = datetime .today ().strftime ("%Y/%m/%d" )
188
- print (".. _github-stats:" )
189
- print ()
190
- print ('Github stats' )
191
- print ('============' )
192
- print ()
193
188
print ("GitHub stats for %s - %s (tag: %s)" % (since_day , today , tag ))
194
189
print ()
195
190
print ("These lists are automatically generated, and may be incomplete or contain duplicates." )
@@ -215,17 +210,23 @@ def report(issues, show_urls=False):
215
210
all_authors .extend ([ u'* ' + a .split (' <' )[0 ] for a in with_email ])
216
211
unique_authors = sorted (set (all_authors ), key = lambda s : s .lower ())
217
212
213
+ print ("We closed %d issues and merged %d pull requests." % (n_issues , n_pulls ))
214
+ if milestone :
215
+ print ("The full list can be seen `on GitHub <https://github.com/%s/milestone/%s>`__"
216
+ % (project , milestone )
217
+ )
218
+
219
+ print ()
218
220
print ("The following %i authors contributed %i commits." % (len (unique_authors ), ncommits ))
219
221
print ()
220
222
print ('\n ' .join (unique_authors ))
221
223
222
- print ()
223
- print ("We closed %d issues and merged %d pull requests;\n "
224
- "this is the full list (generated with the script \n "
225
- ":file:`tools/github_stats.py`):" % (n_pulls , n_issues ))
226
- print ()
227
- print ('Pull Requests (%d):\n ' % n_pulls )
228
- report (pulls , show_urls )
229
- print ()
230
- print ('Issues (%d):\n ' % n_issues )
231
- report (issues , show_urls )
224
+ if opts .links :
225
+ print ()
226
+ print ("GitHub issues and pull requests:" )
227
+ print ()
228
+ print ('Pull Requests (%d):\n ' % n_pulls )
229
+ report (pulls , show_urls )
230
+ print ()
231
+ print ('Issues (%d):\n ' % n_issues )
232
+ report (issues , show_urls )
0 commit comments