OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
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 | 5 |
6 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '1.8.0' | 9 __version__ = '1.8.0' |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 output.write('\n***************\n') | 151 output.write('\n***************\n') |
152 # Write separately in case it's unicode. | 152 # Write separately in case it's unicode. |
153 output.write(self._long_text) | 153 output.write(self._long_text) |
154 output.write('\n***************\n') | 154 output.write('\n***************\n') |
155 if self.fatal: | 155 if self.fatal: |
156 output.fail() | 156 output.fail() |
157 | 157 |
158 | 158 |
159 # Top level object so multiprocessing can pickle | 159 # Top level object so multiprocessing can pickle |
160 # Public access through OutputApi object. | 160 # Public access through OutputApi object. |
161 class _PresubmitAddReviewers(_PresubmitResult): | |
162 """Add some suggested reviewers to the change.""" | |
163 def __init__(self, reviewers): | |
164 super(_PresubmitAddReviewers, self).__init__('') | |
165 self.reviewers = reviewers | |
166 | |
167 def handle(self, output): | |
168 output.reviewers.extend(self.reviewers) | |
169 | |
170 | |
171 # Top level object so multiprocessing can pickle | |
172 # Public access through OutputApi object. | |
173 class _PresubmitError(_PresubmitResult): | 161 class _PresubmitError(_PresubmitResult): |
174 """A hard presubmit error.""" | 162 """A hard presubmit error.""" |
175 fatal = True | 163 fatal = True |
176 | 164 |
177 | 165 |
178 # Top level object so multiprocessing can pickle | 166 # Top level object so multiprocessing can pickle |
179 # Public access through OutputApi object. | 167 # Public access through OutputApi object. |
180 class _PresubmitPromptWarning(_PresubmitResult): | 168 class _PresubmitPromptWarning(_PresubmitResult): |
181 """An warning that prompts the user if they want to continue.""" | 169 """An warning that prompts the user if they want to continue.""" |
182 should_prompt = True | 170 should_prompt = True |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 return [r['email'] | 251 return [r['email'] |
264 for r in self.GetChangeInfo(issue)['labels']['Code-Review']['all'] | 252 for r in self.GetChangeInfo(issue)['labels']['Code-Review']['all'] |
265 if not approving_only or '2' == str(r.get('value', 0))] | 253 if not approving_only or '2' == str(r.get('value', 0))] |
266 | 254 |
267 | 255 |
268 class OutputApi(object): | 256 class OutputApi(object): |
269 """An instance of OutputApi gets passed to presubmit scripts so that they | 257 """An instance of OutputApi gets passed to presubmit scripts so that they |
270 can output various types of results. | 258 can output various types of results. |
271 """ | 259 """ |
272 PresubmitResult = _PresubmitResult | 260 PresubmitResult = _PresubmitResult |
273 PresubmitAddReviewers = _PresubmitAddReviewers | |
274 PresubmitError = _PresubmitError | 261 PresubmitError = _PresubmitError |
275 PresubmitPromptWarning = _PresubmitPromptWarning | 262 PresubmitPromptWarning = _PresubmitPromptWarning |
276 PresubmitNotifyResult = _PresubmitNotifyResult | 263 PresubmitNotifyResult = _PresubmitNotifyResult |
277 MailTextResult = _MailTextResult | 264 MailTextResult = _MailTextResult |
278 | 265 |
279 def __init__(self, is_committing): | 266 def __init__(self, is_committing): |
280 self.is_committing = is_committing | 267 self.is_committing = is_committing |
281 | 268 |
282 def PresubmitPromptOrNotify(self, *args, **kwargs): | 269 def PresubmitPromptOrNotify(self, *args, **kwargs): |
283 """Warn the user when uploading, but only notify if committing.""" | 270 """Warn the user when uploading, but only notify if committing.""" |
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 return 2 | 1822 return 2 |
1836 | 1823 |
1837 | 1824 |
1838 if __name__ == '__main__': | 1825 if __name__ == '__main__': |
1839 fix_encoding.fix_encoding() | 1826 fix_encoding.fix_encoding() |
1840 try: | 1827 try: |
1841 sys.exit(main()) | 1828 sys.exit(main()) |
1842 except KeyboardInterrupt: | 1829 except KeyboardInterrupt: |
1843 sys.stderr.write('interrupted\n') | 1830 sys.stderr.write('interrupted\n') |
1844 sys.exit(1) | 1831 sys.exit(1) |
OLD | NEW |