diff --git a/git_cl.py b/git_cl.py index c8c02e0c6..3ddb9d14c 100755 --- a/git_cl.py +++ b/git_cl.py @@ -455,10 +455,9 @@ def _trigger_try_jobs(auth_config, changelist, buckets, options, patchset): print('To see results here, run: git cl try-results') print('To see results in browser, run: git cl web') - gerrit_changes = [changelist.GetGerritChange()] - shared_properties = { - 'category': options.category, - } + gerrit_changes = [changelist.GetGerritChange(patchset)] + shared_properties = {'category': options.category} + shared_properties.update(changelist.GetLegacyProperties(patchset)) if options.clobber: shared_properties['clobber'] = True shared_properties.update(_get_properties_from_options(options) or {}) @@ -2686,6 +2685,34 @@ class Changelist(object): if data['status'] in ('ABANDONED', 'MERGED'): return 'CL %s is closed' % self.GetIssue() + # TODO(1004447): Remove on Oct 9th, 2019. + def GetLegacyProperties(self, patchset=None): + host = self.GetCodereviewServer() + issue = self.GetIssue() + patchset = int(patchset or self.GetPatchset()) + data = self._GetChangeDetail(['ALL_REVISIONS']) + + assert host and issue and patchset, 'CL must be uploaded first' + + revision_data = None # Pylint wants it to be defined. + for revision_data in data['revisions'].itervalues(): + if int(revision_data['_number']) == patchset: + break + else: + raise Exception('Patchset %d is not known in Gerrit change %d' % + (patchset, issue)) + + return { + 'patch_issue': issue, + 'patch_set': patchset, + 'patch_project': data['project'], + 'patch_storage': 'gerrit', + 'patch_ref': revision_data['fetch']['http']['ref'], + 'patch_repository_url': revision_data['fetch']['http']['url'], + 'patch_gerrit_url': host, + } + + def GetGerritChange(self, patchset=None): """Returns a buildbucket.v2.GerritChange message for the current issue.""" host = urlparse.urlparse(self.GetCodereviewServer()).hostname diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index f103d4660..a51eddcd6 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -3218,6 +3218,15 @@ class CMDTryTestCase(unittest.TestCase): "category": "git_cl_try", "json": [{"a": 1}, None], "key": "val", + 'patch_issue': 123456, + 'patch_set': 7, + 'patch_project': 'depot_tools', + 'patch_storage': 'gerrit', + 'patch_ref': 'refs/changes/56/123456/7', + 'patch_repository_url': + 'https://chromium.googlesource.com/depot_tools', + 'patch_gerrit_url': + 'https://chromium-review.googlesource.com', }, "tags": [ {"value": "win", "key": "builder"},