From b80fd319ee7206aee3919d25bb05dc15a8fd1d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C5=91d=20Ill=C3=A9s?= Date: Mon, 29 Jan 2024 18:28:20 +0100 Subject: [PATCH] Add helper script to abandon open changes To delete stable/ 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 --- doc/source/reference/using.rst | 13 +++++ tools/abandon_patches_on_branch.sh | 82 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100755 tools/abandon_patches_on_branch.sh diff --git a/doc/source/reference/using.rst b/doc/source/reference/using.rst index effc669b41..8e3fdf8dd5 100644 --- a/doc/source/reference/using.rst +++ b/doc/source/reference/using.rst @@ -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. +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/ +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 --------------------------------- diff --git a/tools/abandon_patches_on_branch.sh b/tools/abandon_patches_on_branch.sh new file mode 100755 index 0000000000..79d55ed4c6 --- /dev/null +++ b/tools/abandon_patches_on_branch.sh @@ -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/ branch +# needs to be abandoned in order to be able to delete that branch. + +set -e + +if [[ $# -lt 2 ]]; then + echo "Usage: $(basename $0) [...]" + 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 +