Merge "Add script for adding PTL and liaisons to reviews"

This commit is contained in:
Zuul 2020-04-24 08:44:55 +00:00 committed by Gerrit Code Review
commit 050447401e
2 changed files with 115 additions and 0 deletions

View File

@ -621,6 +621,26 @@ To set the pre-release group membership:
tox -e aclmanager -- groups pre_release ttx
tools/add_reviewers.sh
----------------------
A script to add the PTL and release liaisons to one or more reviews.
Around deadlines during the cycle, and especially near the end of the cycle,
the release team needs to generate a large number of release patches for
various subsets of the included deliverables. The ``add_reviewers.sh`` script
can be used to make sure the appropriate people have been added as reveiwers
for these reviews.
For example, assuming the release candidate patches for the Ussuri cycle are
generated using the Gerrit review topic of ``ussuri-rc``, the following will
process all of those reviews to add the necessary PTL and liaison reviewers::
./tools/add_reviewers.sh ussuri-rc
Note that any topic may be used, so this script can be used even if just
adding reviewers to an individual review.
tools/check_approval.py
-----------------------

95
tools/add_reviewers.sh Executable file
View File

@ -0,0 +1,95 @@
#!/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 "Example: $0 ussuri-c-w-i"
}
# Validate topic was provided
if [ $# -lt 1 ]; then
usage
exit 2
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:$1" | \
sed 1d | \
jq --raw-output '.[] | .change_id')
# Loop through each review and find deliverable files
for review in $reviews; do
teams=()
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 [[ ! "${teams[@]}" =~ "$team" ]]; then
teams+=($team)
fi
done
# Look up the contacts for each team and add them as reviewers
for team in $teams; do
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