Bladeren bron

gerrit_client could retrieve the branch and tag info for a commit hash

BUG=1207955
TEST=verified at local

Change-Id: Ife31456371f156d342ddd099bba1521051d700fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3044919
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Michael Moss <mmoss@chromium.org>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
Xinan Lin 4 jaren geleden
bovenliggende
commit
c2fb26a337
2 gewijzigde bestanden met toevoegingen van 24 en 0 verwijderingen
  1. 11 0
      gerrit_client.py
  2. 13 0
      gerrit_util.py

+ 11 - 0
gerrit_client.py

@@ -254,6 +254,17 @@ def CMDsubmitchange(parser, args):
   write_result(result, opt)
 
 
+@subcommand.usage('[args ...]')
+def CMDgetcommitincludedin(parser, args):
+  """Retrieves the branches and tags for a given commit."""
+  parser.add_option('--commit', dest='commit', help='commit hash')
+  (opt, args) = parser.parse_args(args)
+  result = gerrit_util.GetCommitIncludedIn(
+      urlparse.urlparse(opt.host).netloc, opt.project, opt.commit)
+  logging.info(result)
+  write_result(result, opt)
+
+
 @subcommand.usage('')
 def CMDabandon(parser, args):
   """Abandons a Gerrit change."""

+ 13 - 0
gerrit_util.py

@@ -797,6 +797,19 @@ def SetCommitMessage(host, change, description, notify='ALL'):
         'in change %s' % change)
 
 
+def GetCommitIncludedIn(host, project, commit):
+  """Retrieves the branches and tags for a given commit.
+
+  https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-included-in
+
+  Returns:
+    A JSON object with keys of 'branches' and 'tags'.
+  """
+  path = 'projects/%s/commits/%s/in' % (urllib.parse.quote(project, ''), commit)
+  conn = CreateHttpConn(host, path, reqtype='GET')
+  return ReadHttpJsonResponse(conn, accept_statuses=[200])
+
+
 def IsCodeOwnersEnabledOnHost(host):
   """Check if the code-owners plugin is enabled for the host."""
   path = 'config/server/capabilities'