Add script which helps abandon old patches in gerrit

This script is almost the same as script in neutron repo [1]
but without closing Launchpad bugs as Tobiko don't use Launchpad
as a bug tracker.


Change-Id: I790c6692b05382353e630d23e3b45245a09b678f
Slawek Kaplonski 2023-02-16 08:56:53 +01:00
parent 6a2d965021
commit 9733a4fe10
1 changed files with 112 additions and 0 deletions

tools/ Executable file
View File

@ -0,0 +1,112 @@
#!/usr/bin/env bash
# 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
# 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.
# Please do not run this script without talking to the Tobiko Core team. Auto
# abandoning people's changes is a good thing, but must be done with care.
# before you run this modify your .ssh/config to create a
# entry:
# Host
# User <yourgerritusername>
# Port 29418
# Note: due to gerrit bug somewhere, this double posts messages. :(
# first purge all the reviews that are more than 4w old and blocked by a core -2
PROJECTS="(x/tobiko OR x/devstack-plugin-tobiko)"
function print_help {
echo "Script to abandon patches without activity for more than 4 weeks."
echo "Usage:"
echo " ./ [--dry-run] [--help]"
echo " --dry-run In dry-run mode it will only print what patches would be abandoned "
echo " but will not take any real actions in gerrit"
echo " --help Print help message"
while [ $# -gt 0 ]; do
case $key in
echo "Enabling dry run mode"
shift # past argument
exit 2
set -o errexit
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function abandon_review {
local gitid=$1
local msg=$@
# echo ssh gerrit review $gitid --abandon --message \"$msg\"
if [ $DRY_RUN -eq 1 ]; then
echo "Would abandon $gitid"
echo "Abandoning $gitid"
ssh gerrit review $gitid --abandon --message \"$msg\"
blocked_reviews=$(ssh "gerrit query --current-patch-set --format json $PROJECTS status:open age:4w label:Code-Review<=-2" | jq .currentPatchSet.revision | grep -v null | sed 's/"//g')
blocked_msg=$(cat <<EOF
This review is > 4 weeks without comment and currently blocked by a
core reviewer with a -2. We are abandoning this for now.
Feel free to reactivate the review by pressing the restore button and
contacting the reviewer with the -2 on this review to ensure you
address their concerns.
for review in $blocked_reviews; do
# echo ssh gerrit review $review --abandon --message \"$msg\"
echo "Blocked review $review"
abandon_review $review $blocked_msg
# then purge all the reviews that are > 4w with no changes and Jenkins has -1ed
failing_reviews=$(ssh "gerrit query --current-patch-set --format json $PROJECTS status:open age:4w NOT label:Verified>=1,Zuul" | jq .currentPatchSet.revision | grep -v null | sed 's/"//g')
failing_msg=$(cat <<EOF
This review is > 4 weeks without comment, and failed Jenkins the last
time it was checked. We are abandoning this for now.
Feel free to reactivate the review by pressing the restore button and
leaving a 'recheck' comment to get fresh test results.
for review in $failing_reviews; do
echo "Failing review $review"
abandon_review $review $failing_msg