diff --git a/git_cl.py b/git_cl.py index 67d349989..d2fb3faa2 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1722,6 +1722,30 @@ class Changelist(object): self.SetPatchset(patchset) return patchset + def GetMostRecentDryRunPatchset(self): + """Get patchsets equivalent to the most recent patchset and return + the patchset with the latest dry run. If none have been dry run, return + the latest patchset.""" + if not self.GetIssue(): + return None + + data = self._GetChangeDetail(['ALL_REVISIONS']) + patchset = data['revisions'][data['current_revision']]['_number'] + dry_run = set([int(m['_revision_number']) + for m in data.get('messages', []) + if m.get('tag', '').endswith('dry-run')]) + + for revision_info in sorted(data.get('revisions', {}).values(), + key=lambda c: c['_number'], reverse=True): + if revision_info['_number'] in dry_run: + patchset = revision_info['_number'] + break + if revision_info.get('kind', '') not in \ + ('NO_CHANGE', 'NO_CODE_CHANGE', 'TRIVIAL_REBASE'): + break + self.SetPatchset(patchset) + return patchset + def AddComment(self, message, publish=None): gerrit_util.SetReview( self._GetGerritHost(), self._GerritChangeIdentifier(), @@ -4533,7 +4557,7 @@ def CMDtry_results(parser, args): patchset = options.patchset if not patchset: - patchset = cl.GetMostRecentPatchset() + patchset = cl.GetMostRecentDryRunPatchset() if not patchset: parser.error('Code review host doesn\'t know about issue %s. ' 'No access to issue or wrong issue number?\n' diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 1027190c2..a4a0cbc20 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -2950,9 +2950,13 @@ class CMDTestCaseBase(unittest.TestCase): 'owner': {'email': 'owner@e.mail'}, 'current_revision': 'beeeeeef', 'revisions': { - 'deadbeaf': {'_number': 6}, + 'deadbeaf': { + '_number': 6, + 'kind': 'REWORK', + }, 'beeeeeef': { '_number': 7, + 'kind': 'NO_CODE_CHANGE', 'fetch': {'http': { 'url': 'https://chromium.googlesource.com/depot_tools', 'ref': 'refs/changes/56/123456/7' @@ -2988,6 +2992,9 @@ class CMDTestCaseBase(unittest.TestCase): mock.patch( 'git_cl.Changelist.GetMostRecentPatchset', return_value=7).start() + mock.patch( + 'git_cl.Changelist.GetMostRecentDryRunPatchset', + return_value=6).start() mock.patch( 'git_cl.Changelist.GetRemoteUrl', return_value='https://chromium.googlesource.com/depot_tools').start() @@ -3075,6 +3082,19 @@ class CMDPresubmitTestCase(CMDTestCaseBase): class CMDTryResultsTestCase(CMDTestCaseBase): _DEFAULT_REQUEST = { + 'predicate': { + "gerritChanges": [{ + "project": "depot_tools", + "host": "chromium-review.googlesource.com", + "patchset": 6, + "change": 123456, + }], + }, + 'fields': ('builds.*.id,builds.*.builder,builds.*.status' + + ',builds.*.createTime,builds.*.tags'), + } + + _TRIVIAL_REQUEST = { 'predicate': { "gerritChanges": [{ "project": "depot_tools", @@ -3096,6 +3116,36 @@ class CMDTryResultsTestCase(CMDTestCaseBase): mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', self._DEFAULT_REQUEST) + def testTrivialCommits(self): + self.assertEqual(0, git_cl.main(['try-results'])) + git_cl._call_buildbucket.assert_called_with( + mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', + self._DEFAULT_REQUEST) + + git_cl._call_buildbucket.return_value = {} + self.assertEqual(0, git_cl.main(['try-results', '--patchset', '7'])) + git_cl._call_buildbucket.assert_called_with( + mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', + self._TRIVIAL_REQUEST) + self.assertEqual([ + 'Successes:', + ' bot_success https://ci.chromium.org/b/103', + 'Infra Failures:', + ' bot_infra_failure https://ci.chromium.org/b/105', + 'Failures:', + ' bot_failure https://ci.chromium.org/b/104', + 'Canceled:', + ' bot_canceled ', + 'Started:', + ' bot_started https://ci.chromium.org/b/102', + 'Scheduled:', + ' bot_scheduled id=101', + 'Other:', + ' bot_status_unspecified id=100', + 'Total: 7 tryjobs', + 'No tryjobs scheduled.', + ], sys.stdout.getvalue().splitlines()) + def testPrintToStdout(self): self.assertEqual(0, git_cl.main(['try-results'])) self.assertEqual([