Skip to content

Commit

Permalink
Support curl, auto detect which one to use.
Browse files Browse the repository at this point in the history
Closes: #2 [via git-merge-pr]
  • Loading branch information
ericonr authored and leahneukirchen committed Jun 22, 2020
1 parent 3196859 commit 4759da4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions git-merge-pr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ PROJECT=${URL%.git}
PROJECT=${PROJECT##*:}
PROJECT=${PROJECT#//github.com/}

if command -v wget >/dev/null; then
API_CMD="wget -q -O --header"
PATCH_CMD="wget -nv -O"
elif command -v curl >/dev/null; then
API_CMD="curl -s -H"
PATCH_CMD="curl -Lo"
else
echo "Neither wget or curl could be found in PATH"
exit 1
fi

if [ -z "$PR" ]; then
wget -q -O- --header 'Accept: application/json' \
$API_CMD 'Accept: application/json' \
"https://api.github.com/repos/${PROJECT}/pulls" |
jq -r 'if length > 0
then reverse[] | "\(.number) <\(.user.login)> \(.title)"
Expand All @@ -29,7 +40,7 @@ fi

PATCH="$(mktemp)"
trap "rm -f $PATCH" INT TERM EXIT
wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch
$PATCH_CMD "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch
WHITESPACE="$(git config --get merge-pr.whitespace || true)"
git am "--whitespace=${WHITESPACE:-warn}" "$@" "$PATCH"

Expand Down

0 comments on commit 4759da4

Please sign in to comment.