Commit 603d01e8 authored by Mun Yong Jang's avatar Mun Yong Jang Committed by Commit Bot

[presubmit] Use GerritAccessor in CheckChangedLUCIConfigs

For tryjobs, determine the remote branch using GerritAccessor

Bug: 761488
Change-Id: Ieea6028d222af0014ec3a57c3ad7b7eb8af5ec33
Reviewed-on: https://chromium-review.googlesource.com/834995Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent aac382b3
......@@ -1244,13 +1244,16 @@ def CheckChangedLUCIConfigs(input_api, output_api):
LUCI_CONFIG_HOST_NAME = 'luci-config.appspot.com'
cl = git_cl.Changelist()
remote, remote_branch = cl.GetRemoteBranch()
if remote_branch.startswith('refs/remotes/%s/' % remote):
remote_branch = remote_branch.replace(
'refs/remotes/%s/' % remote, 'refs/heads/', 1)
if remote_branch.startswith('refs/remotes/branch-heads/'):
remote_branch = remote_branch.replace(
'refs/remotes/branch-heads/', 'refs/branch-heads/', 1)
if input_api.change.issue and input_api.gerrit:
remote_branch = input_api.gerrit.GetDestRef(input_api.change.issue)
else:
remote, remote_branch = cl.GetRemoteBranch()
if remote_branch.startswith('refs/remotes/%s/' % remote):
remote_branch = remote_branch.replace(
'refs/remotes/%s/' % remote, 'refs/heads/', 1)
if remote_branch.startswith('refs/remotes/branch-heads/'):
remote_branch = remote_branch.replace(
'refs/remotes/branch-heads/', 'refs/branch-heads/', 1)
remote_host_url = cl.GetRemoteUrl()
if not remote_host_url:
......
......@@ -245,6 +245,14 @@ class GerritAccessor(object):
return rev_info['commit']['message']
def GetDestRef(self, issue):
ref = self.GetChangeInfo(issue)['branch']
if not ref.startswith('refs/'):
# NOTE: it is possible to create 'refs/x' branch,
# aka 'refs/heads/refs/x'. However, this is ill-advised.
ref = 'refs/heads/%s' % ref
return ref
def GetChangeOwner(self, issue):
return self.GetChangeInfo(issue)['owner']['email']
......
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