util: Make gerrit bot respect reviewer removal
Currently, if a maintainer is removed from a change, the maintainer will be added again. This change prevents the bot from adding the removed maintainer again. The bot will query all updates related to reviewer addition/removal for each new change. If a reviewer has ever been added/removed from a change, that reviewer won't be added to that change again. Change-Id: Ifaab5ebd7ebf3e6453b2551d3e37c1b9e214c906 Signed-off-by: Hoa Nguyen <hoanguyen@ucdavis.edu> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50187 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
This commit is contained in:
@@ -170,9 +170,10 @@ class GerritBot:
|
||||
def __query_new_changes(self, query_age):
|
||||
query = (f"projects:{self.config.projects_prefix} "
|
||||
f"status:open -is:wip -age:{query_age}")
|
||||
response = self.gerrit_api.query_changes(query,
|
||||
self.config.query_limit,
|
||||
"CURRENT_REVISION")
|
||||
response = self.gerrit_api.query_changes(
|
||||
query, self.config.query_limit,
|
||||
["CURRENT_REVISION", "REVIEWER_UPDATES", "DETAILED_ACCOUNTS"]
|
||||
)
|
||||
|
||||
if response.status_code >= 300:
|
||||
print("Error: Couldn't query new Gerrit changes")
|
||||
|
||||
@@ -60,6 +60,14 @@ def add_maintainers_to_change(change, maintainers, maintainers_account_ids,
|
||||
tags, message = parse_commit_subject(change["subject"])
|
||||
change_id = change["id"]
|
||||
maintainer_emails = set()
|
||||
|
||||
# There are cases that a reviewer being removed from the reviewer list
|
||||
# by another reviewer. We want to respect this removal. To do this,
|
||||
# we can avoid adding reviewers that have been added/removed to the
|
||||
# reviewer list.
|
||||
avoid_emails = set()
|
||||
for update in change["reviewer_updates"]:
|
||||
avoid_emails.add(update["reviewer"]["email"])
|
||||
for tag in tags:
|
||||
try:
|
||||
for name, email in maintainers[tag].maintainers:
|
||||
@@ -68,6 +76,8 @@ def add_maintainers_to_change(change, maintainers, maintainers_account_ids,
|
||||
print((f"warning: `change-{change_id}` has an unknown tag: "
|
||||
f"`{tag}`"))
|
||||
for email in maintainer_emails:
|
||||
if email in avoid_emails:
|
||||
continue
|
||||
try:
|
||||
account_id = maintainers_account_ids[email]
|
||||
gerrit_api.add_reviewer(change_id, account_id)
|
||||
|
||||
Reference in New Issue
Block a user