-
-
Save zoidyzoidzoid/80e1adc5b11798daecf845b5b0154c46 to your computer and use it in GitHub Desktop.
git alias to push and open PR view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Pushes to origin and opens a github compare view of it to speed up PR | |
# creation. | |
# | |
# To install add to $PATH with executable permission and run | |
# | |
# git config --global alias.pr '!github-push-pr' | |
# | |
remote=origin | |
branch=$(git symbolic-ref --short HEAD) | |
# https://github.com/foo/bar.git -> foo/bar | |
repo=$(git ls-remote --get-url ${remote} \ | |
| sed 's|^.*github.com[:/]\(.*\)$|\1|' \ | |
| sed 's|\(.*\)/$|\1|' \ | |
| sed 's|\(.*\)\(\.git\)|\1|') | |
set -x | |
git push ${remote} ${branch} | |
open "https://github.com/${repo}/compare/${branch}?expand=1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code inspired by the above, but for Gitlab url | |
# like 'hub url' | |
remote=origin | |
branch=$(git symbolic-ref --short HEAD) | |
# https://github.com/foo/bar.git -> foo/bar | |
repo=$(git ls-remote --get-url ${remote} \ | |
| sed -E 's|^(.*)(@\|://)([^:/]+)[:/](.*)$|\4|' \ | |
| sed 's|\(.*\)/$|\1|' \ | |
| sed 's|\(.*\)\(\.git\)|\1|') | |
# https://gitlab.example.com/foo/bar.git -> gitlab.example.com | |
base_url=$(git ls-remote --get-url ${remote} \ | |
| sed -E 's|^(.*)(@\|://)([^:/]+)(.*)$|\3|') | |
target_branch=master | |
case "$repo" in | |
foo/bar) | |
target_branch=develop | |
;; | |
example/repo) | |
target_branch=trunk | |
;; | |
esac | |
set -x | |
open "https://${base_url}/${repo}/merge_requests/new?merge_request%5Bsource_branch%5D=${branch}&merge_request%5Btarget_branch%5D=${target_branch}" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remote=origin | |
sha=$(git rev-parse --short HEAD) | |
# https://github.com/foo/bar.git -> foo/bar | |
repo=$(git ls-remote --get-url ${remote} \ | |
| sed -E 's|^(.*)(@\|://)([^:/]+)[:/](.*)$|\4|' \ | |
| sed 's|\(.*\)/$|\1|' \ | |
| sed 's|\(.*\)\(\.git\)|\1|') | |
# https://gitlab.example.com/foo/bar.git -> gitlab.example.com | |
base_url=$(git ls-remote --get-url ${remote} \ | |
| sed -E 's|^(.*)(@\|://)([^:/]+)(.*)$|\3|') | |
set -x | |
open "https://${base_url}/${repo}/commit/${sha}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment