OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
6 | 6 |
7 Security implications: | 7 Security implications: |
8 | 8 |
9 The following hypothesis are made: | 9 The following hypothesis are made: |
10 - Rietveld enforces: | 10 - Rietveld enforces: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 def get_issue_properties(self, issue, messages): | 78 def get_issue_properties(self, issue, messages): |
79 """Returns all the issue's metadata as a dictionary.""" | 79 """Returns all the issue's metadata as a dictionary.""" |
80 url = '/api/%d' % issue | 80 url = '/api/%d' % issue |
81 if messages: | 81 if messages: |
82 url += '?messages=true' | 82 url += '?messages=true' |
83 data = json.loads(self.get(url, retry_on_404=True)) | 83 data = json.loads(self.get(url, retry_on_404=True)) |
84 data['description'] = '\n'.join(data['description'].strip().splitlines()) | 84 data['description'] = '\n'.join(data['description'].strip().splitlines()) |
85 return data | 85 return data |
86 | 86 |
| 87 def get_depends_on_patchset(self, issue, patchset): |
| 88 """Returns the patchset this patchset depends on if it exists.""" |
| 89 url = '/%d/patchset/%d/get_depends_on_patchset' % (issue, patchset) |
| 90 resp = None |
| 91 try: |
| 92 resp = json.loads(self.get(url)) |
| 93 except (urllib2.HTTPError, ValueError): |
| 94 # The get_depends_on_patchset endpoint does not exist on this Rietveld |
| 95 # instance yet. Ignore the error and proceed. |
| 96 # TODO(rmistry): Make this an error when all Rietveld instances have |
| 97 # this endpoint. |
| 98 pass |
| 99 return resp |
| 100 |
87 def get_patchset_properties(self, issue, patchset): | 101 def get_patchset_properties(self, issue, patchset): |
88 """Returns the patchset properties.""" | 102 """Returns the patchset properties.""" |
89 url = '/api/%d/%d' % (issue, patchset) | 103 url = '/api/%d/%d' % (issue, patchset) |
90 return json.loads(self.get(url)) | 104 return json.loads(self.get(url)) |
91 | 105 |
92 def get_file_content(self, issue, patchset, item): | 106 def get_file_content(self, issue, patchset, item): |
93 """Returns the content of a new file. | 107 """Returns the content of a new file. |
94 | 108 |
95 Throws HTTP 302 exception if the file doesn't exist or is not a binary file. | 109 Throws HTTP 302 exception if the file doesn't exist or is not a binary file. |
96 """ | 110 """ |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 ReadOnlyRietveld._local_changes.setdefault(issue, {})['closed'] = True | 684 ReadOnlyRietveld._local_changes.setdefault(issue, {})['closed'] = True |
671 | 685 |
672 def get_issue_properties(self, issue, messages): | 686 def get_issue_properties(self, issue, messages): |
673 data = self._rietveld.get_issue_properties(issue, messages) | 687 data = self._rietveld.get_issue_properties(issue, messages) |
674 data.update(self._get_local_changes(issue)) | 688 data.update(self._get_local_changes(issue)) |
675 return data | 689 return data |
676 | 690 |
677 def get_patchset_properties(self, issue, patchset): | 691 def get_patchset_properties(self, issue, patchset): |
678 return self._rietveld.get_patchset_properties(issue, patchset) | 692 return self._rietveld.get_patchset_properties(issue, patchset) |
679 | 693 |
| 694 def get_depends_on_patchset(self, issue, patchset): |
| 695 return self._rietveld.get_depends_on_patchset(issue, patchset) |
| 696 |
680 def get_patch(self, issue, patchset): | 697 def get_patch(self, issue, patchset): |
681 return self._rietveld.get_patch(issue, patchset) | 698 return self._rietveld.get_patch(issue, patchset) |
682 | 699 |
683 def update_description(self, issue, description): # pylint:disable=R0201 | 700 def update_description(self, issue, description): # pylint:disable=R0201 |
684 logging.info('ReadOnlyRietveld: new description for issue %d: %s' % | 701 logging.info('ReadOnlyRietveld: new description for issue %d: %s' % |
685 (issue, description)) | 702 (issue, description)) |
686 | 703 |
687 def add_comment(self, # pylint:disable=R0201 | 704 def add_comment(self, # pylint:disable=R0201 |
688 issue, | 705 issue, |
689 message, | 706 message, |
(...skipping 10 matching lines...) Expand all Loading... |
700 self, issue, patchset, reason, clobber, revision, builders_and_tests, | 717 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
701 master=None, category='cq'): | 718 master=None, category='cq'): |
702 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 719 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
703 (builders_and_tests, issue)) | 720 (builders_and_tests, issue)) |
704 | 721 |
705 def trigger_distributed_try_jobs( # pylint:disable=R0201 | 722 def trigger_distributed_try_jobs( # pylint:disable=R0201 |
706 self, issue, patchset, reason, clobber, revision, masters, | 723 self, issue, patchset, reason, clobber, revision, masters, |
707 category='cq'): | 724 category='cq'): |
708 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 725 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
709 (masters, issue)) | 726 (masters, issue)) |
OLD | NEW |