git-cl: Set legacy properties.

Will be removed back again on Oct 9, 2019.

Bug: 1004447
Change-Id: I7003fac9ae8b184e2a7073b516535e8fd599f4f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1825446
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@google.com>
diff --git a/git_cl.py b/git_cl.py
index c8c02e0..3ddb9d1 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -455,10 +455,9 @@
   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 @@
     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