Show More
@@ -32,6 +32,8 b' def get_issues(project="ipython/ipython", state="closed", pulls=False):' | |||||
32 | url = "https://api.github.com/repos/%s/%s?state=%s&per_page=%i" % (project, which, state, PER_PAGE) |
|
32 | url = "https://api.github.com/repos/%s/%s?state=%s&per_page=%i" % (project, which, state, PER_PAGE) | |
33 | return get_paged_request(url, headers=make_auth_header()) |
|
33 | return get_paged_request(url, headers=make_auth_header()) | |
34 |
|
34 | |||
|
35 | def round_hour(dt): | |||
|
36 | return dt.replace(minute=0,second=0,microsecond=0) | |||
35 |
|
37 | |||
36 | def _parse_datetime(s): |
|
38 | def _parse_datetime(s): | |
37 | """Parse dates in the format returned by the Github API.""" |
|
39 | """Parse dates in the format returned by the Github API.""" | |
@@ -68,26 +70,30 b' def split_pulls(all_issues, project="ipython/ipython"):' | |||||
68 |
|
70 | |||
69 |
|
71 | |||
70 |
|
72 | |||
71 | def issues_closed_since(period=timedelta(days=365), project="ipython/ipython"): |
|
73 | def issues_closed_since(period=timedelta(days=365), project="ipython/ipython", pulls=False): | |
72 | """Get all issues closed since a particular point in time. period |
|
74 | """Get all issues closed since a particular point in time. period | |
73 | can either be a datetime object, or a timedelta object. In the |
|
75 | can either be a datetime object, or a timedelta object. In the | |
74 | latter case, it is used as a time before the present. |
|
76 | latter case, it is used as a time before the present. | |
75 | """ |
|
77 | """ | |
76 |
|
78 | |||
77 | which = 'issues' |
|
79 | which = 'pulls' if pulls else 'issues' | |
78 |
|
80 | |||
79 | if isinstance(period, timedelta): |
|
81 | if isinstance(period, timedelta): | |
80 | since = datetime.now() - period |
|
82 | since = round_hour(datetime.utcnow() - period) | |
81 | else: |
|
83 | else: | |
82 | since = period |
|
84 | since = period | |
83 | url = "https://api.github.com/repos/%s/%s?state=closed&sort=updated&since=%s&per_page=%i" % (project, which, since.strftime(ISO8601), PER_PAGE) |
|
85 | url = "https://api.github.com/repos/%s/%s?state=closed&sort=updated&since=%s&per_page=%i" % (project, which, since.strftime(ISO8601), PER_PAGE) | |
84 | allclosed = get_paged_request(url, headers=make_auth_header()) |
|
86 | allclosed = get_paged_request(url, headers=make_auth_header()) | |
85 |
|
87 | |||
86 | issues, pulls = split_pulls(allclosed, project=project) |
|
88 | filtered = [ i for i in allclosed if _parse_datetime(i['closed_at']) > since ] | |
87 | issues = [i for i in issues if _parse_datetime(i['closed_at']) > since] |
|
89 | if pulls: | |
88 |
|
|
90 | filtered = [ i for i in filtered if _parse_datetime(i['merged_at']) > since ] | |
|
91 | # filter out PRs not against master (backports) | |||
|
92 | filtered = [ i for i in filtered if i['base']['ref'] == 'master' ] | |||
|
93 | else: | |||
|
94 | filtered = [ i for i in filtered if not is_pull_request(i) ] | |||
89 |
|
95 | |||
90 |
return |
|
96 | return filtered | |
91 |
|
97 | |||
92 |
|
98 | |||
93 | def sorted_by_field(issues, field='closed_at', reverse=False): |
|
99 | def sorted_by_field(issues, field='closed_at', reverse=False): | |
@@ -113,6 +119,10 b' def report(issues, show_urls=False):' | |||||
113 | #----------------------------------------------------------------------------- |
|
119 | #----------------------------------------------------------------------------- | |
114 |
|
120 | |||
115 | if __name__ == "__main__": |
|
121 | if __name__ == "__main__": | |
|
122 | # deal with unicode | |||
|
123 | import codecs | |||
|
124 | sys.stdout = codecs.getwriter('utf8')(sys.stdout) | |||
|
125 | ||||
116 | # Whether to add reST urls for all issues in printout. |
|
126 | # Whether to add reST urls for all issues in printout. | |
117 | show_urls = True |
|
127 | show_urls = True | |
118 |
|
128 | |||
@@ -129,15 +139,25 b' if __name__ == "__main__":' | |||||
129 | if tag: |
|
139 | if tag: | |
130 | cmd = ['git', 'log', '-1', '--format=%ai', tag] |
|
140 | cmd = ['git', 'log', '-1', '--format=%ai', tag] | |
131 | tagday, tz = check_output(cmd).strip().rsplit(' ', 1) |
|
141 | tagday, tz = check_output(cmd).strip().rsplit(' ', 1) | |
132 |
since = datetime.strptime(tagday, "%Y-%m-%d %H:%M:%S") |
|
142 | since = datetime.strptime(tagday, "%Y-%m-%d %H:%M:%S") | |
|
143 | h = int(tz[1:3]) | |||
|
144 | m = int(tz[3:]) | |||
|
145 | td = timedelta(hours=h, minutes=m) | |||
|
146 | if tz[0] == '-': | |||
|
147 | since += td | |||
|
148 | else: | |||
|
149 | since -= td | |||
133 | else: |
|
150 | else: | |
134 | since = datetime.now() - timedelta(days=days) |
|
151 | since = datetime.utcnow() - timedelta(days=days) | |
|
152 | ||||
|
153 | since = round_hour(since) | |||
135 |
|
154 | |||
136 | print("fetching GitHub stats since %s (tag: %s)" % (since, tag), file=sys.stderr) |
|
155 | print("fetching GitHub stats since %s (tag: %s)" % (since, tag), file=sys.stderr) | |
137 | # turn off to play interactively without redownloading, use %run -i |
|
156 | # turn off to play interactively without redownloading, use %run -i | |
138 | if 1: |
|
157 | if 1: | |
139 |
issues |
|
158 | issues = issues_closed_since(since, pulls=False) | |
140 |
|
159 | pulls = issues_closed_since(since, pulls=True) | ||
|
160 | ||||
141 | # For regular reports, it's nice to show them in reverse chronological order |
|
161 | # For regular reports, it's nice to show them in reverse chronological order | |
142 | issues = sorted_by_field(issues, reverse=True) |
|
162 | issues = sorted_by_field(issues, reverse=True) | |
143 | pulls = sorted_by_field(pulls, reverse=True) |
|
163 | pulls = sorted_by_field(pulls, reverse=True) | |
@@ -146,6 +166,7 b' if __name__ == "__main__":' | |||||
146 | n_total = n_issues + n_pulls |
|
166 | n_total = n_issues + n_pulls | |
147 |
|
167 | |||
148 | # Print summary report we can directly include into release notes. |
|
168 | # Print summary report we can directly include into release notes. | |
|
169 | ||||
149 | print() |
|
170 | print() | |
150 | since_day = since.strftime("%Y/%m/%d") |
|
171 | since_day = since.strftime("%Y/%m/%d") | |
151 | today = datetime.today().strftime("%Y/%m/%d") |
|
172 | today = datetime.today().strftime("%Y/%m/%d") | |
@@ -159,10 +180,9 b' if __name__ == "__main__":' | |||||
159 | cmd = ['git', 'log', '--oneline', since_tag] |
|
180 | cmd = ['git', 'log', '--oneline', since_tag] | |
160 | ncommits = len(check_output(cmd).splitlines()) |
|
181 | ncommits = len(check_output(cmd).splitlines()) | |
161 |
|
182 | |||
162 | author_cmd = ['git', 'log', '--format=* %aN', since_tag] |
|
183 | author_cmd = ['git', 'log', '--use-mailmap', "--format='* %aN'", since_tag] | |
163 | all_authors = check_output(author_cmd).splitlines() |
|
184 | all_authors = check_output(author_cmd).decode('utf-8', 'replace').splitlines() | |
164 | unique_authors = sorted(set(all_authors)) |
|
185 | unique_authors = sorted(set(all_authors), key=lambda s: s.lower()) | |
165 |
|
||||
166 | print("The following %i authors contributed %i commits." % (len(unique_authors), ncommits)) |
|
186 | print("The following %i authors contributed %i commits." % (len(unique_authors), ncommits)) | |
167 | print() |
|
187 | print() | |
168 | print('\n'.join(unique_authors)) |
|
188 | print('\n'.join(unique_authors)) |
General Comments 0
You need to be logged in to leave comments.
Login now