зеркало из https://github.com/mislav/hub.git
add format option to `git pr show`
This commit is contained in:
Родитель
51a256596e
Коммит
dcf47d6cae
|
@ -17,7 +17,7 @@ var (
|
|||
Usage: `
|
||||
pr list [-s <STATE>] [-h <HEAD>] [-b <BASE>] [-o <SORT_KEY> [-^]] [-f <FORMAT>] [-L <LIMIT>]
|
||||
pr checkout <PR-NUMBER> [<BRANCH>]
|
||||
pr show [-uc] [-h <HEAD>]
|
||||
pr show [-uc] [-h <HEAD>] [-f <FORMAT>]
|
||||
pr show [-uc] <PR-NUMBER>
|
||||
`,
|
||||
Long: `Manage GitHub Pull Requests for the current repository.
|
||||
|
@ -160,13 +160,9 @@ hub-issue(1), hub-pull-request(1), hub(1)
|
|||
}
|
||||
|
||||
cmdShowPr = &Command{
|
||||
Key: "show",
|
||||
Run: showPr,
|
||||
KnownFlags: `
|
||||
-h, --head HEAD
|
||||
-u, --url
|
||||
-c, --copy
|
||||
`,
|
||||
Key: "show",
|
||||
Run: showPr,
|
||||
Long: cmdPr.Long,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -283,8 +279,9 @@ func showPr(command *Command, args *Args) {
|
|||
|
||||
words := args.Words()
|
||||
openUrl := ""
|
||||
prNumber := 0
|
||||
if len(words) > 0 {
|
||||
if prNumber, err := strconv.Atoi(words[0]); err == nil {
|
||||
if prNumber, err = strconv.Atoi(words[0]); err == nil {
|
||||
openUrl = baseProject.WebURL("", "", fmt.Sprintf("pull/%d", prNumber))
|
||||
} else {
|
||||
utils.Check(fmt.Errorf("invalid pull request number: '%s'", words[0]))
|
||||
|
@ -293,12 +290,26 @@ func showPr(command *Command, args *Args) {
|
|||
pr, err := findCurrentPullRequest(localRepo, baseProject, args.Flag.Value("--head"))
|
||||
utils.Check(err)
|
||||
openUrl = pr.HtmlUrl
|
||||
prNumber = pr.Number
|
||||
}
|
||||
|
||||
args.NoForward()
|
||||
printUrl := args.Flag.Bool("--url")
|
||||
copyUrl := args.Flag.Bool("--copy")
|
||||
printBrowseOrCopy(args, openUrl, !printUrl && !copyUrl, copyUrl)
|
||||
if format := args.Flag.Value("--format"); format != "" {
|
||||
host, err := github.CurrentConfig().PromptForHost(baseProject.Host)
|
||||
utils.Check(err)
|
||||
client := github.NewClientWithHost(host)
|
||||
pr, err := client.PullRequest(baseProject, strconv.Itoa(prNumber))
|
||||
utils.Check(err)
|
||||
|
||||
// ui.Println(pr.Number)
|
||||
colorize := colorizeOutput(args.Flag.HasReceived("--color"), args.Flag.Value("--color"))
|
||||
ui.Println(formatPullRequest(*pr, format, colorize))
|
||||
} else {
|
||||
printUrl := args.Flag.Bool("--url")
|
||||
copyUrl := args.Flag.Bool("--copy")
|
||||
|
||||
printBrowseOrCopy(args, openUrl, !printUrl && !copyUrl, copyUrl)
|
||||
}
|
||||
}
|
||||
|
||||
func findCurrentPullRequest(localRepo *github.GitHubRepo, baseProject *github.Project, headArg string) (*github.PullRequest, error) {
|
||||
|
|
|
@ -35,6 +35,48 @@ Feature: hub pr show
|
|||
And the output should contain exactly:
|
||||
"""
|
||||
https://github.com/ashemesh/hub/pull/102\n
|
||||
"""
|
||||
|
||||
Scenario: Format Current branch output URL
|
||||
Given I am on the "topic" branch
|
||||
Given the GitHub API server:
|
||||
"""
|
||||
get('/repos/ashemesh/hub/pulls'){
|
||||
assert :state => "open",
|
||||
:head => "ashemesh:topic"
|
||||
json [
|
||||
{
|
||||
:html_url => "https://github.com/ashemesh/hub/pull/102",
|
||||
:number => 102
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
get('/repos/ashemesh/hub/pulls/102') {
|
||||
json :number => 999,
|
||||
:title => "First",
|
||||
:state => "open",
|
||||
:base => {
|
||||
:ref => "master",
|
||||
:label => "github:master",
|
||||
:repo => { :owner => { :login => "github" } }
|
||||
},
|
||||
:head => { :ref => "patch-1", :label => "octocat:patch-1" },
|
||||
:user => { :login => "octocat" },
|
||||
:requested_reviewers => [
|
||||
{ :login => "rey" },
|
||||
],
|
||||
:requested_teams => [
|
||||
{ :slug => "troopers" },
|
||||
{ :slug => "cantina-band" },
|
||||
]
|
||||
}
|
||||
"""
|
||||
When I successfully run `hub pr show -f "%sC%>(8)%i %rs%n"`
|
||||
Then "open https://github.com/ashemesh/hub/pull/102" should not be run
|
||||
And the output should contain exactly:
|
||||
"""
|
||||
#999 rey, github/troopers, github/cantina-band\n
|
||||
"""
|
||||
|
||||
Scenario: Current branch in fork
|
||||
|
@ -146,6 +188,36 @@ Feature: hub pr show
|
|||
When I successfully run `hub pr show 102`
|
||||
Then "open https://github.com/ashemesh/hub/pull/102" should be run
|
||||
|
||||
Scenario: Format pull request by number
|
||||
Given the GitHub API server:
|
||||
"""
|
||||
get('/repos/ashemesh/hub/pulls/102') {
|
||||
json :number => 999,
|
||||
:title => "First",
|
||||
:state => "open",
|
||||
:base => {
|
||||
:ref => "master",
|
||||
:label => "github:master",
|
||||
:repo => { :owner => { :login => "github" } }
|
||||
},
|
||||
:head => { :ref => "patch-1", :label => "octocat:patch-1" },
|
||||
:user => { :login => "octocat" },
|
||||
:requested_reviewers => [
|
||||
{ :login => "rey" },
|
||||
],
|
||||
:requested_teams => [
|
||||
{ :slug => "troopers" },
|
||||
{ :slug => "cantina-band" },
|
||||
]
|
||||
}
|
||||
"""
|
||||
When I successfully run `hub pr show 102 -f "%sC%>(8)%i %rs%n"`
|
||||
Then "open https://github.com/ashemesh/hub/pull/102" should not be run
|
||||
And the output should contain exactly:
|
||||
"""
|
||||
#999 rey, github/troopers, github/cantina-band\n
|
||||
"""
|
||||
|
||||
Scenario: Show pull request by invalid number
|
||||
When I run `hub pr show XYZ`
|
||||
Then the exit status should be 1
|
||||
|
|
Загрузка…
Ссылка в новой задаче