git-pull-request
Advanced tools
Comparing version 0.3.1 to 0.3.2
76
gpr.js
@@ -11,4 +11,4 @@ #!/usr/local/bin/node | ||
var version = 'git-pull-request 0.3.1'; | ||
var usage = '\n gpr [-i | -l | -p | -b [name] | -d | -D | -h | -v ] <pr#>'; | ||
var version = 'git-pull-request 0.3.2'; | ||
var usage = '\n ' + version + '\n\n gpr [-i | -l [-r] | -p | -f | -b [<name>] | -n | -d | -D | -v | -h] <pr#>'; | ||
var help = usage + '\n\n' + | ||
@@ -18,10 +18,15 @@ ' By default, gpr will fetch the remote branch for <pr#> and checkout on a detached HEAD.\n\n' + | ||
' [-i | info] <pr#> Show the PR title and requestor for <pr#>.\n' + | ||
' [-l | ls | list] [-r | remote] List local gpr branches. / List 30 most recent open PRs.\n\n' + | ||
' [-p | pull] <pr#> Pull the remote branch for <pr#> to the current branch.\n' + | ||
' [-b | branch] [name] <pr#> Create new branch [name] from master and pull. Defaults to \'gpr/<pr#>\'.\n' + | ||
' [-f | force] <pr#> Force overwrite the local branch and checkout on a detached HEAD.\n' + | ||
' [-b | branch] [<name>] <pr#> Create new branch [name] from master and pull. Defaults to \'gpr/<pr#>\'.\n' + | ||
' [-n] [user:branch] Fetch from the named ref and checkout on a detached HEAD.\n\n' + | ||
' [-d | delete] <pr#> Delete the gpr/<pr#> branch.\n' + | ||
' [-D | Delete] <pr#> Force delete the gpr/<pr#> branch.\n' + | ||
' [-l | ls | list] [-r | remote] List local gpr branches. / List 30 most recent open PRs.\n' + | ||
' [-n] [user:branch] Fetch from the named ref and checkout on a detached HEAD.\n\n' + | ||
' [-D | Delete] <pr#> Force delete the gpr/<pr#> branch.\n\n' + | ||
' [-v | version] Show git-pull-request version.\n' + | ||
' [-h | help] This help.\n\n' + | ||
' <pr#> PR number to apply the command to.'; | ||
@@ -46,2 +51,18 @@ | ||
// Exit with a message | ||
function exit(error) { | ||
console.log(error,'\n') | ||
process.exit(); | ||
}; | ||
// Exec with echo | ||
function execho(command) { | ||
console.log(command); | ||
try { | ||
console.log(execSync(command, {encoding: 'utf8'})); | ||
} catch (error) { | ||
console.error(error.output[1]); | ||
} | ||
}; | ||
// Process args that don't require the API, or setup those that do | ||
@@ -97,18 +118,2 @@ switch(args[2]) { | ||
// Exit with a message | ||
function exit(error) { | ||
console.log(error,'\n') | ||
process.exit(); | ||
}; | ||
// Exec with echo | ||
function execho(command) { | ||
console.log(command); | ||
try { | ||
console.log(execSync(command, {encoding: 'utf8'})); | ||
} catch (error) { | ||
console.error(error.output[1]); | ||
} | ||
}; | ||
// Read from the API | ||
@@ -147,14 +152,17 @@ https.get(options, function(result) { | ||
// Color [bracketed] string | ||
function colorBracketed(string) { | ||
string = string.replace('[', cyan + '['); | ||
string = string.replace(']', ']' + reset); | ||
return string; | ||
} | ||
function displayPr(pr) { | ||
// Color [bracketed] string | ||
pr.title = pr.title.replace('[', cyan + '['); | ||
pr.title = pr.title.replace(']', ']' + reset); | ||
console.log(red + pr.number + reset, pr.title, green + '(@' + pr.user.login + ')' + reset); | ||
}; | ||
// Process args | ||
switch(args[2]) { | ||
case 'info': case '-i': | ||
response.title = colorBracketed(response.title); | ||
console.log('\n' + response.title, green + '(@' + response.user.login + ')\n' + reset ); | ||
console.log(); | ||
displayPr(response); | ||
console.log(); | ||
break; | ||
@@ -165,4 +173,3 @@ | ||
response.forEach( function(pr) { | ||
pr.title = colorBracketed(pr.title); | ||
console.log(red + pr.number + reset, pr.title, green + '(@' + pr.user.login + ')' + reset); | ||
displayPr(pr); | ||
}); | ||
@@ -196,2 +203,7 @@ console.log(); | ||
case 'force': case '-f': | ||
execho('git fetch -f ' + remote); | ||
execho('git checkout FETCH_HEAD'); | ||
break; | ||
default: | ||
@@ -198,0 +210,0 @@ execho('git fetch ' + remote); |
{ | ||
"name": "git-pull-request", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "A cli utility to pull a remote branch based on a github PR number", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,8 +7,19 @@ ## git-pull-request [![npm version](https://badge.fury.io/js/git-pull-request.svg)](https://badge.fury.io/js/git-pull-request) | ||
npm install -g git-pull-request | ||
`npm install -g git-pull-request` | ||
You must have [Node.js](https://nodejs.org) installed in `/usr/local/bin/node` to use `gpr`. | ||
If it's anywhere else, please create an alias. (You don't need to be using node or npm for your project.) | ||
`gpr` reads your repository information from the `package.json` file for your project in the current directory, | ||
or an ancestor directory. If you don't have one, you can create one in the root of your project using this template: | ||
``` | ||
{"repository": {"url": "git+https://github.com/your/repository.git"}} | ||
``` | ||
Paste into package.json and edit the github URL. This isn't a fully formed package.json, but is sufficient for `gpr`. | ||
### Usage | ||
``` | ||
gpr [-i | -l | -p | -b [name] | -d | -D | -h | -v ] <pr#> | ||
gpr [-i | -l [-r] | -p | -f | -b [<name>] | -n | -d | -D | -v | -h] <pr#> | ||
@@ -18,8 +29,11 @@ By default, gpr will fetch the remote branch for <pr#> and checkout on a detached HEAD. | ||
[-i | info] <pr#> Show the PR title and requestor for <pr#>. | ||
[-l | ls | list] [-r | remote] List local gpr branches. / List 30 most recent open PRs. | ||
[-p | pull] <pr#> Pull the remote branch for <pr#> to the current branch. | ||
[-b | branch] [name] <pr#> Create new branch [name] from master and pull. Defaults to 'gpr/<pr#>'. | ||
[-f | force] <pr#> Force overwrite the local branch and checkout on a detached HEAD. | ||
[-b | branch] [<name>] <pr#> Create new branch [name] from master and pull. Defaults to 'gpr/<pr#>'. | ||
[-n] [user:branch] Fetch from the named ref and checkout on a detached HEAD. | ||
[-d | delete] <pr#> Delete the gpr/<pr#> branch. | ||
[-D | Delete] <pr#> Force delete the gpr/<pr#> branch. | ||
[-l | ls | list] [-r | remote] List local gpr branches. / List 30 most recent open PRs. | ||
[-n] [user:branch] Fetch from the named ref and checkout on a detached HEAD. | ||
@@ -26,0 +40,0 @@ [-v | version] Show git-pull-request version. |
9814
169
43