dotfiles/bin/gpr

35 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2022-09-08 16:17:06 +00:00
#!/bin/sh
2022-11-04 06:29:58 +00:00
set -e
2022-09-08 16:17:06 +00:00
# github pr helper
2023-08-17 03:37:32 +00:00
# push current branch to ORIGIN(remote) and create a PR toward UPSTREAM(remote)
# UPSTREAM must be a https github url
2022-12-12 13:43:03 +00:00
if [ -n "$PROXY_HOST" ] && [ -n "$PROXY_PORT" ]; then
2023-04-21 17:06:57 +00:00
export HTTP_PROXY=http://$PROXY_HOST:$PROXY_PORT
echo HTTP_PROXY=$HTTP_PROXY
echo HTTPS_PROXY=$HTTP_PROXY
2022-12-12 13:43:03 +00:00
fi
2022-09-08 16:17:06 +00:00
BRANCH=$(git branch --show-current)
2023-12-13 12:40:39 +00:00
# UPSTREAM_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} | awk -F/ '{print $2}')
2023-04-21 17:06:57 +00:00
UPSTREAM_BRANCH=$(HTTPS_PROXY=$HTTP_PROXY git remote show upstream | grep -oP 'HEAD branch: \K\w+')
2023-08-17 03:37:32 +00:00
ORIGIN_NAME=${1:-origin}
ORIGIN_URL=$(git remote get-url $ORIGIN_NAME)
2022-09-08 16:17:06 +00:00
case "$ORIGIN_URL" in
git@github.com:*)
ORIGIN_ORG=$(printf "$ORIGIN_URL" | sed -E 's#^.+:([^/]+).+$#\1#')
# ORIGIN=$(printf "$ORIGIN_URL" | grep -oP 'git@github.com:\K.+(?=\.git$)')
;;
esac
UPSTREAM_URL=$(git remote get-url upstream)
UPSTREAM_URL=$(echo "$UPSTREAM_URL" | sed 's/.git$//')
echo ORIGIN_ORG: $ORIGIN_ORG
echo UPSTREAM_URL: $UPSTREAM_URL
2023-08-17 03:37:32 +00:00
git push -f -u $ORIGIN_NAME $BRANCH
x-open "$UPSTREAM_URL/compare/$UPSTREAM_BRANCH...$ORIGIN_ORG:$BRANCH?expand=1"
2022-09-08 16:17:06 +00:00
sleep 2
command -v awesome-client && awesome-client '
local awful = require("awful")
awful.client.urgent.jumpto()
'