[owners] Implement GetFilesApprovalStatus for OwnersClient.

Add a utility method to check approval status for files
when no change has been created yet.

Change-Id: I4cc47e2f598cedc7b7aab68bed356bd3ae566cc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2551373
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
diff --git a/owners_client.py b/owners_client.py
index 3d15020..e5f2be1 100644
--- a/owners_client.py
+++ b/owners_client.py
@@ -54,6 +54,28 @@
     """Check if the owners configuration in a change is valid."""
     raise Exception('Not implemented')
 
+  def GetFilesApprovalStatus(
+      self, project, branch, paths, approvers, reviewers):
+    """Check the approval status for the given paths.
+
+    Utility method to check for approval status when a change has not yet been
+    created, given reviewers and approvers.
+
+    See GetChangeApprovalStatus for description of the returned value.
+    """
+    approvers = set(approvers)
+    reviewers = set(reviewers)
+    status = {}
+    for path in paths:
+      path_owners = set(self.ListOwnersForFile(project, branch, path))
+      if path_owners.intersection(approvers):
+        status[path] = APPROVED
+      elif path_owners.intersection(reviewers):
+        status[path] = PENDING
+      else:
+        status[path] = INSUFFICIENT_REVIEWERS
+    return status
+
 
 class DepotToolsClient(OwnersClient):
   """Implement OwnersClient using owners.py Database."""
@@ -90,18 +112,7 @@
     approvers = [v['email'] for v in label['all'] if v['value'] == max_value]
 
     files = data['revisions'][data['current_revision']]['files']
-
-    self._db.load_data_needed_for(files)
-
-    status = {}
-    for f in files:
-      if self._db.is_covered_by(f, approvers):
-        status[f] = APPROVED
-      elif self._db.is_covered_by(f, reviewers):
-        status[f] = PENDING
-      else:
-        status[f] = INSUFFICIENT_REVIEWERS
-    return status
+    return self.GetFilesApprovalStatus(None, None, files, approvers, reviewers)
 
   def ValidateOwnersConfig(self, change_id):
     data = gerrit_util.GetChange(