From 603d01e818babc0b25904be0f73036c60f290b62 Mon Sep 17 00:00:00 2001 From: Mun Yong Jang Date: Tue, 19 Dec 2017 16:38:30 -0800 Subject: [PATCH] [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/834995 Reviewed-by: Andrii Shyshkalov Commit-Queue: Andrii Shyshkalov --- presubmit_canned_checks.py | 17 ++++++++++------- presubmit_support.py | 8 ++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index b2eb00f4e..2cc710cc3 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -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: diff --git a/presubmit_support.py b/presubmit_support.py index 8a68a45d1..ab3f3d70b 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -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']