| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """An interface to git-cl. | 5 """An interface to git-cl. |
| 6 | 6 |
| 7 The git-cl tool is responsible for communicating with Rietveld, Gerrit, | 7 The git-cl tool is responsible for communicating with Rietveld, Gerrit, |
| 8 and Buildbucket to manage changelists and try jobs associated with them. | 8 and Buildbucket to manage changelists and try jobs associated with them. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import logging | |
| 12 import time | 11 import time |
| 13 | 12 |
| 14 _log = logging.getLogger(__name__) | |
| 15 | |
| 16 | 13 |
| 17 class GitCL(object): | 14 class GitCL(object): |
| 18 | 15 |
| 19 def __init__(self, executive, auth_refresh_token_json=None, cwd=None): | 16 def __init__(self, executive, auth_refresh_token_json=None, cwd=None): |
| 20 self._executive = executive | 17 self._executive = executive |
| 21 self._auth_refresh_token_json = auth_refresh_token_json | 18 self._auth_refresh_token_json = auth_refresh_token_json |
| 22 self._cwd = cwd | 19 self._cwd = cwd |
| 23 | 20 |
| 24 def run(self, args): | 21 def run(self, args): |
| 25 """Runs git-cl with the given arguments and returns the output.""" | 22 """Runs git-cl with the given arguments and returns the output.""" |
| 26 command = ['git', 'cl'] + args | 23 command = ['git', 'cl'] + args |
| 27 if self._auth_refresh_token_json: | 24 if self._auth_refresh_token_json: |
| 28 command += ['--auth-refresh-token-json', self._auth_refresh_token_js
on] | 25 command += ['--auth-refresh-token-json', self._auth_refresh_token_js
on] |
| 29 return self._executive.run_command(command, cwd=self._cwd) | 26 return self._executive.run_command(command, cwd=self._cwd) |
| 30 | 27 |
| 31 def get_issue_number(self): | 28 def get_issue_number(self): |
| 32 return self.run(['issue']).split()[2] | 29 return self.run(['issue']).split()[2] |
| 33 | 30 |
| 34 def has_failing_try_results(self, poll_delay_seconds=300): | 31 def has_failing_try_results(self, poll_delay_seconds=300): |
| 35 """Waits for try job results and checks whether there are failing result
s.""" | 32 """Waits for try job results and checks whether there are failing result
s.""" |
| 36 # TODO(qyearsley): Refactor to make this more easily-testable. | 33 # TODO(qyearsley): Refactor to make this more easily-testable. |
| 37 # TODO(qyearsley): Add a time-out to avoid infinite looping. | 34 # TODO(qyearsley): Add a time-out to avoid infinite looping. |
| 38 while True: | 35 while True: |
| 39 time.sleep(poll_delay_seconds) | 36 time.sleep(poll_delay_seconds) |
| 40 _log.info('Waiting for results.') | 37 print 'Waiting for results.' |
| 41 out = self.run(['try-results']) | 38 out = self.run(['try-results']) |
| 42 results = self.parse_try_job_results(out) | 39 results = self.parse_try_job_results(out) |
| 43 if results.get('Started') or results.get('Scheduled'): | 40 if results.get('Started') or results.get('Scheduled'): |
| 44 continue | 41 continue |
| 45 if results.get('Failures'): | 42 if results.get('Failures'): |
| 46 return True | 43 return True |
| 47 return False | 44 return False |
| 48 | 45 |
| 49 @staticmethod | 46 @staticmethod |
| 50 def parse_try_job_results(results): | 47 def parse_try_job_results(results): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 63 for line in results.splitlines(): | 60 for line in results.splitlines(): |
| 64 line = line.strip() | 61 line = line.strip() |
| 65 if line[-1] == ':': | 62 if line[-1] == ':': |
| 66 result_type = line[:-1] | 63 result_type = line[:-1] |
| 67 sets[result_type] = set() | 64 sets[result_type] = set() |
| 68 elif line.split()[0] == 'Total:': | 65 elif line.split()[0] == 'Total:': |
| 69 break | 66 break |
| 70 else: | 67 else: |
| 71 sets[result_type].add(line.split()[0]) | 68 sets[result_type].add(line.split()[0]) |
| 72 return sets | 69 return sets |
| OLD | NEW |