From 3697e0fc00fcb32d371a43217f4d4acb02f3902b Mon Sep 17 00:00:00 2001 From: Nathan Cutler Date: Tue, 19 Nov 2019 13:20:24 +0100 Subject: [PATCH] ceph-backport.sh: allow user to specify --fork explicitly Some users prefer to use a Ceph fork on GitHub other than their personal one. Support this by implementing a "--fork EXPLICIT_FORK" option. Users without a personal fork of ceph/ceph.git would need to provide this option always -- even when setting up the script. Signed-off-by: Nathan Cutler --- src/script/ceph-backport.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/script/ceph-backport.sh b/src/script/ceph-backport.sh index d70b799679a9a..368397ac01ee0 100755 --- a/src/script/ceph-backport.sh +++ b/src/script/ceph-backport.sh @@ -514,6 +514,7 @@ function init_endpoints { function init_fork_remote { [ "$github_user" ] || assert_fail "github_user not set" + [ "$EXPLICIT_FORK" ] && info "Using explicit fork ->$EXPLICIT_FORK<- instead of personal fork." fork_remote="${fork_remote:-$(maybe_deduce_remote fork)}" } @@ -756,7 +757,11 @@ function maybe_deduce_remote { if [ "$remote_type" = "upstream" ] ; then url_component="ceph" elif [ "$remote_type" = "fork" ] ; then - url_component="$github_user" + if [ "$EXPLICIT_FORK" ] ; then + url_component="$EXPLICIT_FORK" + else + url_component="$github_user" + fi else assert_fail "bad remote_type ->$remote_type<- in maybe_deduce_remote" fi @@ -1079,6 +1084,7 @@ Options (not needed in normal operation): --debug (turns on "set -x") --existing-pr BACKPORT_PR_ID (use this when the backport PR is already open) + --fork EXPLICIT_FORK (use EXPLICIT_FORK instead of personal GitHub fork) --milestones (vet all backport PRs for correct milestone setting) --setup/-s (run the interactive setup routine - NOTE: this can be done any number of times) @@ -1236,7 +1242,11 @@ function vet_remotes { verbose "Fork remote is $fork_remote" else error "Cannot auto-determine fork remote" - info "(Could not find GitHub user ${github_user}'s fork of ceph/ceph in \"git remote -v\")" + if [ "$EXPLICIT_FORK" ] ; then + info "(Could not find $EXPLICIT_FORK fork of ceph/ceph in \"git remote -v\")" + else + info "(Could not find GitHub user ${github_user}'s fork of ceph/ceph in \"git remote -v\")" + fi setup_ok="" fi } @@ -1258,6 +1268,7 @@ function vet_setup { [ "$github_token" ] && [ "$setup_ok" ] && set_github_user_from_github_token init_upstream_remote [ "$github_token" ] && [ "$setup_ok" ] && init_fork_remote + vet_remotes [ "$redmine_key" ] && set_redmine_user_from_redmine_key fi if [ "$github_token" ] ; then @@ -1353,7 +1364,7 @@ fi # process command-line arguments # -munged_options=$(getopt -o c:dhsv --long "cherry-pick-only,component:,debug,existing-pr:,force,help,milestones,prepare,setup,setup-report,troubleshooting,update-version,usage,verbose,version" -n "$this_script" -- "$@") +munged_options=$(getopt -o c:dhsv --long "cherry-pick-only,component:,debug,existing-pr:,force,fork:,help,milestones,prepare,setup,setup-report,troubleshooting,update-version,usage,verbose,version" -n "$this_script" -- "$@") eval set -- "$munged_options" ADVICE="" @@ -1363,6 +1374,7 @@ CHERRY_PICK_PHASE="yes" DEBUG="" EXISTING_PR="" EXPLICIT_COMPONENT="" +EXPLICIT_FORK="" FORCE="" HELP="" INTERACTIVE_SETUP_ROUTINE="" @@ -1380,6 +1392,7 @@ while true ; do --debug|-d) DEBUG="$1" ; shift ;; --existing-pr) shift ; EXISTING_PR="$1" ; CHERRY_PICK_PHASE="" ; PR_PHASE="" ; shift ;; --force) FORCE="$1" ; shift ;; + --fork) shift ; EXPLICIT_FORK="$1" ; shift ;; --help|-h) ADVICE="1" ; HELP="$1" ; shift ;; --milestones) CHECK_MILESTONES="$1" ; shift ;; --prepare) CHERRY_PICK_PHASE="yes" ; PR_PHASE="" ; TRACKER_PHASE="" ; shift ;; @@ -1444,6 +1457,13 @@ if [ "$SETUP_OPTION" ] ; then [ "$yes_or_no_answer" ] && yes_or_no_answer="${yes_or_no_answer:0:1}" if [ "$yes_or_no_answer" = "y" ] ; then INTERACTIVE_SETUP_ROUTINE="yes" + else + if [ "$FORCE" ] ; then + warning "--force was given; proceeding with broken setup" + else + info "Bailing out!" + exit 1 + fi fi fi fi @@ -1634,7 +1654,12 @@ if [ "$PR_PHASE" ] ; then fi debug "Opening backport PR" - remote_api_output=$(curl --silent --data-binary "{\"title\":\"${backport_pr_title}\",\"head\":\"${github_user}:${local_branch}\",\"base\":\"${target_branch}\",\"body\":\"${desc}\"}" "https://api.github.com/repos/ceph/ceph/pulls?access_token=${github_token}") + if [ "$EXPLICIT_FORK" ] ; then + source_repo="$EXPLICIT_FORK" + else + source_repo="$github_user" + fi + remote_api_output=$(curl --silent --data-binary "{\"title\":\"${backport_pr_title}\",\"head\":\"${source_repo}:${local_branch}\",\"base\":\"${target_branch}\",\"body\":\"${desc}\"}" "https://api.github.com/repos/ceph/ceph/pulls?access_token=${github_token}") backport_pr_number=$(echo "$remote_api_output" | jq -r .number) if [ -z "$backport_pr_number" ] || [ "$backport_pr_number" = "null" ] ; then error "failed to open backport PR" -- 2.39.5