Skip to content

Instantly share code, notes, and snippets.

@vvo
Last active Nov 7, 2017
Embed
What would you like to do?
spr command line
#!/usr/bin/env bash
function spr() {
remoteOrigin=$(git remote get-url origin)
originGitHubUser=${remoteOrigin#git@github.com:*}
originGitHubUser=${originGitHubUser%%/*}
if [[ $1 == "--"* ]] # spr --branch
then
params=(${@:1})
target=""
else # spr user[/repo] [--branch]
params=(${@:2})
target=$1
fi
if [[ $target == *"/"* ]]
then
user=${target%/*}
repo=${target#*/}
elif [[ -z "$target" ]]
then
user=$originGitHubUser
repo=$(basename $PWD)
else
user=$target
repo=$(basename $PWD)
fi
echo "spr: Submitting a pull request to $user/$repo with params ${params[*]}"
gh pr --submit $user --repo $repo ${params[*]} --user $originGitHubUser --description "$(git log -1 --pretty=%B | tail -n +3)"
}

spr

Send Pull Request, ease the creation and submission of pull request on command line.

Usage

/Users/you/Dev/jest
> spr # sends PR to github.com/$gitOriginUser/jest, so if $origin is facebook/jest then sends PR to facebook/jest
> spr --branch develop # same as previous, but will send PR to the develop branch instead of main branch
> spr algolia # sends PR to github.com/algolia/jest, useful when working on a fork
> spr algolia/jest2 # sends PR github.com/algolia/jest2, useful when creating different directories locally

Requirements

yarn global add gh

Installation

Put the content of the .profile file inside your own .zprofile, .profile or .bash_profile.

Ultimately this could be exposed as an npm package with some rewrite, but right now it already works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment