releases/tools/add_reviewers.sh
Sean McGinnis 27d4f7db98 Update add_reviewers to add to all open reviews
This updates the script to not require a specific topic to make it
easier to automate a job that periodically makes sure all open reviews
have had the PTL and liaison added.

Also refactored the adding of teams because bash array handling can be a
bit wonky sometimes and not always append values. This makes sure no
teams are skipped.

This is slightly less optimized for large reviews like the final series
release since it loops through teams based on the deliverable files. As
a slight optimization, it will skip a team if it was the same team as
the last deliverable file. It just might be possible that the same team
will be processed multiple times if their deliverable files are not in
alphabetical order, but there is no harm in that other than taking
slightly longer to complete.

Change-Id: I9a9194ea276aa0120aef21a321f48a93419fb848
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-05-09 07:15:06 -05:00

101 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
#
# Script to add PTL and release liaison(s) as reviewers for any release
# patches under a given topic.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
function usage {
echo "Usage: $0 $gerrit_topic"
echo
echo "# Add reviewers to all open reviews"
echo "Example: $0"
echo "# Add reviewers for a specific topic"
echo "Example: $0 ussuri-c-w-i # Adds reviewers for a specific topic"
}
# Validate topic was provided
if [ $# -gt 1 ]; then
usage
exit 2
fi
topic=""
if [ $# -eq 1 ]; then
topic="+topic:$1"
fi
# We make assumptions that local commands will be available
if [[ -z "$VIRTUAL_ENV" ]]; then
if [[ ! -d .tox/venv ]]; then
tox -e venv --notest
fi
source ./.tox/venv/bin/activate
fi
# Make sure we have a gerrit user for authenticated commands
GERRIT_ID=${GERRIT_USER}
if [[ -z "$GERRIT_ID" ]]; then
GERRIT_ID=$(git config --list | grep gitreview.username | cut -d '=' -f 2)
fi
if [[ -z "$GERRIT_ID" ]]; then
echo "Need GERRIT_USER environment variable set or be in a repo with"
echo "gitreview.username set in your git config."
exit 2
fi
GERRIT="review.opendev.org"
GERRIT_URL="https://$GERRIT"
GERRIT_PROJECT="openstack/releases"
# Get all open reviews for the given topic
reviews=$(curl -s \
"$GERRIT_URL/changes/?q=status:open+project:$GERRIT_PROJECT${topic}" | \
sed 1d | \
jq --raw-output '.[] | .change_id')
# Loop through each review and find deliverable files
for review in $reviews; do
last_team=""
deliverable_files=$(curl -s \
"$GERRIT_URL/changes/?q=$review&o=CURRENT_REVISION&o=CURRENT_FILES" | \
sed 1d | \
jq -r '.[] | .revisions | map(.files) | .[] | keys | .[]' | \
grep deliverables)
# Extract the owning teams for each deliverable in this patch
for file in $deliverable_files; do
team=$(grep team $file | sed 's/team: //g')
if [[ "$team" == "$last_team" ]]; then
continue
fi
last_team="$team"
echo "Adding $team reviewers for $review"
declare -a emails=$(
get-contacts --all "$team" | awk -F': ' '/Email/ {print $2}')
for email in $emails; do
# Skip over some common dummy entries
if [[ "$email" == "None" ]] || [[ "$email" =~ "example" ]]; then
continue
fi
echo " Adding Email: $email"
ssh -p 29418 "$GERRIT_ID@review.opendev.org" gerrit set-reviewers \
-a "$email" "$review" || true
done
done
done