Skip to content

Instantly share code, notes, and snippets.

@mping
Last active September 26, 2016 15:14
Show Gist options
  • Select an option

  • Save mping/29e779669071baa88c4c to your computer and use it in GitHub Desktop.

Select an option

Save mping/29e779669071baa88c4c to your computer and use it in GitHub Desktop.
"Make" a PR on the current branch for another branch (github only)
#
# https://gist.github.com/mping/29e779669071baa88c4c
# make a url like this, for PRs:
# https://github.com/Company/repo/compare/master...BRANCH?expand=1
# https://repo.gitlab.com/Company/repomerge_requests/new?utf8=%E2%9C%93&merge_request%5Bsource_project_id%5D=25&merge_request%5Bsource_branch%5D=BRANCh&merge_request%5Btarget_project_id%5D=25&merge_request%5Btarget_branch%5D=master
#
# > makepr master
# will generate the url for a PR from the current branch to master
function makepr {
origin=`git config --get remote.origin.url | sed -e s/git@//g | sed -e s/.git// | sed -e 's/:/\//'`
branch=`git rev-parse --abbrev-ref HEAD`
against=$1
commits=`git log $(git merge-base $against $branch)..HEAD --oneline | wc -l | tr -d ' '`
echo "make a pr from '$branch' against '$against', with $commits commits"
if [ "$commits" -gt 1 ]
then
echo -e "\e[31m***********************************************"
echo -e "\e[31m*** Too many commits ($commits), you should squash ***"
echo -e "\e[31m***********************************************"
fi
echo -e "\e[93mGithub: \e[39mhttps://$origin/compare/$against...$branch?expand=1"
echo -e "\e[93mGitlab: \e[39mhttps://$origin/merge_requests/new?utf8=%E2%9C%93&merge_request%5Bsource_project_id%5D=25&merge_request%5Bsource_branch%5D=$branch&merge_request%5Btarget_project_id%5D=25&merge_request%5Btarget_branch%5D=$against"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment