From 8ac65c7c7bee4a2a51666519b886eeac1e4d9d0b Mon Sep 17 00:00:00 2001 From: Nathan Cutler Date: Sat, 12 Oct 2019 12:34:09 +0200 Subject: [PATCH] ceph-backport.sh: implement stricter vetting of backport issue Refuse to work on a backport that is * not in "New" or "Need More Info" status * targeting a release that is not among the GitHub active milestones Signed-off-by: Nathan Cutler --- src/script/ceph-backport.sh | 94 ++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/src/script/ceph-backport.sh b/src/script/ceph-backport.sh index 3f38e135b17..0b87c13cecc 100755 --- a/src/script/ceph-backport.sh +++ b/src/script/ceph-backport.sh @@ -77,6 +77,32 @@ function bail_out_github_api { false } +function check_tracker_status { + local -a ok_statuses=("new" "need more info") + local ts="$1" + local tslc="${ts,,}" + local tslc_is_ok= + for oks in "${ok_statuses[@]}"; do + if [ "$tslc" = "$oks" ] ; then + debug "Tracker status $ts is OK for backport to proceed" + tslc_is_ok="yes" + break + fi + done + if [ "$tslc_is_ok" ] ; then + true + else + if [ "$tslc" = "in progress" ] ; then + error "Backport $redmine_url is already in progress" + false + else + error "Backport $redmine_url is closed (status: ${ts})" + false + fi + fi + echo "$tslc_is_ok" +} + function cherry_pick_phase { local offset=0 populate_original_issue @@ -201,6 +227,18 @@ function failed_mandatory_var_check { setup_ok="" } +# takes a string and a substring - returns position of substring within string, +# or -1 if not found +# NOTE: position of first character in string is 0 +function grep_for_substr { + munged="${1%%$2*}" + if [ "$munged" = "$1" ] ; then + echo "-1" + else + echo "${#munged}" + fi +} + # takes PR title, attempts to guess component function guess_component { local comp= @@ -250,6 +288,19 @@ function init_mandatory_vars { fork_remote="${fork_remote:-$(deduce_remote fork)}" } +function is_active_milestone { + local is_active= + local milestone_under_test="$1" + for m in $active_milestones ; do + if [ "$milestone_under_test" = "$m" ] ; then + verbose "Milestone $m is active" + is_active="yes" + break + fi + done + echo "$is_active" +} + function log { local level="$1" shift @@ -418,18 +469,6 @@ EOM fi } -# takes a string and a substring - returns position of substring within string, -# or -1 if not found -# NOTE: position of first character in string is 0 -function grep_for_substr { - munged="${1%%$2*}" - if [ "$munged" = "$1" ] ; then - echo "-1" - else - echo "${#munged}" - fi -} - function troubleshooting_advice { cat <$tracker_title<-" @@ -728,6 +792,12 @@ else false fi +if [ -z "$(is_active_milestone "$milestone")" ] ; then + error "$redmine_url is a backport to $milestone which is not an active milestone" + info "Cowardly refusing to work on a backport to an inactive release" + false +fi + milestone_number=$(try_known_milestones "$milestone") if [ "$milestone_number" -gt "0" ] >/dev/null 2>&1 ; then target_branch="$milestone" -- 2.39.5