blob: b5acc86ae64c407599830676645bb08b5220419d [file] [log] [blame]
Edward Lesmes91bb7502020-11-06 00:50:24 +00001# Copyright (c) 2020 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Edward Lesmesb4f42262020-11-10 23:41:35 +00005import owners
6
Edward Lesmes91bb7502020-11-06 00:50:24 +00007
8class OwnersClient(object):
9 """Interact with OWNERS files in a repository.
10
11 This class allows you to interact with OWNERS files in a repository both the
12 Gerrit Code-Owners plugin REST API, and the owners database implemented by
13 Depot Tools in owners.py:
14
15 - List all the owners for a change.
16 - Check if a change has been approved.
17 - Check if the OWNERS configuration in a change is valid.
18
19 All code should use this class to interact with OWNERS files instead of the
20 owners database in owners.py
21 """
22 def __init__(self, host):
23 self._host = host
24
25 def ListOwnersForFile(self, project, branch, path):
26 """List all owners for a file."""
27 raise Exception('Not implemented')
28
Edward Lesmesb4f42262020-11-10 23:41:35 +000029 def IsChangeApproved(self, change_id):
Edward Lesmes91bb7502020-11-06 00:50:24 +000030 """Check if the latest patch set for a change has been approved."""
31 raise Exception('Not implemented')
32
Edward Lesmesb4f42262020-11-10 23:41:35 +000033 def IsOwnerConfigurationValid(self, change_id, patch):
Edward Lesmes91bb7502020-11-06 00:50:24 +000034 """Check if the owners configuration in a change is valid."""
35 raise Exception('Not implemented')
Edward Lesmesb4f42262020-11-10 23:41:35 +000036
37
38class DepotToolsClient(OwnersClient):
39 """Implement OwnersClient using owners.py Database."""
40 def __init__(self, host, root):
41 super(DepotToolsClient, self).__init__(host)
42 self._root = root
43 self._db = owners.Database(root, open, os.path)
44
45 def ListOwnersForFile(self, _project, _branch, path):
46 return sorted(self._db.all_possible_owners([arg], None))