Skip to content

Instantly share code, notes, and snippets.

@vvo
Last active November 7, 2017 12:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvo/760470aded3fd4b6db52f14a1b8f7c5c to your computer and use it in GitHub Desktop.
Save vvo/760470aded3fd4b6db52f14a1b8f7c5c to your computer and use it in GitHub Desktop.
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