Files
scylla/scripts/pull_github_pr.sh
Avi Kivity a63a00b0ea scripts/pull_pr: don't pollute local branch namespace
Currently, scripts/pull_pr pollutes the local branch namespace
by creating a branch and never deleting it. This can be avoided
by using FETCH_HEAD, a temporary name automatically assigned by
git to fetches with no destination.
2020-09-23 15:47:51 +03:00

52 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Script for pulling a github pull request
# along with generating a merge commit message.
# Example usage for pull request #6007 and /next branch:
# git fetch
# git checkout origin/next
# ./scripts/pull_github_pr.sh 6007
set -e
if [[ $# != 1 ]]; then
echo Please provide a github pull request number
exit 1
fi
for required in jq curl; do
if ! type $required >& /dev/null; then
echo Please install $required first
exit 1
fi
done
NL=$'\n'
PR_NUM=$1
PR_PREFIX=https://api.github.com/repos/scylladb/scylla/pulls
PR_DATA=$(curl -s $PR_PREFIX/$PR_NUM)
PR_TITLE=$(jq -r .title <<< $PR_DATA)
PR_DESCR=$(jq -r .body <<< $PR_DATA)
PR_LOGIN=$(jq -r .head.user.login <<< $PR_DATA)
PR_REPO=$(jq -r .head.repo.html_url <<< $PR_DATA)
USER_NAME=$(curl -s "https://api.github.com/users/$PR_LOGIN" | jq -r .name)
git fetch origin pull/$PR_NUM/head
nr_commits=$(git log --pretty=oneline HEAD..FETCH_HEAD | wc -l)
closes="${NL}${NL}Closes #${PR_NUM}${NL}"
if [[ $nr_commits == 1 ]]; then
commit=$(git log --pretty=oneline HEAD..FETCH_HEAD | awk '{print $1}')
message="$(git log -1 "$commit" --format="format:%s%n%n%b")"
git cherry-pick $commit
git commit --amend -m "${message}${closes}"
else
git merge --no-ff --log FETCH_HEAD -m "Merge '$PR_TITLE' from $USER_NAME" -m "${PR_DESCR}${closes}"
fi
git commit --amend # for a manual double-check