Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 344e013

Browse files
committed
MNT: update vendored gh scripts from IPython
Copied from IPython commit 058dda2a8cfc39eaa2541300f577af95f2f407e5 Not bothering to customize the script, leaving IPython specific documentation
1 parent fce685e commit 344e013

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

tools/gh_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def get_pull_request(project, num, auth=False):
103103
header = make_auth_header()
104104
else:
105105
header = None
106+
print("fetching %s" % url, file=sys.stderr)
106107
response = requests.get(url, headers=header)
107108
response.raise_for_status()
108109
return json.loads(response.text, object_hook=Obj)
@@ -161,6 +162,7 @@ def get_issues_list(project, auth=False, **params):
161162
return pages
162163

163164
def get_milestones(project, auth=False, **params):
165+
params.setdefault('state', 'all')
164166
url = "https://api.github.com/repos/{project}/milestones".format(project=project)
165167
if auth:
166168
headers = make_auth_header()

tools/github_stats.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/usr/bin/env python
22
"""Simple tools to query github.com and gather stats about issues.
33
4-
The tool is copied from IPython rev 59f77d02558ed9b42303d04a22c49a230f5c7159
4+
To generate a report for IPython 2.0, run:
55
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
97
"""
108
#-----------------------------------------------------------------------------
119
# Imports
@@ -97,25 +95,24 @@ def sorted_by_field(issues, field='closed_at', reverse=False):
9795

9896

9997
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."""
10399
if show_urls:
104100
for i in issues:
105101
role = 'ghpull' if 'merged_at' in i else 'ghissue'
106102
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'``')))
108104
else:
109105
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'``')))
111107

112108
#-----------------------------------------------------------------------------
113109
# Main script
114110
#-----------------------------------------------------------------------------
115111

116112
if __name__ == "__main__":
117113
# 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)
119116

120117
# Whether to add reST urls for all issues in printout.
121118
show_urls = True
@@ -130,9 +127,12 @@ def report(issues, show_urls=False):
130127
parser.add_argument('--days', type=int,
131128
help="The number of days of data to summarize (use this or --since-tag)."
132129
)
133-
parser.add_argument('--project', type=str, default="matplotlib/matplotlib",
130+
parser.add_argument('--project', type=str, default="ipython/ipython",
134131
help="The project to summarize."
135132
)
133+
parser.add_argument('--links', action='store_true', default=False,
134+
help="Include links to all closed Issues and PRs in the output."
135+
)
136136

137137
opts = parser.parse_args()
138138
tag = opts.since_tag
@@ -142,9 +142,9 @@ def report(issues, show_urls=False):
142142
since = datetime.utcnow() - timedelta(days=opts.days)
143143
else:
144144
if not tag:
145-
tag = check_output(['git', 'describe', '--abbrev=0']).strip()
145+
tag = check_output(['git', 'describe', '--abbrev=0']).strip().decode('utf8')
146146
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)
148148
since = datetime.strptime(tagday, "%Y-%m-%d %H:%M:%S")
149149
h = int(tz[1:3])
150150
m = int(tz[3:])
@@ -185,11 +185,6 @@ def report(issues, show_urls=False):
185185
print()
186186
since_day = since.strftime("%Y/%m/%d")
187187
today = datetime.today().strftime("%Y/%m/%d")
188-
print(".. _github-stats:")
189-
print()
190-
print('Github stats')
191-
print('============')
192-
print()
193188
print("GitHub stats for %s - %s (tag: %s)" % (since_day, today, tag))
194189
print()
195190
print("These lists are automatically generated, and may be incomplete or contain duplicates.")
@@ -215,17 +210,23 @@ def report(issues, show_urls=False):
215210
all_authors.extend([ u'* ' + a.split(' <')[0] for a in with_email ])
216211
unique_authors = sorted(set(all_authors), key=lambda s: s.lower())
217212

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()
218220
print("The following %i authors contributed %i commits." % (len(unique_authors), ncommits))
219221
print()
220222
print('\n'.join(unique_authors))
221223

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

Comments
 (0)