Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 self.repo_url = repo_url | 37 self.repo_url = repo_url |
| 38 if self.repo_url.endswith('/'): | 38 if self.repo_url.endswith('/'): |
| 39 self.repo_url = self.repo_url[:-1] | 39 self.repo_url = self.repo_url[:-1] |
| 40 self.http_client = http_client | 40 self.http_client = http_client |
| 41 | 41 |
| 42 @property | 42 @property |
| 43 def identifier(self): | 43 def identifier(self): |
| 44 return self.repo_url | 44 return self.repo_url |
| 45 | 45 |
| 46 @Cached(namespace='Gitiles-json-view', expire_time=CACHE_EXPIRE_TIME_SECONDS) | 46 @Cached(namespace='Gitiles-json-view', expire_time=CACHE_EXPIRE_TIME_SECONDS) |
| 47 def _SendRequestForJsonResponse(self, url, params=None): | 47 def _SendRequestForJsonResponse(self, url, params=None, headers=None): |
|
stgao
2016/05/05 21:02:47
It seems not clean for the GitRepository to know a
Sharu Jiang
2016/05/05 23:03:45
Done.
| |
| 48 if params is None: # pragma: no cover | 48 if params is None: # pragma: no cover |
| 49 params = {} | 49 params = {} |
| 50 params['format'] = 'json' | 50 params['format'] = 'json' |
| 51 | 51 |
| 52 # Gerrit prepends )]}' to json-formatted response. | 52 # Gerrit prepends )]}' to json-formatted response. |
| 53 prefix = ')]}\'\n' | 53 prefix = ')]}\'\n' |
| 54 | 54 |
| 55 status_code, content = self.http_client.Get(url, params) | 55 status_code, content = self.http_client.Get(url, params, headers=headers) |
| 56 if status_code != 200: | 56 if status_code != 200: |
| 57 return None | 57 return None |
| 58 elif not content or not content.startswith(prefix): | 58 elif not content or not content.startswith(prefix): |
| 59 raise Exception('Response does not begin with %s' % prefix) | 59 raise Exception('Response does not begin with %s' % prefix) |
| 60 | 60 |
| 61 return json.loads(content[len(prefix):]) | 61 return json.loads(content[len(prefix):]) |
| 62 | 62 |
| 63 @Cached(namespace='Gitiles-text-view', expire_time=CACHE_EXPIRE_TIME_SECONDS) | 63 @Cached(namespace='Gitiles-text-view', expire_time=CACHE_EXPIRE_TIME_SECONDS) |
| 64 def _SendRequestForTextResponse(self, url): | 64 def _SendRequestForTextResponse(self, url, headers=None): |
| 65 status_code, content = self.http_client.Get(url, {'format': 'text'}) | 65 status_code, content = self.http_client.Get(url, {'format': 'text'}, |
| 66 headers=headers) | |
| 66 if status_code != 200: | 67 if status_code != 200: |
| 67 return None | 68 return None |
| 68 return base64.b64decode(content) | 69 return base64.b64decode(content) |
| 69 | 70 |
| 70 def ExtractCommitPositionAndCodeReviewUrl(self, message): | 71 def ExtractCommitPositionAndCodeReviewUrl(self, message): |
| 71 """Returns the commit position and code review url in the commit message. | 72 """Returns the commit position and code review url in the commit message. |
| 72 | 73 |
| 73 Returns: | 74 Returns: |
| 74 (commit_position, code_review_url) | 75 (commit_position, code_review_url) |
| 75 """ | 76 """ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 changelogs = [] | 251 changelogs = [] |
| 251 | 252 |
| 252 for revision in revisions: | 253 for revision in revisions: |
| 253 changelog = self.GetChangeLog(revision) | 254 changelog = self.GetChangeLog(revision) |
| 254 if not changelog: | 255 if not changelog: |
| 255 raise Exception('Failed to pull changelog for revision %s' % revision) | 256 raise Exception('Failed to pull changelog for revision %s' % revision) |
| 256 | 257 |
| 257 changelogs.append(changelog) | 258 changelogs.append(changelog) |
| 258 | 259 |
| 259 return changelogs | 260 return changelogs |
| 261 | |
| 262 def GetRevisionForChromeVersion(self, version): | |
| 263 """Gets the githash revision of a chrome version.""" | |
| 264 changelog = self.GetChangeLog(version) | |
| 265 if not changelog: | |
| 266 return None | |
| 267 | |
| 268 return changelog.revision | |
| OLD | NEW |