[owners] Fix SuggestOwners when there is only one owner.

If there are less than two owners for the given paths,
current implementation will get stuck in infinite loop.

Change it to return any possible owner.

Change-Id: I75f18e0a00057c58d227dac23dc8572f1fba23f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2572802
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
diff --git a/owners_client.py b/owners_client.py
index 7bd6ec8..01b3f18 100644
--- a/owners_client.py
+++ b/owners_client.py
@@ -38,7 +38,6 @@
   return reversed(list(itertools.combinations(reversed(owners), num_owners)))
 
 
-
 class InvalidOwnersConfig(Exception):
   pass
 
@@ -124,15 +123,16 @@
     # Select the minimum number of owners that can approve all paths.
     # We start at 2 to avoid sending all changes that require multiple reviewers
     # to top-level owners.
-    num_owners = 2
-    while True:
+    if len(owners) < 2:
+      return owners
+
+    for num_owners in range(2, len(owners)):
       # Iterate all combinations of `num_owners` by decreasing score, and select
       # the first one that covers all paths.
       for selected in _owner_combinations(owners, num_owners):
         covered = set.union(*(paths_by_owner[o] for o in selected))
         if len(covered) == len(paths):
           return selected
-      num_owners += 1
 
 
 class DepotToolsClient(OwnersClient):
diff --git a/tests/owners_client_test.py b/tests/owners_client_test.py
index fc58c90..489bb71 100644
--- a/tests/owners_client_test.py
+++ b/tests/owners_client_test.py
@@ -166,6 +166,11 @@
          (emily, dave)])
 
   def testSuggestOwners(self):
+    self.client.owners_by_path = {'a': [alice]}
+    self.assertEqual(
+        self.client.SuggestOwners('project', 'branch', ['a']),
+        [alice])
+
     self.client.owners_by_path = {'abcd': [alice, bob, chris, dave]}
     self.assertEqual(
         self.client.SuggestOwners('project', 'branch', ['abcd']),