Skip to content

Instantly share code, notes, and snippets.

@ejona86
Last active June 17, 2022 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ejona86/52b0d10c6c23b4c8898f341574cdae2f to your computer and use it in GitHub Desktop.
Save ejona86/52b0d10c6c23b4c8898f341574cdae2f to your computer and use it in GitHub Desktop.
Custom backport script for grpc-java
#!/bin/bash
# Copyright 2020 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
if [[ $# < 2 ]]; then
echo "Usage: $0 PR MINOR_VERSIONS"
exit 1
fi
readonly pr="$1"
readonly minors="$2"
readonly repo="$(git remote get-url origin | sed -E 's#.*[:/]([a-zA-Z0-9-]+)/grpc-java.*#\1#')"
readonly pr_metadata="$(curl -sSf -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/grpc/grpc-java/pulls/$pr")"
readonly assignee="$(echo "$pr_metadata" | jq -r '.assignee.login')"
readonly commits="$(echo "$pr_metadata" | jq -r '.merge_commit_sha')"
readonly branch_id="$(echo "$pr_metadata" | jq -r '.head.ref')"
readonly title="$(echo "$pr_metadata" | jq -r '.title')"
readonly body="$(echo "$pr_metadata" | jq -r '.body')"
cat <<EOT
PR: https://github.com/grpc/grpc-java/pull/$pr
Versions: $minors
Assignee: $assignee
Commits: $commits
Branch id: $branch_id
Repo: $repo
EOT
read -p "Continue? "
urlencode() {
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$*"
}
git fetch upstream
readonly orig_branch="$(git rev-parse --abbrev-ref HEAD)"
#readonly title="$(git log -1 --pretty=format:%s "$commit")"
#readonly body="$(git log -1 --pretty=format:%b "$commit")"
for minor in $minors; do
git checkout -b "backport-${branch_id}-1.$minor" "upstream/v1.$minor.x"
git cherry-pick $commits
git push --set-upstream origin "backport-${branch_id}-1.$minor"
echo
echo
echo ------------------------------------------------------
echo "https://github.com/grpc/grpc-java/compare/v1.$minor.x...$repo:backport-${branch_id}-1.$minor?expand=1&assignees=$assignee&title=$(urlencode "$title")%20%281.$minor.x%20backport%29&body=$(urlencode "$body")%0A%0ABackport%20of%20%23$pr"
echo ------------------------------------------------------
echo
echo
done
git checkout "$orig_branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment