scripts: set_assignee: Make review requests more deterministic
When there are more than 15 reviewers, the `set_assignee` script was adding the reviewers more or less on a random basis because the input set was arbitrarily ordered (thanks to how Python "set" works), and the attempt to add any reviewers beyond the count of 15 results in the previoulsy added reviewer being removed. This commit updates the `set_assignee` script such that: 1. The collaborator list (input for generating the reviewer list) is ordered by the area match, such that the collaborators of the most relevant area come first. 2. The reviewers of the relevant areas are added first, until the total reviewer count is 15. The script does not attempt to add more than 15 reviewers because that can result in the previously added reviewers being removed from the list. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
parent
bc78a03ca0
commit
faf4208295
1 changed files with 22 additions and 11 deletions
|
@ -55,7 +55,6 @@ def process_pr(gh, maintainer_file, number):
|
|||
log(f"working on https://github.com/{args.org}/{args.repo}/pull/{pr.number} : {pr.title}")
|
||||
|
||||
labels = set()
|
||||
collab = set()
|
||||
area_counter = defaultdict(int)
|
||||
maint = defaultdict(int)
|
||||
|
||||
|
@ -75,19 +74,24 @@ def process_pr(gh, maintainer_file, number):
|
|||
for a in areas:
|
||||
area_counter[a.name] += 1
|
||||
labels.update(a.labels)
|
||||
collab.update(a.collaborators)
|
||||
collab.update(a.maintainers)
|
||||
for p in a.maintainers:
|
||||
maint[p] += 1
|
||||
|
||||
ac = dict(sorted(area_counter.items(), key=lambda item: item[1], reverse=True))
|
||||
log(f"Area matches: {ac}")
|
||||
log(f"labels: {labels}")
|
||||
log(f"collab: {collab}")
|
||||
if len(labels) > 10:
|
||||
log(f"Too many labels to be applied")
|
||||
return
|
||||
|
||||
# Create a list of collaborators ordered by the area match
|
||||
collab = list()
|
||||
for a in ac:
|
||||
collab += maintainer_file.areas[a].maintainers
|
||||
collab += maintainer_file.areas[a].collaborators
|
||||
collab = list(dict.fromkeys(collab))
|
||||
log(f"collab: {collab}")
|
||||
|
||||
sm = dict(sorted(maint.items(), key=lambda item: item[1], reverse=True))
|
||||
|
||||
log(f"Submitted by: {pr.user.login}")
|
||||
|
@ -168,13 +172,20 @@ def process_pr(gh, maintainer_file, number):
|
|||
except UnknownObjectException as e:
|
||||
log(f"Can't get user '{c}', account does not exist anymore? ({e})")
|
||||
|
||||
if reviewers:
|
||||
try:
|
||||
log(f"adding reviewers {reviewers}...")
|
||||
if not args.dry_run:
|
||||
pr.create_review_request(reviewers=reviewers)
|
||||
except GithubException:
|
||||
log("cant add reviewer")
|
||||
if len(existing_reviewers) < 15:
|
||||
reviewer_vacancy = 15 - len(existing_reviewers)
|
||||
reviewers = reviewers[:reviewer_vacancy]
|
||||
|
||||
if reviewers:
|
||||
try:
|
||||
log(f"adding reviewers {reviewers}...")
|
||||
if not args.dry_run:
|
||||
pr.create_review_request(reviewers=reviewers)
|
||||
except GithubException:
|
||||
log("cant add reviewer")
|
||||
else:
|
||||
log("not adding reviewers because the existing reviewer count is greater than or "
|
||||
"equal to 15")
|
||||
|
||||
ms = []
|
||||
# assignees
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue