Add 'create tag' support to gerrit_client and gerrit recipe_module.

BUG=1052179
R=dpranke@google.com, linxinan@chromium.org

Change-Id: I6e220b70e63d990e9257d9fe4d107de7dbd2eb81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3232849
Auto-Submit: Michael Moss <mmoss@chromium.org>
Commit-Queue: Michael Moss <mmoss@chromium.org>
Reviewed-by: Xinan Lin <linxinan@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
diff --git a/gerrit_util.py b/gerrit_util.py
index 0fec632..6680ee0 100644
--- a/gerrit_util.py
+++ b/gerrit_util.py
@@ -1015,6 +1015,23 @@
   raise GerritError(200, 'Unable to create gerrit branch')
 
 
+def CreateGerritTag(host, project, tag, commit):
+  """Creates a new tag at the given commit.
+
+  https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#create-tag
+
+  Returns:
+    A JSON object with 'ref' key.
+  """
+  path = 'projects/%s/tags/%s' % (project, tag)
+  body = {'revision': commit}
+  conn = CreateHttpConn(host, path, reqtype='PUT', body=body)
+  response = ReadHttpJsonResponse(conn, accept_statuses=[201])
+  if response:
+    return response
+  raise GerritError(200, 'Unable to create gerrit tag')
+
+
 def GetHead(host, project):
   """Retrieves current HEAD of Gerrit project