Commit c2fb26a3 authored by Xinan Lin's avatar Xinan Lin Committed by LUCI CQ

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/+/3044919Reviewed-by: 's avatarDirk Pranke <dpranke@google.com>
Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
parent 690ba8f9
......@@ -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."""
......
......@@ -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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment