Просмотр исходного кода

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>
Mike Frysinger 6 лет назад
Родитель
Сommit
84685ba187
3 измененных файлов с 29 добавлено и 0 удалено
  1. 1 0
      docs/internal-fs-layout.md
  2. 4 0
      project.py
  3. 24 0
      subcmds/upload.py

+ 1 - 0
docs/internal-fs-layout.md

@@ -172,6 +172,7 @@ The `[branch]` settings are updated by `repo start` and `git branch`.
 | review.\<url\>.autocopy       | upload        | Automatically add to `--cc=<value>` |
 | review.\<url\>.autocopy       | upload        | Automatically add to `--cc=<value>` |
 | review.\<url\>.autoreviewer   | upload        | Automatically add to `--reviewers=<value>` |
 | review.\<url\>.autoreviewer   | upload        | Automatically add to `--reviewers=<value>` |
 | review.\<url\>.autoupload     | upload        | Automatically answer "yes" or "no" to all prompts |
 | review.\<url\>.autoupload     | upload        | Automatically answer "yes" or "no" to all prompts |
+| review.\<url\>.uploadhashtags | upload        | Automatically add to `--hashtags=<value>` |
 | review.\<url\>.uploadtopic    | upload        | Default [topic] to use |
 | review.\<url\>.uploadtopic    | upload        | Default [topic] to use |
 | review.\<url\>.username       | upload        | Override username with `ssh://` review URIs |
 | review.\<url\>.username       | upload        | Override username with `ssh://` review URIs |
 | remote.\<remote\>.fetch       | sync          | Set of refs to fetch |
 | remote.\<remote\>.fetch       | sync          | Set of refs to fetch |

+ 4 - 0
project.py

@@ -199,6 +199,7 @@ class ReviewableBranch(object):
 
 
   def UploadForReview(self, people,
   def UploadForReview(self, people,
                       auto_topic=False,
                       auto_topic=False,
+                      hashtags=(),
                       draft=False,
                       draft=False,
                       private=False,
                       private=False,
                       notify=None,
                       notify=None,
@@ -209,6 +210,7 @@ class ReviewableBranch(object):
     self.project.UploadForReview(self.name,
     self.project.UploadForReview(self.name,
                                  people,
                                  people,
                                  auto_topic=auto_topic,
                                  auto_topic=auto_topic,
+                                 hashtags=hashtags,
                                  draft=draft,
                                  draft=draft,
                                  private=private,
                                  private=private,
                                  notify=notify,
                                  notify=notify,
@@ -1331,6 +1333,7 @@ class Project(object):
   def UploadForReview(self, branch=None,
   def UploadForReview(self, branch=None,
                       people=([], []),
                       people=([], []),
                       auto_topic=False,
                       auto_topic=False,
+                      hashtags=(),
                       draft=False,
                       draft=False,
                       private=False,
                       private=False,
                       notify=None,
                       notify=None,
@@ -1388,6 +1391,7 @@ class Project(object):
     opts = []
     opts = []
     if auto_topic:
     if auto_topic:
       opts += ['topic=' + branch.name]
       opts += ['topic=' + branch.name]
+    opts += ['t=%s' % p for p in hashtags]
 
 
     opts += ['r=%s' % p for p in people[0]]
     opts += ['r=%s' % p for p in people[0]]
     opts += ['cc=%s' % p for p in people[1]]
     opts += ['cc=%s' % p for p in people[1]]

+ 24 - 0
subcmds/upload.py

@@ -130,6 +130,12 @@ is set to "true" then repo will assume you always want the equivalent
 of the -t option to the repo command. If unset or set to "false" then
 of the -t option to the repo command. If unset or set to "false" then
 repo will make use of only the command line option.
 repo will make use of only the command line option.
 
 
+review.URL.uploadhashtags:
+
+To add hashtags whenever uploading a commit, you can set a per-project
+or global Git option to do so. The value of review.URL.uploadhashtags
+will be used as comma delimited hashtags like the --hashtags option.
+
 # References
 # References
 
 
 Gerrit Code Review:  https://www.gerritcodereview.com/
 Gerrit Code Review:  https://www.gerritcodereview.com/
@@ -140,6 +146,9 @@ Gerrit Code Review:  https://www.gerritcodereview.com/
     p.add_option('-t',
     p.add_option('-t',
                  dest='auto_topic', action='store_true',
                  dest='auto_topic', action='store_true',
                  help='Send local branch name to Gerrit Code Review')
                  help='Send local branch name to Gerrit Code Review')
+    p.add_option('--hashtag', '--ht',
+                 dest='hashtags', action='append', default=[],
+                 help='Add hashtags (comma delimited) to the review.')
     p.add_option('--re', '--reviewers',
     p.add_option('--re', '--reviewers',
                  type='string', action='append', dest='reviewers',
                  type='string', action='append', dest='reviewers',
                  help='Request reviews from these people.')
                  help='Request reviews from these people.')
@@ -384,6 +393,20 @@ Gerrit Code Review:  https://www.gerritcodereview.com/
           key = 'review.%s.uploadtopic' % branch.project.remote.review
           key = 'review.%s.uploadtopic' % branch.project.remote.review
           opt.auto_topic = branch.project.config.GetBoolean(key)
           opt.auto_topic = branch.project.config.GetBoolean(key)
 
 
+        # Check if hashtags should be included.
+        def _ExpandHashtag(value):
+          """Split |value| up into comma delimited tags."""
+          if not value:
+            return
+          for tag in value.split(','):
+            tag = tag.strip()
+            if tag:
+              yield tag
+        key = 'review.%s.uploadhashtags' % branch.project.remote.review
+        hashtags = set(_ExpandHashtag(branch.project.config.GetString(key)))
+        for tag in opt.hashtags:
+          hashtags.update(_ExpandHashtag(tag))
+
         destination = opt.dest_branch or branch.project.dest_branch
         destination = opt.dest_branch or branch.project.dest_branch
 
 
         # Make sure our local branch is not setup to track a different remote branch
         # 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/
 
 
         branch.UploadForReview(people,
         branch.UploadForReview(people,
                                auto_topic=opt.auto_topic,
                                auto_topic=opt.auto_topic,
+                               hashtags=hashtags,
                                draft=opt.draft,
                                draft=opt.draft,
                                private=opt.private,
                                private=opt.private,
                                notify=None if opt.notify else 'NONE',
                                notify=None if opt.notify else 'NONE',