Randomize results of git cl owners

git cl owners orders owners by score with alphabetization being the tie
breaker. This leads to some owners being suggested far more often than
others.

Adding a tiny amount of randomization to the scoring leads to an even
distribution of equally qualified reviewers. Less qualified reviewers
will still be sorted into distinct buckets - the randomness is too small
to do anything except break ties.

The tests were updated so that they can tolerate the randomness, but
only for breaking ties.

Bug: 1024083
Change-Id: If7d39d1b3bbd980b80b46ab3f62c65215309bdc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1913642
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
Bruce Dawson
2019-11-14 00:27:44 +00:00
committed by Commit Bot
parent 088977a7a7
commit 37740e2bc9
3 changed files with 30 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ from __future__ import print_function
import os
import copy
import owners as owners_module
import random
def first(iterable):
@@ -161,10 +162,12 @@ class OwnersFinder(object):
self.selected_owners = set()
self.deselected_owners = set()
# Initialize owners queue, sort it by the score and name
self.owners_queue = sorted(
self.owners_to_files.keys(),
key=lambda owner: (self.owners_score[owner], owner))
# Randomize owners' names so that if many reviewers have identical scores
# they will be randomly ordered to avoid bias.
owners = list(self.owners_to_files.keys())
random.shuffle(owners)
self.owners_queue = sorted(owners,
key=lambda owner: self.owners_score[owner])
self.find_mandatory_owners()
def select_owner(self, owner, findMandatoryOwners=True):