Commit fb09de29 authored by Stephen Martinis's avatar Stephen Martinis Committed by LUCI CQ

Revert "Use GetCodeOwnersClient in presubmit_support"

This reverts commit 7a67bca6.

Reason for revert: Probably broke chromium presubmit, see https://ci.chromium.org/ui/p/chromium/builders/try/chromium_presubmit/1152280/overview

Original change's description:
> Use GetCodeOwnersClient in presubmit_support
>
> This change also adds a target_ref flag to presubmit_support.py.
>
> Recipe-Nontrivial-Roll: build
> Change-Id: I6de6bb87fc1482b88d9fbebe5e4ad1dbd8ce9748
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2702792
> Commit-Queue: Gavin Mak <gavinmak@google.com>
> Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
> Reviewed-by: Josip Sokcevic <sokcevic@google.com>

Change-Id: I2cca469f14194f65306baab7928ddddd48033a3b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2718691
Auto-Submit: Stephen Martinis <martiniss@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
parent 7a67bca6
...@@ -1294,8 +1294,6 @@ class Changelist(object): ...@@ -1294,8 +1294,6 @@ class Changelist(object):
gerrit_url = self.GetCodereviewServer() gerrit_url = self.GetCodereviewServer()
issue = self.GetIssue() issue = self.GetIssue()
patchset = self.GetPatchset() patchset = self.GetPatchset()
remote, remote_branch = self.GetRemoteBranch()
target_ref = GetTargetRef(remote, remote_branch, None)
if author: if author:
args.extend(['--author', author]) args.extend(['--author', author])
if gerrit_url: if gerrit_url:
...@@ -1304,8 +1302,6 @@ class Changelist(object): ...@@ -1304,8 +1302,6 @@ class Changelist(object):
args.extend(['--issue', str(issue)]) args.extend(['--issue', str(issue)])
if patchset: if patchset:
args.extend(['--patchset', str(patchset)]) args.extend(['--patchset', str(patchset)])
if target_ref:
args.extend(['--target_ref', target_ref])
return args return args
......
...@@ -228,6 +228,6 @@ def GetCodeOwnersClient(root, host, project, branch): ...@@ -228,6 +228,6 @@ def GetCodeOwnersClient(root, host, project, branch):
Defaults to GerritClient, and falls back to DepotToolsClient if code-owners Defaults to GerritClient, and falls back to DepotToolsClient if code-owners
plugin is not available.""" plugin is not available."""
if host and gerrit_util.IsCodeOwnersEnabled(host): if gerrit_util.IsCodeOwnersEnabled(host):
return GerritClient(host, project, branch) return GerritClient(host, project, branch)
return DepotToolsClient(root, branch) return DepotToolsClient(root, branch)
...@@ -376,10 +376,8 @@ class GerritAccessor(object): ...@@ -376,10 +376,8 @@ class GerritAccessor(object):
To avoid excessive Gerrit calls, caches the results. To avoid excessive Gerrit calls, caches the results.
""" """
def __init__(self, host, project=None, branch=None): def __init__(self, host):
self.host = host self.host = host
self.project = project
self.branch = branch
self.cache = {} self.cache = {}
def _FetchChangeDetail(self, issue): def _FetchChangeDetail(self, issue):
...@@ -652,19 +650,10 @@ class InputApi(object): ...@@ -652,19 +650,10 @@ class InputApi(object):
# Temporary files we must manually remove at the end of a run. # Temporary files we must manually remove at the end of a run.
self._named_temporary_files = [] self._named_temporary_files = []
host = '' # TODO(dpranke): figure out a list of all approved owners for a repo
project = '' # in order to be able to handle wildcard OWNERS files?
branch = '' self.owners_client = owners_client.DepotToolsClient(
if gerrit_obj: change.RepositoryRoot(), change.UpstreamBranch(), os_path=self.os_path)
host = gerrit_obj.host or ''
project = gerrit_obj.project or ''
branch = gerrit_obj.branch or ''
self.owners_client = owners_client.GetCodeOwnersClient(
root=change.RepositoryRoot(),
host=host,
project=project,
branch=branch)
self.owners_db = owners_db.Database( self.owners_db = owners_db.Database(
change.RepositoryRoot(), fopen=open, os_path=self.os_path) change.RepositoryRoot(), fopen=open, os_path=self.os_path)
self.owners_finder = owners_finder.OwnersFinder self.owners_finder = owners_finder.OwnersFinder
...@@ -1518,7 +1507,7 @@ def DoPostUploadExecuter(change, ...@@ -1518,7 +1507,7 @@ def DoPostUploadExecuter(change,
class PresubmitExecuter(object): class PresubmitExecuter(object):
def __init__(self, change, committing, verbose, gerrit_obj, dry_run=None, def __init__(self, change, committing, verbose, gerrit_obj, dry_run=None,
thread_pool=None, parallel=False): thread_pool=None, parallel=False, gerrit_project=None):
""" """
Args: Args:
change: The Change object. change: The Change object.
...@@ -1536,6 +1525,7 @@ class PresubmitExecuter(object): ...@@ -1536,6 +1525,7 @@ class PresubmitExecuter(object):
self.more_cc = [] self.more_cc = []
self.thread_pool = thread_pool self.thread_pool = thread_pool
self.parallel = parallel self.parallel = parallel
self.gerrit_project = gerrit_project
def ExecPresubmitScript(self, script_text, presubmit_path): def ExecPresubmitScript(self, script_text, presubmit_path):
"""Executes a single presubmit script. """Executes a single presubmit script.
...@@ -1578,10 +1568,9 @@ class PresubmitExecuter(object): ...@@ -1578,10 +1568,9 @@ class PresubmitExecuter(object):
# Get the URL of git remote origin and use it to identify host and project # Get the URL of git remote origin and use it to identify host and project
host = '' host = ''
project = '' if self.gerrit and self.gerrit.host:
if self.gerrit: host = self.gerrit.host
host = self.gerrit.host or '' project = self.gerrit_project or ''
project = self.gerrit.project or ''
# Prefix for test names # Prefix for test names
prefix = 'presubmit:%s/%s:%s/' % (host, project, rel_path) prefix = 'presubmit:%s/%s:%s/' % (host, project, rel_path)
...@@ -1680,7 +1669,8 @@ def DoPresubmitChecks(change, ...@@ -1680,7 +1669,8 @@ def DoPresubmitChecks(change,
gerrit_obj, gerrit_obj,
dry_run=None, dry_run=None,
parallel=False, parallel=False,
json_output=None): json_output=None,
gerrit_project=None):
"""Runs all presubmit checks that apply to the files in the change. """Runs all presubmit checks that apply to the files in the change.
This finds all PRESUBMIT.py files in directories enclosing the files in the This finds all PRESUBMIT.py files in directories enclosing the files in the
...@@ -1723,7 +1713,7 @@ def DoPresubmitChecks(change, ...@@ -1723,7 +1713,7 @@ def DoPresubmitChecks(change,
results = [] results = []
thread_pool = ThreadPool() thread_pool = ThreadPool()
executer = PresubmitExecuter(change, committing, verbose, gerrit_obj, executer = PresubmitExecuter(change, committing, verbose, gerrit_obj,
dry_run, thread_pool, parallel) dry_run, thread_pool, parallel, gerrit_project)
if default_presubmit: if default_presubmit:
if verbose: if verbose:
sys.stdout.write('Running default presubmit script.\n') sys.stdout.write('Running default presubmit script.\n')
...@@ -1880,15 +1870,11 @@ def _parse_gerrit_options(parser, options): ...@@ -1880,15 +1870,11 @@ def _parse_gerrit_options(parser, options):
parser: The parser used to parse the arguments from command line. parser: The parser used to parse the arguments from command line.
options: The arguments parsed from command line. options: The arguments parsed from command line.
Returns: Returns:
A GerritAccessor object if options.gerrit_url or options.gerrit_project are A GerritAccessor object if options.gerrit_url is set, or None otherwise.
set, or None otherwise.
""" """
gerrit_obj = None gerrit_obj = None
if options.gerrit_url or options.gerrit_project: if options.gerrit_url:
gerrit_obj = GerritAccessor( gerrit_obj = GerritAccessor(urlparse.urlparse(options.gerrit_url).netloc)
urlparse.urlparse(options.gerrit_url or '').netloc,
options.gerrit_project,
options.target_ref)
if not options.gerrit_fetch: if not options.gerrit_fetch:
return gerrit_obj return gerrit_obj
...@@ -1974,8 +1960,6 @@ def main(argv=None): ...@@ -1974,8 +1960,6 @@ def main(argv=None):
'executing presubmit or post-upload hooks. fnmatch ' 'executing presubmit or post-upload hooks. fnmatch '
'wildcards can also be used.') 'wildcards can also be used.')
parser.add_argument('--gerrit_project', help=argparse.SUPPRESS) parser.add_argument('--gerrit_project', help=argparse.SUPPRESS)
parser.add_argument('--target_ref',
help='The remote branch ref to use for the change.')
options = parser.parse_args(argv) options = parser.parse_args(argv)
log_level = logging.ERROR log_level = logging.ERROR
...@@ -2008,7 +1992,8 @@ def main(argv=None): ...@@ -2008,7 +1992,8 @@ def main(argv=None):
gerrit_obj, gerrit_obj,
options.dry_run, options.dry_run,
options.parallel, options.parallel,
options.json_output) options.json_output,
options.gerrit_project)
except PresubmitFailure as e: except PresubmitFailure as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
print('Maybe your depot_tools is out of date?', file=sys.stderr) print('Maybe your depot_tools is out of date?', file=sys.stderr)
......
...@@ -98,7 +98,6 @@ class PresubmitApi(recipe_api.RecipeApi): ...@@ -98,7 +98,6 @@ class PresubmitApi(recipe_api.RecipeApi):
'--issue', self.m.tryserver.gerrit_change.change, '--issue', self.m.tryserver.gerrit_change.change,
'--patchset', self.m.tryserver.gerrit_change.patchset, '--patchset', self.m.tryserver.gerrit_change.patchset,
'--gerrit_url', 'https://%s' % self.m.tryserver.gerrit_change.host, '--gerrit_url', 'https://%s' % self.m.tryserver.gerrit_change.host,
'--target_ref', self.m.tryserver.gerrit_change_target_ref,
'--gerrit_fetch', '--gerrit_fetch',
] ]
if self.m.cq.state == self.m.cq.DRY: if self.m.cq.state == self.m.cq.DRY:
......
...@@ -2958,9 +2958,6 @@ class ChangelistTest(unittest.TestCase): ...@@ -2958,9 +2958,6 @@ class ChangelistTest(unittest.TestCase):
mock.patch('git_cl.Changelist.GetAuthor', return_value='author').start() mock.patch('git_cl.Changelist.GetAuthor', return_value='author').start()
mock.patch('git_cl.Changelist.GetIssue', return_value=123456).start() mock.patch('git_cl.Changelist.GetIssue', return_value=123456).start()
mock.patch('git_cl.Changelist.GetPatchset', return_value=7).start() mock.patch('git_cl.Changelist.GetPatchset', return_value=7).start()
mock.patch('git_cl.Changelist.GetRemoteBranch',
return_value=('foo', 'bar')).start()
mock.patch('git_cl.GetTargetRef', return_value='ref').start()
mock.patch('git_cl.PRESUBMIT_SUPPORT', 'PRESUBMIT_SUPPORT').start() mock.patch('git_cl.PRESUBMIT_SUPPORT', 'PRESUBMIT_SUPPORT').start()
mock.patch('git_cl.Settings.GetRoot', return_value='root').start() mock.patch('git_cl.Settings.GetRoot', return_value='root').start()
mock.patch('git_cl.time_time').start() mock.patch('git_cl.time_time').start()
...@@ -3003,7 +3000,6 @@ class ChangelistTest(unittest.TestCase): ...@@ -3003,7 +3000,6 @@ class ChangelistTest(unittest.TestCase):
'--gerrit_url', 'https://chromium-review.googlesource.com', '--gerrit_url', 'https://chromium-review.googlesource.com',
'--issue', '123456', '--issue', '123456',
'--patchset', '7', '--patchset', '7',
'--target_ref', 'ref',
'--commit', '--commit',
'--may_prompt', '--may_prompt',
'--parallel', '--parallel',
...@@ -3052,7 +3048,6 @@ class ChangelistTest(unittest.TestCase): ...@@ -3052,7 +3048,6 @@ class ChangelistTest(unittest.TestCase):
'vpython', 'PRESUBMIT_SUPPORT', 'vpython', 'PRESUBMIT_SUPPORT',
'--root', 'root', '--root', 'root',
'--upstream', 'upstream', '--upstream', 'upstream',
'--target_ref', 'ref',
'--upload', '--upload',
'--json_output', '/tmp/fake-temp2', '--json_output', '/tmp/fake-temp2',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
...@@ -3100,7 +3095,6 @@ class ChangelistTest(unittest.TestCase): ...@@ -3100,7 +3095,6 @@ class ChangelistTest(unittest.TestCase):
'vpython', 'PRESUBMIT_SUPPORT', 'vpython', 'PRESUBMIT_SUPPORT',
'--root', 'root', '--root', 'root',
'--upstream', 'upstream', '--upstream', 'upstream',
'--target_ref', 'ref',
'--upload', '--upload',
'--json_output', '/tmp/fake-temp2', '--json_output', '/tmp/fake-temp2',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
...@@ -3141,7 +3135,6 @@ class ChangelistTest(unittest.TestCase): ...@@ -3141,7 +3135,6 @@ class ChangelistTest(unittest.TestCase):
'--gerrit_url', 'https://chromium-review.googlesource.com', '--gerrit_url', 'https://chromium-review.googlesource.com',
'--issue', '123456', '--issue', '123456',
'--patchset', '7', '--patchset', '7',
'--target_ref', 'ref',
'--post_upload', '--post_upload',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
]) ])
......
...@@ -275,13 +275,6 @@ class GetCodeOwnersClientTest(unittest.TestCase): ...@@ -275,13 +275,6 @@ class GetCodeOwnersClientTest(unittest.TestCase):
mock.patch('gerrit_util.IsCodeOwnersEnabled').start() mock.patch('gerrit_util.IsCodeOwnersEnabled').start()
self.addCleanup(mock.patch.stopall) self.addCleanup(mock.patch.stopall)
def testGetCodeOwnersClient_NoHost(self):
owners_client.GetCodeOwnersClient('root', None, 'project', 'branch')
gerrit_util.IsCodeOwnersEnabled.assert_not_called()
owners_client.GetCodeOwnersClient('root', '', 'project', 'branch')
gerrit_util.IsCodeOwnersEnabled.assert_not_called()
def testGetCodeOwnersClient_GerritClient(self): def testGetCodeOwnersClient_GerritClient(self):
gerrit_util.IsCodeOwnersEnabled.return_value = True gerrit_util.IsCodeOwnersEnabled.return_value = True
self.assertIsInstance( self.assertIsInstance(
......
...@@ -184,7 +184,6 @@ index fe3de7b..54ae6e1 100755 ...@@ -184,7 +184,6 @@ index fe3de7b..54ae6e1 100755
mock.patch('os.path.abspath', lambda f: f).start() mock.patch('os.path.abspath', lambda f: f).start()
mock.patch('os.path.isfile').start() mock.patch('os.path.isfile').start()
mock.patch('os.remove').start() mock.patch('os.remove').start()
mock.patch('owners_client.GetCodeOwnersClient').start()
mock.patch('presubmit_support._parse_files').start() mock.patch('presubmit_support._parse_files').start()
mock.patch('presubmit_support.rdb_wrapper.client', mock.patch('presubmit_support.rdb_wrapper.client',
return_value=self.rdb_client).start() return_value=self.rdb_client).start()
...@@ -1145,10 +1144,9 @@ def CheckChangeOnCommit(input_api, output_api): ...@@ -1145,10 +1144,9 @@ def CheckChangeOnCommit(input_api, output_api):
upstream=options.upstream) upstream=options.upstream)
scm.GIT.GetAllFiles.assert_called_once_with(options.root) scm.GIT.GetAllFiles.assert_called_once_with(options.root)
def testParseGerritOptions_NoGerritUrlOrProject(self): def testParseGerritOptions_NoGerritUrl(self):
options = mock.Mock( options = mock.Mock(
gerrit_url=None, gerrit_url=None,
gerrit_project=None,
gerrit_fetch=False, gerrit_fetch=False,
author='author', author='author',
description='description') description='description')
...@@ -1162,16 +1160,14 @@ def CheckChangeOnCommit(input_api, output_api): ...@@ -1162,16 +1160,14 @@ def CheckChangeOnCommit(input_api, output_api):
def testParseGerritOptions_NoGerritFetch(self): def testParseGerritOptions_NoGerritFetch(self):
options = mock.Mock( options = mock.Mock(
gerrit_url='https://foo-review.googlesource.com/bar', gerrit_url='https://foo-review.googlesource.com/bar',
gerrit_project='baz/project',
gerrit_fetch=False, gerrit_fetch=False,
target_ref='refs/heads/foobar',
author='author', author='author',
description='description') description='description')
gerrit_obj = presubmit._parse_gerrit_options(None, options) gerrit_obj = presubmit._parse_gerrit_options(None, options)
presubmit.GerritAccessor.assert_called_once_with( presubmit.GerritAccessor.assert_called_once_with(
'foo-review.googlesource.com', 'baz/project', 'refs/heads/foobar') 'foo-review.googlesource.com')
self.assertEqual(presubmit.GerritAccessor.return_value, gerrit_obj) self.assertEqual(presubmit.GerritAccessor.return_value, gerrit_obj)
self.assertEqual('author', options.author) self.assertEqual('author', options.author)
self.assertEqual('description', options.description) self.assertEqual('description', options.description)
...@@ -1185,16 +1181,14 @@ def CheckChangeOnCommit(input_api, output_api): ...@@ -1185,16 +1181,14 @@ def CheckChangeOnCommit(input_api, output_api):
options = mock.Mock( options = mock.Mock(
gerrit_url='https://foo-review.googlesource.com/bar', gerrit_url='https://foo-review.googlesource.com/bar',
gerrit_project='baz/project',
gerrit_fetch=True, gerrit_fetch=True,
target_ref='refs/heads/foobar',
issue=123, issue=123,
patchset=4) patchset=4)
gerrit_obj = presubmit._parse_gerrit_options(None, options) gerrit_obj = presubmit._parse_gerrit_options(None, options)
presubmit.GerritAccessor.assert_called_once_with( presubmit.GerritAccessor.assert_called_once_with(
'foo-review.googlesource.com', 'baz/project', 'refs/heads/foobar') 'foo-review.googlesource.com')
self.assertEqual(presubmit.GerritAccessor.return_value, gerrit_obj) self.assertEqual(presubmit.GerritAccessor.return_value, gerrit_obj)
self.assertEqual('new owner', options.author) self.assertEqual('new owner', options.author)
self.assertEqual('new description', options.description) self.assertEqual('new description', options.description)
......
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