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/tests/git_cl_test.py b/tests/git_cl_test.py
index 9e5f57e..63b9b0c 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -905,7 +905,8 @@
title=None, notify=False,
post_amend_description=None, issue=None, cc=None,
custom_cl_base=None, tbr=None,
- short_hostname='chromium'):
+ short_hostname='chromium',
+ labels=None):
if post_amend_description is None:
post_amend_description = description
cc = cc or []
@@ -1048,6 +1049,10 @@
if c in cc:
cc.remove(c)
+ if not tbr:
+ for k, v in sorted((labels or {}).items()):
+ ref_suffix += ',l=%s+%d' % (k, v)
+
calls.append((
(['git', 'push',
'https://%s.googlesource.com/my/repo' % short_hostname,
@@ -1130,7 +1135,8 @@
other_cl_owner=None,
custom_cl_base=None,
tbr=None,
- short_hostname='chromium'):
+ short_hostname='chromium',
+ labels=None):
"""Generic gerrit upload test framework."""
if squash_mode is None:
if '--no-squash' in upload_args:
@@ -1172,7 +1178,8 @@
post_amend_description=post_amend_description,
issue=issue, cc=cc,
custom_cl_base=custom_cl_base, tbr=tbr,
- short_hostname=short_hostname)
+ short_hostname=short_hostname,
+ labels=labels)
# Uncomment when debugging.
# print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))
git_cl.main(['upload'] + upload_args)
@@ -1256,6 +1263,15 @@
squash=True,
expected_upstream_ref='origin/master')
+ def test_gerrit_upload_squash_first_with_labels(self):
+ self._run_gerrit_upload_test(
+ ['--squash', '--cq-dry-run', '--enable-auto-submit'],
+ 'desc\nBUG=\n\nChange-Id: 123456789',
+ [],
+ squash=True,
+ expected_upstream_ref='origin/master',
+ labels={'Commit-Queue': 1, 'Auto-Submit': 1})
+
def test_gerrit_upload_squash_first_against_rev(self):
custom_cl_base = 'custom_cl_base_rev_or_branch'
self._run_gerrit_upload_test(