Skip to content

Commit

Permalink
Merge pull request ceph#28446 from tspmelo/wip-prepare-backport
Browse files Browse the repository at this point in the history
script/ceph-backport.sh: Add prepare function

Reviewed-by: Abhishek Lekshmanan <[email protected]>
Reviewed-by: Nathan Cutler <[email protected]>
  • Loading branch information
smithfarm authored Jun 13, 2019
2 parents 494d624 + 40768c3 commit 12ab3fc
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions src/script/ceph-backport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@
#
# 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
Expand All @@ -58,6 +60,13 @@
# 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
Expand All @@ -84,10 +93,11 @@ test "$redmine_user_id" || failed_required_variable_check redmine_user_id
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"
Expand Down Expand Up @@ -132,7 +142,42 @@ then
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

Expand Down

0 comments on commit 12ab3fc

Please sign in to comment.