#
# Once you have the actual values for the above variables, create a file
# $HOME/bin/backport_common.sh with the following contents
-#
+#
# redmine_key=[your_redmine_key]
# redmine_user_id=[your_redmine_user_id]
# github_token=[your_github_personal_access_token]
# github_user=[your_github_username]
#
-# You can also optionally add the remote repo's name in this file, like
+# You can also optionally add yours and ceph remote repo's name in this file,
+# like
#
# github_repo=[your_github_repo_name]
+# ceph_repo=[ceph_github_repo_name]
#
-# If you don't add it, it will default to "origin".
+# If you don't add it, it will default to "origin" and "upstream", respectively.
#
# Obviously, since this file contains secrets, you should protect it from
# exposure using all available means (restricted file privileges, encrypted
# http://tracker.ceph.com/issues/19206 (a jewel backport)
# becomes something like this:
#
+# For simple backports you can just run:
+#
+# ceph-backport.sh 19206 jewel --prepare
+# ceph-backport.sh 19206 jewel
+#
+# alternatively, you can prepare the backport manually:
+#
# git remote add ceph http://github.com/ceph/ceph.git
# git fetch ceph
# git checkout -b wip-19206-jewel ceph/jewel
test "$github_token" || failed_required_variable_check github_token
test "$github_user" || failed_required_variable_check github_user
: "${github_repo:=origin}"
+: "${ceph_repo:=upstream}"
function usage () {
echo "Usage:"
- echo " $0 [BACKPORT_TRACKER_ISSUE_NUMBER] [MILESTONE]"
+ echo " $0 [BACKPORT_TRACKER_ISSUE_NUMBER] [MILESTONE] [--prepare]"
echo
echo "Example:"
echo " $0 19206 jewel"
fi
title=$(curl --silent 'http://tracker.ceph.com/issues/'$issue.json?key=$redmine_key | jq .issue.subject | tr -d '\\"')
-echo "Issue title: $title"
+echo "Issue title: $title"
+
+function prepare () {
+ related_issue=$(curl --silent http://tracker.ceph.com/issues/$issue.json?include=relations |
+ jq '.issue.relations[] | select(.relation_type | contains("copied_to")) | .issue_id')
+ [ -z "$related_issue" ] && echo "Could not find original issue." && return 1
+ echo "Original issue: $related_issue"
+
+ pr=$(curl --silent http://tracker.ceph.com/issues/$related_issue.json |
+ jq '.issue.custom_fields[] | select(.id | contains(21)) | .value' |
+ tr -d '\\"')
+ [ -z "$pr" ] && echo "Could not find PR." && return 1
+ echo "Original PR: $pr"
+
+ number=$(curl --silent 'https://api.github.com/repos/ceph/ceph/pulls/'$pr | jq .commits)
+ [ -z "$number" ] && echo "Could not determine the number of commits." && return 1
+ echo "Found $number commit(s)"
+
+ git fetch $ceph_repo
+ echo "fetch latest $milestone branch."
+
+ git checkout $ceph_repo/$milestone -b wip-$issue-$milestone
+
+ git fetch $ceph_repo pull/$pr/head:pr-$pr
+
+ git cherry-pick -x pr-$pr~$number..pr-$pr
+ echo "cherry picked pr-$pr into wip-$issue-$milestone"
+
+ exit 0
+}
+
+if [[ $* == *--prepare* ]]
+then
+ echo "'--prepare' found, will only prepare the backport"
+ prepare
+fi
git push -u $github_repo wip-$issue-$milestone