diff options
Diffstat (limited to 'subcmds')
-rw-r--r-- | subcmds/upload.py | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index ef6d0242..93f9c1e7 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -134,7 +134,13 @@ review.URL.uploadhashtags: | |||
134 | 134 | ||
135 | To add hashtags whenever uploading a commit, you can set a per-project | 135 | To add hashtags whenever uploading a commit, you can set a per-project |
136 | or global Git option to do so. The value of review.URL.uploadhashtags | 136 | or global Git option to do so. The value of review.URL.uploadhashtags |
137 | will be used as comma delimited hashtags like the --hashtags option. | 137 | will be used as comma delimited hashtags like the --hashtag option. |
138 | |||
139 | review.URL.uploadlabels: | ||
140 | |||
141 | To add labels whenever uploading a commit, you can set a per-project | ||
142 | or global Git option to do so. The value of review.URL.uploadlabels | ||
143 | will be used as comma delimited labels like the --label option. | ||
138 | 144 | ||
139 | # References | 145 | # References |
140 | 146 | ||
@@ -152,6 +158,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
152 | p.add_option('--hashtag-branch', '--htb', | 158 | p.add_option('--hashtag-branch', '--htb', |
153 | action='store_true', | 159 | action='store_true', |
154 | help='Add local branch name as a hashtag.') | 160 | help='Add local branch name as a hashtag.') |
161 | p.add_option('-l', '--label', | ||
162 | dest='labels', action='append', default=[], | ||
163 | help='Add a label when uploading.') | ||
155 | p.add_option('--re', '--reviewers', | 164 | p.add_option('--re', '--reviewers', |
156 | type='string', action='append', dest='reviewers', | 165 | type='string', action='append', dest='reviewers', |
157 | help='Request reviews from these people.') | 166 | help='Request reviews from these people.') |
@@ -410,22 +419,35 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
410 | key = 'review.%s.uploadtopic' % branch.project.remote.review | 419 | key = 'review.%s.uploadtopic' % branch.project.remote.review |
411 | opt.auto_topic = branch.project.config.GetBoolean(key) | 420 | opt.auto_topic = branch.project.config.GetBoolean(key) |
412 | 421 | ||
413 | # Check if hashtags should be included. | 422 | def _ExpandCommaList(value): |
414 | def _ExpandHashtag(value): | 423 | """Split |value| up into comma delimited entries.""" |
415 | """Split |value| up into comma delimited tags.""" | ||
416 | if not value: | 424 | if not value: |
417 | return | 425 | return |
418 | for tag in value.split(','): | 426 | for ret in value.split(','): |
419 | tag = tag.strip() | 427 | ret = ret.strip() |
420 | if tag: | 428 | if ret: |
421 | yield tag | 429 | yield ret |
430 | |||
431 | # Check if hashtags should be included. | ||
422 | key = 'review.%s.uploadhashtags' % branch.project.remote.review | 432 | key = 'review.%s.uploadhashtags' % branch.project.remote.review |
423 | hashtags = set(_ExpandHashtag(branch.project.config.GetString(key))) | 433 | hashtags = set(_ExpandCommaList(branch.project.config.GetString(key))) |
424 | for tag in opt.hashtags: | 434 | for tag in opt.hashtags: |
425 | hashtags.update(_ExpandHashtag(tag)) | 435 | hashtags.update(_ExpandCommaList(tag)) |
426 | if opt.hashtag_branch: | 436 | if opt.hashtag_branch: |
427 | hashtags.add(branch.name) | 437 | hashtags.add(branch.name) |
428 | 438 | ||
439 | # Check if labels should be included. | ||
440 | key = 'review.%s.uploadlabels' % branch.project.remote.review | ||
441 | labels = set(_ExpandCommaList(branch.project.config.GetString(key))) | ||
442 | for label in opt.labels: | ||
443 | labels.update(_ExpandCommaList(label)) | ||
444 | # Basic sanity check on label syntax. | ||
445 | for label in labels: | ||
446 | if not re.match(r'^.+[+-][0-9]+$', label): | ||
447 | print('repo: error: invalid label syntax "%s": labels use forms ' | ||
448 | 'like CodeReview+1 or Verified-1' % (label,), file=sys.stderr) | ||
449 | sys.exit(1) | ||
450 | |||
429 | destination = opt.dest_branch or branch.project.dest_branch | 451 | destination = opt.dest_branch or branch.project.dest_branch |
430 | 452 | ||
431 | # Make sure our local branch is not setup to track a different remote branch | 453 | # Make sure our local branch is not setup to track a different remote branch |
@@ -445,6 +467,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
445 | dryrun=opt.dryrun, | 467 | dryrun=opt.dryrun, |
446 | auto_topic=opt.auto_topic, | 468 | auto_topic=opt.auto_topic, |
447 | hashtags=hashtags, | 469 | hashtags=hashtags, |
470 | labels=labels, | ||
448 | draft=opt.draft, | 471 | draft=opt.draft, |
449 | private=opt.private, | 472 | private=opt.private, |
450 | notify=None if opt.notify else 'NONE', | 473 | notify=None if opt.notify else 'NONE', |