This bot utilizes the Gerrit REST API to query for new changes made to Gerrit within a certain amount of time and performs a set of tests on the changes. Signed-off-by: Hoa Nguyen <hoanguyen@ucdavis.edu> Change-Id: I9d5af31d952bc0cd791f1569e6aac7c270e687e4 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34737 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu> Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2020 The Regents of the University of California
|
|
# All Rights Reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions are
|
|
# met: redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer;
|
|
# redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution;
|
|
# neither the name of the copyright holders nor the names of its
|
|
# contributors may be used to endorse or promote products derived from
|
|
# this software without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
# Utility functions
|
|
def parse_commit_subject(subject):
|
|
parsed_subject = subject.split(":", maxsplit = 1)
|
|
|
|
# If the subject does not have a colon, it either does not have tags
|
|
# or does not have a message
|
|
if len(parsed_subject) <= 1:
|
|
return None, None
|
|
|
|
tags = [ tag.strip() for tag in parsed_subject[0].split(",") ]
|
|
message = parsed_subject[1]
|
|
|
|
return tags, message
|
|
|
|
# Convert time in seconds to a plausible unit
|
|
def convert_time_in_seconds(delta):
|
|
time = int(delta)
|
|
time_unit = "s"
|
|
|
|
for curr_unit_limit, next_unit in zip([60, 60, 24], ["m", "h", "d"]):
|
|
if time <= curr_unit_limit:
|
|
break
|
|
time = time // curr_unit_limit + 1
|
|
time_unit = next_unit
|
|
|
|
return f"{time}{time_unit}"
|
|
|
|
# End of Utility functions
|
|
|
|
def add_maintainers_to_change(change, maintainers, gerrit_api):
|
|
tags, message = parse_commit_subject(change["subject"])
|
|
change_id = change["id"]
|
|
maintainer_emails = set()
|
|
for tag in tags:
|
|
try:
|
|
for name, email in maintainers[tag].maintainers:
|
|
maintainer_emails.add(email)
|
|
except KeyError:
|
|
print((f"warning: `change-{change_id}` has an unknown tag: "
|
|
f"`{tag}`"))
|
|
for email in maintainer_emails:
|
|
gerrit_api.add_reviewer(change_id, email)
|