From ea97a5a02baea105a650659bbf9905e0382ea822 Mon Sep 17 00:00:00 2001 From: Nathan Cutler Date: Sun, 6 Oct 2019 21:32:42 +0200 Subject: [PATCH] ceph-backport.sh: guess component label If component label is not provided explicitly on the command line, attempt to guess it. Signed-off-by: Nathan Cutler --- src/script/ceph-backport.sh | 99 +++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 9 deletions(-) diff --git a/src/script/ceph-backport.sh b/src/script/ceph-backport.sh index b8eb623d359..b699181df02 100755 --- a/src/script/ceph-backport.sh +++ b/src/script/ceph-backport.sh @@ -24,6 +24,46 @@ if [[ $* == *--debug* ]]; then set -x fi +# associative array keyed on "component" strings from PR titles, mapping them to +# GitHub PR labels that make sense in backports +declare -A comp_hash=( +["bluestore"]="bluestore" +["build/ops"]="build/ops" +["ceph.spec"]="build/ops" +["ceph-volume"]="ceph-volume" +["cephfs"]="cephfs" +["cmake"]="build/ops" +["config"]="config" +["client"]="cephfs" +["common"]="common" +["core"]="core" +["dashboard"]="dashboard" +["deb"]="build/ops" +["doc"]="documentation" +["grafana"]="monitoring" +["mds"]="cephfs" +["messenger"]="core" +["mon"]="core" +["msg"]="core" +["mgr/dashboard"]="dashboard" +["mgr/prometheus"]="monitoring" +["mgr"]="core" +["monitoring"]="monitoring" +["orch"]="orchestrator" +["osd"]="core" +["perf"]="performance" +["prometheus"]="monitoring" +["pybind"]="pybind" +["py3"]="python3" +["python3"]="python3" +["qa"]="tests" +["rbd"]="rbd" +["rgw"]="rgw" +["rpm"]="build/ops" +["tests"]="tests" +["tool"]="tools" +) + function bail_out_github_api { local api_said="$1" info "GitHub API said:" @@ -146,6 +186,25 @@ function failed_mandatory_var_check { setup_ok="" } +# takes PR title, attempts to guess component +function guess_component { + local comp= + local pos="0" + local pr_title="$1" + local winning_comp= + local winning_comp_pos="9999" + for comp in "${!comp_hash[@]}" ; do + pos=$(grep_for_substr "$pr_title" "$comp") + # echo "$comp: $pos" + [ "$pos" = "-1" ] && continue + if [ "$pos" -lt "$winning_comp_pos" ] ; then + winning_comp_pos="$pos" + winning_comp="$comp" + fi + done + [ "$winning_comp" ] && echo "${comp_hash["$winning_comp"]}" || echo "" +} + function info { log info "$@" } @@ -344,6 +403,18 @@ 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 <