summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-19 02:22:22 -0500
committerMike Frysinger <vapier@google.com>2020-02-19 08:31:18 +0000
commit84685ba1875db265051cdd043d5dba768c7c42e5 (patch)
tree426cb29f23da77aac700bce1c08cba935d6f96aa
parent72ebf19e52e7c4b270e40ba07fec1048b3612797 (diff)
downloadgit-repo-84685ba1875db265051cdd043d5dba768c7c42e5.tar.gz
upload: add support for setting hashtags
This allows users to specify custom hashtags when uploading, both via the CLI and via the same gitconfig settings as other upload options. Bug: https://crbug.com/gerrit/11174 Change-Id: Ia0959e25b463e5f29d704e4d06e0de793d4fc77c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255855 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r--docs/internal-fs-layout.md1
-rw-r--r--project.py4
-rw-r--r--subcmds/upload.py24
3 files changed, 29 insertions, 0 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md
index 0093e870..8e62cde2 100644
--- a/docs/internal-fs-layout.md
+++ b/docs/internal-fs-layout.md
@@ -172,6 +172,7 @@ The `[branch]` settings are updated by `repo start` and `git branch`.
172| review.\<url\>.autocopy | upload | Automatically add to `--cc=<value>` | 172| review.\<url\>.autocopy | upload | Automatically add to `--cc=<value>` |
173| review.\<url\>.autoreviewer | upload | Automatically add to `--reviewers=<value>` | 173| review.\<url\>.autoreviewer | upload | Automatically add to `--reviewers=<value>` |
174| review.\<url\>.autoupload | upload | Automatically answer "yes" or "no" to all prompts | 174| review.\<url\>.autoupload | upload | Automatically answer "yes" or "no" to all prompts |
175| review.\<url\>.uploadhashtags | upload | Automatically add to `--hashtags=<value>` |
175| review.\<url\>.uploadtopic | upload | Default [topic] to use | 176| review.\<url\>.uploadtopic | upload | Default [topic] to use |
176| review.\<url\>.username | upload | Override username with `ssh://` review URIs | 177| review.\<url\>.username | upload | Override username with `ssh://` review URIs |
177| remote.\<remote\>.fetch | sync | Set of refs to fetch | 178| remote.\<remote\>.fetch | sync | Set of refs to fetch |
diff --git a/project.py b/project.py
index e0e9b7fe..06606fa6 100644
--- a/project.py
+++ b/project.py
@@ -199,6 +199,7 @@ class ReviewableBranch(object):
199 199
200 def UploadForReview(self, people, 200 def UploadForReview(self, people,
201 auto_topic=False, 201 auto_topic=False,
202 hashtags=(),
202 draft=False, 203 draft=False,
203 private=False, 204 private=False,
204 notify=None, 205 notify=None,
@@ -209,6 +210,7 @@ class ReviewableBranch(object):
209 self.project.UploadForReview(self.name, 210 self.project.UploadForReview(self.name,
210 people, 211 people,
211 auto_topic=auto_topic, 212 auto_topic=auto_topic,
213 hashtags=hashtags,
212 draft=draft, 214 draft=draft,
213 private=private, 215 private=private,
214 notify=notify, 216 notify=notify,
@@ -1331,6 +1333,7 @@ class Project(object):
1331 def UploadForReview(self, branch=None, 1333 def UploadForReview(self, branch=None,
1332 people=([], []), 1334 people=([], []),
1333 auto_topic=False, 1335 auto_topic=False,
1336 hashtags=(),
1334 draft=False, 1337 draft=False,
1335 private=False, 1338 private=False,
1336 notify=None, 1339 notify=None,
@@ -1388,6 +1391,7 @@ class Project(object):
1388 opts = [] 1391 opts = []
1389 if auto_topic: 1392 if auto_topic:
1390 opts += ['topic=' + branch.name] 1393 opts += ['topic=' + branch.name]
1394 opts += ['t=%s' % p for p in hashtags]
1391 1395
1392 opts += ['r=%s' % p for p in people[0]] 1396 opts += ['r=%s' % p for p in people[0]]
1393 opts += ['cc=%s' % p for p in people[1]] 1397 opts += ['cc=%s' % p for p in people[1]]
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 91bec6f8..633ddc81 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -130,6 +130,12 @@ is set to "true" then repo will assume you always want the equivalent
130of the -t option to the repo command. If unset or set to "false" then 130of the -t option to the repo command. If unset or set to "false" then
131repo will make use of only the command line option. 131repo will make use of only the command line option.
132 132
133review.URL.uploadhashtags:
134
135To add hashtags whenever uploading a commit, you can set a per-project
136or global Git option to do so. The value of review.URL.uploadhashtags
137will be used as comma delimited hashtags like the --hashtags option.
138
133# References 139# References
134 140
135Gerrit Code Review: https://www.gerritcodereview.com/ 141Gerrit Code Review: https://www.gerritcodereview.com/
@@ -140,6 +146,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/
140 p.add_option('-t', 146 p.add_option('-t',
141 dest='auto_topic', action='store_true', 147 dest='auto_topic', action='store_true',
142 help='Send local branch name to Gerrit Code Review') 148 help='Send local branch name to Gerrit Code Review')
149 p.add_option('--hashtag', '--ht',
150 dest='hashtags', action='append', default=[],
151 help='Add hashtags (comma delimited) to the review.')
143 p.add_option('--re', '--reviewers', 152 p.add_option('--re', '--reviewers',
144 type='string', action='append', dest='reviewers', 153 type='string', action='append', dest='reviewers',
145 help='Request reviews from these people.') 154 help='Request reviews from these people.')
@@ -384,6 +393,20 @@ Gerrit Code Review: https://www.gerritcodereview.com/
384 key = 'review.%s.uploadtopic' % branch.project.remote.review 393 key = 'review.%s.uploadtopic' % branch.project.remote.review
385 opt.auto_topic = branch.project.config.GetBoolean(key) 394 opt.auto_topic = branch.project.config.GetBoolean(key)
386 395
396 # Check if hashtags should be included.
397 def _ExpandHashtag(value):
398 """Split |value| up into comma delimited tags."""
399 if not value:
400 return
401 for tag in value.split(','):
402 tag = tag.strip()
403 if tag:
404 yield tag
405 key = 'review.%s.uploadhashtags' % branch.project.remote.review
406 hashtags = set(_ExpandHashtag(branch.project.config.GetString(key)))
407 for tag in opt.hashtags:
408 hashtags.update(_ExpandHashtag(tag))
409
387 destination = opt.dest_branch or branch.project.dest_branch 410 destination = opt.dest_branch or branch.project.dest_branch
388 411
389 # Make sure our local branch is not setup to track a different remote branch 412 # Make sure our local branch is not setup to track a different remote branch
@@ -401,6 +424,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
401 424
402 branch.UploadForReview(people, 425 branch.UploadForReview(people,
403 auto_topic=opt.auto_topic, 426 auto_topic=opt.auto_topic,
427 hashtags=hashtags,
404 draft=opt.draft, 428 draft=opt.draft,
405 private=opt.private, 429 private=opt.private,
406 notify=None if opt.notify else 'NONE', 430 notify=None if opt.notify else 'NONE',