Add helper script to abandon open changes

To delete stable/<series> branches first we have to abandon all open
changes otherwise gerrit does not allow to delete the branch.
This script abandons all the open patches on a given project on a
specific branch.

Change-Id: I431fb305f998608889510f8ed2914583891d2167
This commit is contained in:
Előd Illés 2024-01-29 18:28:20 +01:00 committed by Elod Illes
parent 9b6423d532
commit b80fd319ee
2 changed files with 95 additions and 0 deletions

View File

@ -867,6 +867,19 @@ This script list these stable/branches and offers to delete them.
Only release managers have the access rights to delete branches. Only release managers have the access rights to delete branches.
tools/abandon_patches_on_branch.sh
----------------------------------
A script to help abandoning open patches when a given branch transitions
to ``Unmaintained`` or ``End of Life`` and all patches on stable/<series>
branch needs to be abandoned in order to be able to delete that branch.
Example:
::
tools/abandon_patches_on_branch.sh yoga $(list-deliverables --series yoga)
tools/list_unbranched_projects.sh tools/list_unbranched_projects.sh
--------------------------------- ---------------------------------

View File

@ -0,0 +1,82 @@
#!/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
#
# 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.
# This script helps to abandon open patches when a given branch transitions
# to Unmaintained or End of Life and all patches on stable/<series> branch
# needs to be abandoned in order to be able to delete that branch.
set -e
if [[ $# -lt 2 ]]; then
echo "Usage: $(basename $0) <branch> <repo> [<repo>...]"
echo "repo should be e.g. glance"
echo
echo "Example: $(basename $0) yoga \$(list-deliverables --series yoga --is-eom)"
echo " or: $(basename $0) ussuri \$(list-deliverables --series ussuri --is-eol)"
echo " or: $(basename $0) 2023.1 \$(list-deliverables --series antelope)"
echo
echo " !!! WARNING: please do not run this script without discussing it"
echo " first with release managers!"
exit 1
fi
series="$1"
shift
repos="$@"
function abandon_change {
gitid=$1
msg=$2
commit_message=$(ssh review.opendev.org "gerrit query $gitid --current-patch-set --format json" | head -n1 | jq .subject)
echo "Abandoning: $change -- $commit_message"
ssh review.opendev.org gerrit review $gitid --abandon --message \"$msg\"
}
if [[ -z "$TARGET" ]]; then
echo
read -p "> Is stable/$series transitioning to Unmaintained or End of Life? [u/e]: " TARGET
fi
if [ "${TARGET,,}" != "u" ] && [ "${TARGET,,}" != "e" ]; then
echo "Please choose either u or e."
exit 1
fi
for repo in $repos; do
echo "Processing repository: $repo..."
open_changes=$(
ssh review.opendev.org "gerrit query --current-patch-set --format json \
status:open branch:stable/${series} project:openstack/${repo}" | \
jq .currentPatchSet.revision | grep -v null | sed 's/"//g'
)
if [ "${TARGET,,}" == "u" ]; then
abandon_message="stable/$series branch of openstack/$repo is about to be deleted.
To be able to do that, all open patches need to be abandoned.
Please cherry pick the patch to unmaintained/$series if you want to
further work on this patch."
else
abandon_message="
stable/$series branch of openstack/$repo transitioned to End of Life
and is about to be deleted.
To be able to do that, all open patches need to be abandoned."
fi
for change in $open_changes; do
abandon_change $change "$abandon_message"
done
done