Commit e61ccc59 authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

[depot_tools] Make try-results fetch recent dry-runs

Running git cl try-results fetches the latest patchset which may be a trivial change, e.g. rebase or commit message change.
This change allows try-results to get the result of patchsets equivalent to the latest and returns their results.

Bug: 774179
Change-Id: Iec2fea102597773e24c2e887f19282f14c123e61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2532899Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent 5157fbfb
......@@ -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'
......
......@@ -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([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment