diff options
| author | Mike Frysinger <vapier@google.com> | 2020-02-24 15:38:07 -0500 |
|---|---|---|
| committer | David Pursehouse <dpursehouse@collab.net> | 2020-02-24 23:35:47 +0000 |
| commit | fc1b18ae9e39afc69b37ef4ada7a990e74b2c075 (patch) | |
| tree | 1041653f3c0e3c1917fff2939c5e9af0850c5071 | |
| parent | d957ec6a834e333a3812546911f786b0c20b808f (diff) | |
| download | git-repo-fc1b18ae9e39afc69b37ef4ada7a990e74b2c075.tar.gz | |
upload: allow users to set labels when uploading
Bug: https://crbug.com/gerrit/11801
Change-Id: I060465105b4e68ddfc815e572f62bf5dac2c1ffd
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256614
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
| -rw-r--r-- | docs/internal-fs-layout.md | 3 | ||||
| -rw-r--r-- | project.py | 4 | ||||
| -rw-r--r-- | subcmds/upload.py | 43 |
3 files changed, 39 insertions, 11 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md index 8050e4f0..530252b1 100644 --- a/docs/internal-fs-layout.md +++ b/docs/internal-fs-layout.md | |||
| @@ -193,7 +193,8 @@ The `[branch]` settings are updated by `repo start` and `git branch`. | |||
| 193 | | review.\<url\>.autocopy | upload | Automatically add to `--cc=<value>` | | 193 | | review.\<url\>.autocopy | upload | Automatically add to `--cc=<value>` | |
| 194 | | review.\<url\>.autoreviewer | upload | Automatically add to `--reviewers=<value>` | | 194 | | review.\<url\>.autoreviewer | upload | Automatically add to `--reviewers=<value>` | |
| 195 | | review.\<url\>.autoupload | upload | Automatically answer "yes" or "no" to all prompts | | 195 | | review.\<url\>.autoupload | upload | Automatically answer "yes" or "no" to all prompts | |
| 196 | | review.\<url\>.uploadhashtags | upload | Automatically add to `--hashtags=<value>` | | 196 | | review.\<url\>.uploadhashtags | upload | Automatically add to `--hashtag=<value>` | |
| 197 | | review.\<url\>.uploadlabels | upload | Automatically add to `--label=<value>` | | ||
| 197 | | review.\<url\>.uploadtopic | upload | Default [topic] to use | | 198 | | review.\<url\>.uploadtopic | upload | Default [topic] to use | |
| 198 | | review.\<url\>.username | upload | Override username with `ssh://` review URIs | | 199 | | review.\<url\>.username | upload | Override username with `ssh://` review URIs | |
| 199 | | remote.\<remote\>.fetch | sync | Set of refs to fetch | | 200 | | remote.\<remote\>.fetch | sync | Set of refs to fetch | |
| @@ -201,6 +201,7 @@ class ReviewableBranch(object): | |||
| 201 | dryrun=False, | 201 | dryrun=False, |
| 202 | auto_topic=False, | 202 | auto_topic=False, |
| 203 | hashtags=(), | 203 | hashtags=(), |
| 204 | labels=(), | ||
| 204 | draft=False, | 205 | draft=False, |
| 205 | private=False, | 206 | private=False, |
| 206 | notify=None, | 207 | notify=None, |
| @@ -213,6 +214,7 @@ class ReviewableBranch(object): | |||
| 213 | dryrun=dryrun, | 214 | dryrun=dryrun, |
| 214 | auto_topic=auto_topic, | 215 | auto_topic=auto_topic, |
| 215 | hashtags=hashtags, | 216 | hashtags=hashtags, |
| 217 | labels=labels, | ||
| 216 | draft=draft, | 218 | draft=draft, |
| 217 | private=private, | 219 | private=private, |
| 218 | notify=notify, | 220 | notify=notify, |
| @@ -1346,6 +1348,7 @@ class Project(object): | |||
| 1346 | dryrun=False, | 1348 | dryrun=False, |
| 1347 | auto_topic=False, | 1349 | auto_topic=False, |
| 1348 | hashtags=(), | 1350 | hashtags=(), |
| 1351 | labels=(), | ||
| 1349 | draft=False, | 1352 | draft=False, |
| 1350 | private=False, | 1353 | private=False, |
| 1351 | notify=None, | 1354 | notify=None, |
| @@ -1406,6 +1409,7 @@ class Project(object): | |||
| 1406 | if auto_topic: | 1409 | if auto_topic: |
| 1407 | opts += ['topic=' + branch.name] | 1410 | opts += ['topic=' + branch.name] |
| 1408 | opts += ['t=%s' % p for p in hashtags] | 1411 | opts += ['t=%s' % p for p in hashtags] |
| 1412 | opts += ['l=%s' % p for p in labels] | ||
| 1409 | 1413 | ||
| 1410 | opts += ['r=%s' % p for p in people[0]] | 1414 | opts += ['r=%s' % p for p in people[0]] |
| 1411 | opts += ['cc=%s' % p for p in people[1]] | 1415 | opts += ['cc=%s' % p for p in people[1]] |
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', |
