diff --git a/git_cl.py b/git_cl.py index 5cf3b16ae..2144791d4 100755 --- a/git_cl.py +++ b/git_cl.py @@ -375,7 +375,7 @@ def _parse_bucket(raw_bucket): return project, bucket -def _trigger_try_jobs(changelist, jobs, options, patchset): +def _trigger_tryjobs(changelist, jobs, options, patchset): """Sends a request to Buildbucket to trigger tryjobs for a changelist. Args: @@ -389,8 +389,7 @@ def _trigger_try_jobs(changelist, jobs, options, patchset): print('To see results here, run: git cl try-results') print('To see results in browser, run: git cl web') - requests = _make_try_job_schedule_requests( - changelist, jobs, options, patchset) + requests = _make_tryjob_schedule_requests(changelist, jobs, options, patchset) if not requests: return @@ -411,7 +410,7 @@ def _trigger_try_jobs(changelist, jobs, options, patchset): 'Failed to schedule builds for some bots:\n%s' % '\n'.join(errors)) -def _make_try_job_schedule_requests(changelist, jobs, options, patchset): +def _make_tryjob_schedule_requests(changelist, jobs, options, patchset): gerrit_changes = [changelist.GetGerritChange(patchset)] shared_properties = {'category': getattr(options, 'category', 'git_cl_try')} if getattr(options, 'clobber', False): @@ -455,7 +454,7 @@ def _make_try_job_schedule_requests(changelist, jobs, options, patchset): return requests -def fetch_try_jobs(changelist, buildbucket_host, patchset=None): +def _fetch_tryjobs(changelist, buildbucket_host, patchset=None): """Fetches tryjobs from buildbucket. Returns list of buildbucket.v2.Build with the try jobs for the changelist. @@ -507,7 +506,7 @@ def _fetch_latest_builds(changelist, buildbucket_host, latest_patchset=None): min_ps = max(1, ps - 5) while ps >= min_ps: - builds = fetch_try_jobs(changelist, buildbucket_host, patchset=ps) + builds = _fetch_tryjobs(changelist, buildbucket_host, patchset=ps) if len(builds): return builds, ps ps -= 1 @@ -518,13 +517,13 @@ def _filter_failed_for_retry(all_builds): """Returns a list of buckets/builders that are worth retrying. Args: - all_builds (list): Builds, in the format returned by fetch_try_jobs, + all_builds (list): Builds, in the format returned by _fetch_tryjobs, i.e. a list of buildbucket.v2.Builds which includes status and builder info. Returns: A dict {(proj, bucket): [builders]}. This is the same format accepted by - _trigger_try_jobs. + _trigger_tryjobs. """ grouped = {} for build in all_builds: @@ -559,8 +558,8 @@ def _filter_failed_for_retry(all_builds): return sorted(jobs) -def print_try_jobs(options, builds): - """Prints nicely result of fetch_try_jobs.""" +def _print_tryjobs(options, builds): + """Prints nicely result of _fetch_tryjobs.""" if not builds: print('No tryjobs scheduled.') return @@ -4400,7 +4399,7 @@ def CMDupload(parser, args): if len(jobs) == 0: print('No failed tryjobs, so --retry-failed has no effect.') return ret - _trigger_try_jobs(cl, jobs, options, patchset + 1) + _trigger_tryjobs(cl, jobs, options, patchset + 1) return ret @@ -4716,7 +4715,7 @@ def CMDtry(parser, args): patchset = cl.GetMostRecentPatchset() try: - _trigger_try_jobs(cl, jobs, options, patchset) + _trigger_tryjobs(cl, jobs, options, patchset) except BuildbucketResponseException as ex: print('ERROR: %s' % ex) return 1 @@ -4763,14 +4762,14 @@ def CMDtry_results(parser, args): cl.GetIssue()) try: - jobs = fetch_try_jobs(cl, options.buildbucket_host, patchset) + jobs = _fetch_tryjobs(cl, options.buildbucket_host, patchset) except BuildbucketResponseException as ex: print('Buildbucket error: %s' % ex) return 1 if options.json: write_json(options.json, jobs) else: - print_try_jobs(options, jobs) + _print_tryjobs(options, jobs) return 0 diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index aa56a3a7e..c817d5a50 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -3306,21 +3306,20 @@ class CMDTryTestCase(CMDTestCaseBase): sys.stderr.getvalue()) @mock.patch('git_cl._call_buildbucket') - @mock.patch('git_cl.fetch_try_jobs') + @mock.patch('git_cl._fetch_tryjobs') def testScheduleOnBuildbucketRetryFailed( self, mockFetchTryJobs, mockCallBuildbucket): - - git_cl.fetch_try_jobs.side_effect = lambda *_, **kw: { + git_cl._fetch_tryjobs.side_effect = lambda *_, **kw: { 7: [], 6: [{ 'id': 112112, 'builder': { 'project': 'chromium', 'bucket': 'try', - 'builder': 'linux',}, + 'builder': 'linux', }, 'createTime': '2019-10-09T08:00:01.854286Z', 'tags': [], - 'status': 'FAILURE',}],}[kw['patchset']] + 'status': 'FAILURE', }], }[kw['patchset']] mockCallBuildbucket.return_value = {} self.assertEqual(0, git_cl.main(['try', '--retry-failed'])) @@ -3393,8 +3392,8 @@ class CMDTryTestCase(CMDTestCaseBase): class CMDUploadTestCase(CMDTestCaseBase): def setUp(self): super(CMDUploadTestCase, self).setUp() - mock.patch('git_cl.fetch_try_jobs').start() - mock.patch('git_cl._trigger_try_jobs', return_value={}).start() + mock.patch('git_cl._fetch_tryjobs').start() + mock.patch('git_cl._trigger_tryjobs', return_value={}).start() mock.patch('git_cl.Changelist.CMDUpload', return_value=0).start() mock.patch('git_cl.Settings.GetIsGerrit', return_value=True).start() self.addCleanup(mock.patch.stopall) @@ -3412,7 +3411,7 @@ class CMDUploadTestCase(CMDTestCaseBase): # upload, if --retry-failed is added, then the tool will fetch try jobs # from the previous patchset and trigger the right builders on the latest # patchset. - git_cl.fetch_try_jobs.side_effect = [ + git_cl._fetch_tryjobs.side_effect = [ # Latest patchset: No builds. [], # Patchset before latest: Some builds. @@ -3433,13 +3432,13 @@ class CMDUploadTestCase(CMDTestCaseBase): self.assertEqual([ mock.call(mock.ANY, 'cr-buildbucket.appspot.com', patchset=7), mock.call(mock.ANY, 'cr-buildbucket.appspot.com', patchset=6), - ], git_cl.fetch_try_jobs.mock_calls) + ], git_cl._fetch_tryjobs.mock_calls) expected_buckets = [ ('chromium', 'try', 'bot_failure'), ('chromium', 'try', 'bot_infra_failure'), ] - git_cl._trigger_try_jobs.assert_called_once_with( - mock.ANY, expected_buckets, mock.ANY, 8) + git_cl._trigger_tryjobs.assert_called_once_with(mock.ANY, expected_buckets, + mock.ANY, 8) class CMDFormatTestCase(unittest.TestCase):