dotfiles

configuration files
git clone https://pi.duncano.de/git/dotfiles.git

git-merge-pr (1020B)


      1 #!/bin/sh
      2 # git merge-pr [PRNUM][@REMOTE] [GIT-AM FLAGS...] - list or apply GitHub pull request from command-line
      3 set -e
      4 
      5 PR=$1
      6 REMOTE=
      7 case "$PR" in
      8 *@*)
      9 	REMOTE=${PR#*@}
     10 	PR=${PR%%@*}
     11 esac
     12 
     13 URL=$(git ls-remote --get-url $REMOTE)
     14 
     15 PROJECT=${URL%.git}
     16 PROJECT=${PROJECT##*:}
     17 PROJECT=${PROJECT#//github.com/}
     18 
     19 if [ -z "$PR" ]; then
     20 	wget -q -O- --header 'Accept: application/json' \
     21 		"https://api.github.com/repos/${PROJECT}/pulls?direction=asc" |
     22 		jq -r 'if length > 0
     23 			then .[] | "\(.number) <\(.user.login)> \(.title)"
     24 			else "No open pull requests." end'
     25 	exit $?
     26 else
     27 	shift
     28 fi
     29 
     30 PATCH="$(mktemp)"
     31 trap "rm -f $PATCH" INT TERM EXIT
     32 wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch
     33 git am "$@" "$PATCH"
     34 
     35 if [ "$(git config --bool --get merge-pr.autoclose)" = false ]; then
     36 	exit 0
     37 fi
     38 
     39 # Rewrite last commit message to close GitHub issue.
     40 GIT_EDITOR="git -c trailer.closes.ifExists=replace interpret-trailers \
     41 	--trailer 'Closes: #$PR [via git-merge-pr]' --in-place" \
     42 git commit --quiet --amend