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

GetGerritBranch should return None if the branch does not exist

Currently gerrit_client retries if received 404, which does not
provide anything meaningful.
It is nature to get 404 for a non-exist branch. I am not sure why
we raise a 200 error per an empty response. I think
we could just accept 404 and return it like other GET functions, e.g.
GetAccountDetails().

BUG=1208430
TEST=local

Change-Id: I054bad99b69c54cc125141108299193f5cc092de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3077363Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
parent ee1a2c72
......@@ -1042,20 +1042,17 @@ def UpdateHead(host, project, branch):
def GetGerritBranch(host, project, branch):
"""Gets a branch from given project and commit.
"""Gets a branch info from given project and branch name.
See:
https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#get-branch
Returns:
A JSON object with 'revision' key.
A JSON object with 'revision' key if the branch exists, otherwise None.
"""
path = 'projects/%s/branches/%s' % (project, branch)
conn = CreateHttpConn(host, path, reqtype='GET')
response = ReadHttpJsonResponse(conn)
if response:
return response
raise GerritError(200, 'Unable to get gerrit branch')
return ReadHttpJsonResponse(conn, accept_statuses=[200, 404])
def GetProjectHead(host, project):
......
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