blob: 9bc7145c30ca27a7343a977d47a1ef387e2752ef [file] [log] [blame]
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This is a client to talk to the APIs in"""
import json
_REDIRECT_API = '%s/_ah/api/crrev/v1/redirect' % _CRREV_HOST
def RedirectByCommitPosition(http_client, commit_position):
"""Returns the info for a Chromium commit position.
http_client (libs.http.RetryHttpClient): the http client to send request.
commit_position (int): the Chromium commit position of a git commit.
A dict containing the following info, or None if there is error.
"git_sha": "the sha of the git commit",
"repo_url": ""
url = _REDIRECT_API + '/' + str(commit_position)
status_code, content, _response_headers = http_client.Get(url)
if status_code != 200:
return None
data = json.loads(content)
return {
'git_sha': data['git_sha'],
'repo_url': data['repo_url'],