|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright The Stash Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -eou pipefail |
| 18 | + |
| 19 | +should_cherry_pick() { |
| 20 | + while IFS=$': \t' read -r -u9 marker v; do |
| 21 | + if [ "$marker" = "/cherry-pick" ]; then |
| 22 | + return 0 |
| 23 | + fi |
| 24 | + done 9< <(git show -s --format=%b) |
| 25 | + return 1 |
| 26 | +} |
| 27 | + |
| 28 | +should_cherry_pick || { |
| 29 | + echo "Skipped cherry picking." |
| 30 | + echo "To automatically cherry pick, add /cherry-pick to commit message body." |
| 31 | + exit 0 |
| 32 | +} |
| 33 | + |
| 34 | +git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git |
| 35 | + |
| 36 | +while IFS=/ read -r -u9 repo branch; do |
| 37 | + git checkout $branch |
| 38 | + pr_branch="master-${GITHUB_SHA:0:8}"${branch#"release"} |
| 39 | + git checkout -b $pr_branch |
| 40 | + git cherry-pick --strategy=recursive -X theirs $GITHUB_SHA |
| 41 | + git push -u origin HEAD -f |
| 42 | + hub pull-request \ |
| 43 | + --base $branch \ |
| 44 | + --labels automerge \ |
| 45 | + --message "[cherry-pick] $(git show -s --format=%s)" \ |
| 46 | + --message "$(git show -s --format=%b)" || true |
| 47 | + sleep 2 |
| 48 | +done 9< <(git branch -r | grep release) |
0 commit comments