| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 from datetime import datetime | 6 from datetime import datetime |
| 7 from datetime import timedelta | 7 from datetime import timedelta |
| 8 import json | 8 import json |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 def _GetDateTimeFromString(self, datetime_string, | 80 def _GetDateTimeFromString(self, datetime_string, |
| 81 date_format='%a %b %d %H:%M:%S %Y'): | 81 date_format='%a %b %d %H:%M:%S %Y'): |
| 82 if TIMEZONE_PATTERN.findall(datetime_string): | 82 if TIMEZONE_PATTERN.findall(datetime_string): |
| 83 # Need to handle timezone conversion. | 83 # Need to handle timezone conversion. |
| 84 naive_datetime_str, _, offset_str = datetime_string.rpartition(' ') | 84 naive_datetime_str, _, offset_str = datetime_string.rpartition(' ') |
| 85 naive_datetime = datetime.strptime(naive_datetime_str, date_format) | 85 naive_datetime = datetime.strptime(naive_datetime_str, date_format) |
| 86 return TimeZoneInfo(offset_str).LocalToUTC(naive_datetime) | 86 return TimeZoneInfo(offset_str).LocalToUTC(naive_datetime) |
| 87 | 87 |
| 88 return datetime.strptime(datetime_string, date_format) | 88 return datetime.strptime(datetime_string, date_format) |
| 89 | 89 |
| 90 def _DownloadChangeLogData(self, revision): | |
| 91 url = '%s/+/%s' % (self.repo_url, revision) | |
| 92 return url, self._SendRequestForJsonResponse(url) | |
| 93 | |
| 94 def _ParseChangeLogFromLogData(self, data): | 90 def _ParseChangeLogFromLogData(self, data): |
| 95 commit_position, code_review_url = ( | 91 commit_position, code_review_url = ( |
| 96 commit_util.ExtractCommitPositionAndCodeReviewUrl(data['message'])) | 92 commit_util.ExtractCommitPositionAndCodeReviewUrl(data['message'])) |
| 97 | 93 |
| 98 touched_files = [] | 94 touched_files = [] |
| 99 for file_diff in data['tree_diff']: | 95 for file_diff in data['tree_diff']: |
| 100 change_type = file_diff['type'].lower() | 96 change_type = file_diff['type'].lower() |
| 101 if not diff.IsKnownChangeType(change_type): | 97 if not diff.IsKnownChangeType(change_type): |
| 102 raise Exception('Unknown change type "%s"' % change_type) | 98 raise Exception('Unknown change type "%s"' % change_type) |
| 103 touched_files.append( | 99 touched_files.append( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 commit_util.NormalizeEmail(data['author']['email']), | 110 commit_util.NormalizeEmail(data['author']['email']), |
| 115 author_time, | 111 author_time, |
| 116 data['committer']['name'], | 112 data['committer']['name'], |
| 117 commit_util.NormalizeEmail(data['committer']['email']), | 113 commit_util.NormalizeEmail(data['committer']['email']), |
| 118 committer_time, data['commit'], commit_position, | 114 committer_time, data['commit'], commit_position, |
| 119 data['message'], touched_files, url, code_review_url, | 115 data['message'], touched_files, url, code_review_url, |
| 120 reverted_revision) | 116 reverted_revision) |
| 121 | 117 |
| 122 def GetChangeLog(self, revision): | 118 def GetChangeLog(self, revision): |
| 123 """Returns the change log of the given revision.""" | 119 """Returns the change log of the given revision.""" |
| 124 _, data = self._DownloadChangeLogData(revision) | 120 url = '%s/+/%s' % (self.repo_url, revision) |
| 121 data = self._SendRequestForJsonResponse(url) |
| 125 if not data: | 122 if not data: |
| 126 return None | 123 return None |
| 127 | 124 |
| 128 return self._ParseChangeLogFromLogData(data) | 125 return self._ParseChangeLogFromLogData(data) |
| 129 | 126 |
| 130 def GetCommitsBetweenRevisions(self, start_revision, end_revision, n=1000): | 127 def GetCommitsBetweenRevisions(self, start_revision, end_revision, n=1000): |
| 131 """Gets a list of commit hashes between start_revision and end_revision. | 128 """Gets a list of commit hashes between start_revision and end_revision. |
| 132 | 129 |
| 133 Args: | 130 Args: |
| 134 start_revision: The oldest revision in the range. | 131 start_revision: The oldest revision in the range. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 212 |
| 216 for log in data['log']: | 213 for log in data['log']: |
| 217 changelogs.append(self._ParseChangeLogFromLogData(log)) | 214 changelogs.append(self._ParseChangeLogFromLogData(log)) |
| 218 | 215 |
| 219 if 'next' in data: | 216 if 'next' in data: |
| 220 next_end_revision = data['next'] | 217 next_end_revision = data['next'] |
| 221 else: | 218 else: |
| 222 next_end_revision = None | 219 next_end_revision = None |
| 223 | 220 |
| 224 return changelogs | 221 return changelogs |
| OLD | NEW |