git cl upload: set CQ and Auto Submit labels through refspec.

Except when TBR is active, because it's not clear how to
compute max score for Code-Review label before uploading a change.

Tested with this very own CL:
  To https://chromium.googlesource.com/chromium/tools/depot_tools.git
   * [new branch]        c78de165c7be156bdf8032c0ce3d8bad42778f1c ->
     refs/for/refs/heads/master%ready,notify=ALL,m=Initial_upload,r=ehmaldonado,
         cc=ajp,cc=chromium-reviews@chromium.org,cc=iannucci+depot_tools@chromium.org,
         l=Commit-Queue+1,hashtag=git-cl-upload
R=ehmaldonado

Bug: 877717
Change-Id: I464d9df2814bd830dd608bb881040e2dd3c41dbb
Reviewed-on: https://chromium-review.googlesource.com/c/1307052
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index a46509c..8f7f6b7 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2927,6 +2927,17 @@
       # https://gerrit-review.googlesource.com/Documentation/user-upload.html#topic
       refspec_opts.append('topic=%s' % options.topic)
 
+    if not change_desc.get_reviewers(tbr_only=True):
+      # Change is not TBR, so we can inline setting other labels, too.
+      # TODO(crbug.com/877717): make this working for TBR, too, by figuring out
+      # max score for CR label somehow.
+      if options.enable_auto_submit:
+        refspec_opts.append('l=Auto-Submit+1')
+      if options.use_commit_queue:
+        refspec_opts.append('l=Commit-Queue+2')
+      elif options.cq_dry_run:
+        refspec_opts.append('l=Commit-Queue+1')
+
     # Gerrit sorts hashtags, so order is not important.
     hashtags = {change_desc.sanitize_hash_tag(t) for t in options.hashtags}
     if not self.GetIssue():
@@ -3042,9 +3053,9 @@
           self._GerritChangeIdentifier(),
           msg='Self-approving for TBR',
           labels={'Code-Review': score})
-
-    self.SetLabels(options.enable_auto_submit, options.use_commit_queue,
-                   options.cq_dry_run)
+      # Labels aren't set through refspec only if tbr is set (see check above).
+      self.SetLabels(options.enable_auto_submit, options.use_commit_queue,
+                     options.cq_dry_run)
     return 0
 
   def _ComputeParent(self, remote, upstream_branch, custom_cl_base, force,