Edward Lesmes | 91bb750 | 2020-11-06 00:50:24 +0000 | [diff] [blame] | 1 | # 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 Lesmes | b4f4226 | 2020-11-10 23:41:35 +0000 | [diff] [blame] | 5 | import owners |
| 6 | |
Edward Lesmes | 91bb750 | 2020-11-06 00:50:24 +0000 | [diff] [blame] | 7 | |
| 8 | class 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 Lesmes | b4f4226 | 2020-11-10 23:41:35 +0000 | [diff] [blame] | 29 | def IsChangeApproved(self, change_id): |
Edward Lesmes | 91bb750 | 2020-11-06 00:50:24 +0000 | [diff] [blame] | 30 | """Check if the latest patch set for a change has been approved.""" |
| 31 | raise Exception('Not implemented') |
| 32 | |
Edward Lesmes | b4f4226 | 2020-11-10 23:41:35 +0000 | [diff] [blame] | 33 | def IsOwnerConfigurationValid(self, change_id, patch): |
Edward Lesmes | 91bb750 | 2020-11-06 00:50:24 +0000 | [diff] [blame] | 34 | """Check if the owners configuration in a change is valid.""" |
| 35 | raise Exception('Not implemented') |
Edward Lesmes | b4f4226 | 2020-11-10 23:41:35 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | class 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)) |