From af79f24cae4d1d044c2c1e3f51b8e9227aab189c Mon Sep 17 00:00:00 2001 From: Xinan Lin Date: Mon, 9 Aug 2021 21:23:58 +0000 Subject: [PATCH] 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/+/3077363 Reviewed-by: Michael Moss Reviewed-by: Anthony Polito Commit-Queue: Xinan Lin --- gerrit_util.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index 9a8a2db41..c3a058b10 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -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):