From 632b30df6d3bfe5dba93813f087b1e1b7532a486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C5=91d=20Ill=C3=A9s?= Date: Mon, 3 May 2021 21:51:51 +0200 Subject: [PATCH] Fix list_eol_stale_branches.sh to list only stale branches clone_repo script does not fail if the branch does not exist, but checks out the master branch [1], so we have to make sure the required branch exists. This patch also adds a check that there were no more patches merged after the given branch was tagged EOL. [1] https://opendev.org/openstack/releases/src/branch/master/tools/clone_repo.sh#L187 Change-Id: Ia1ededfc3cebbae807719750dc5e2d5949ce9a21 --- tools/list_eol_stale_branches.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/list_eol_stale_branches.sh b/tools/list_eol_stale_branches.sh index 2e0390bff1..9bf3a8d589 100755 --- a/tools/list_eol_stale_branches.sh +++ b/tools/list_eol_stale_branches.sh @@ -63,16 +63,34 @@ setup_temp_space 'list-eol-stale-branches' branch=$(series_to_branch "$series") +function no_open_patches { + req="${GERRIT_URL}/changes/?q=status:open+project:${repo}+branch:stable/${em_serie}" + patches=$(curl -s ${req} | sed 1d | jq --raw-output '.[] | .change_id') + [ -z "${patches}" ] + no_opens=$? + if [[ "$no_opens" -eq 1 ]]; then + echo "Patches remained open on stale branch (make sure to abandon them):" + echo "https://review.opendev.org/q/status:open+project:${repo}+branch:stable/${em_serie}" + fi + return $no_opens +} + +function eol_tag_matches_head { + head=$(git log --oneline --decorate -1) + [[ "$head" =~ "${em_serie}-eol" ]] && [[ "$head" =~ "origin/stable/${em_serie}" ]] + matches=$? + if [[ "$matches" -eq 1 ]] ; then + echo "stable/${em_serie} has patches on top of the ${em_serie}-eol tag" + fi + return $matches +} + function is_eol { clone_repo ${repo} stable/${em_serie} + cd ${repo} && git checkout -f -q stable/${em_serie} 2>/dev/null if [[ $? -eq 0 ]]; then echo "${repo} contains eol stale branch (${em_serie})" - req="${GERRIT_URL}/changes/?q=status:open+project:${repo}+branch:stable/${em_serie}" - patches=$(curl -s ${req} | sed 1d | jq --raw-output '.[] | .change_id') - if [ ! -z "${patches}" ]; then - echo "Patches remained open on stale branch (make sure to abandon them):" - echo "https://review.opendev.org/q/status:open+project:${repo}+branch:stable/${em_serie}" - else + if no_open_patches && eol_tag_matches_head; then read -p "> Do you want to delete the branch stable/${em_serie} from ${repo} repository? [y/N]: " YN if [ "${YN,,}" == "y" ]; then if [ -z "$gerrit_username" ]; then @@ -81,6 +99,7 @@ function is_eol { ${TOOLSDIR}/delete_stable_branch.py ${gerrit_username} ${repo} ${em_serie} fi fi + cd .. fi }