diff --git a/commands/pull_request.go b/commands/pull_request.go index d239887c91d1bf75cdef59a256c0b5ed92e1f61d..e4a0472b16256131ecc956c87077dc214a076505 100644 --- a/commands/pull_request.go +++ b/commands/pull_request.go @@ -32,6 +32,10 @@ pull-request -i Use the first line of as pull request title, and the rest as pull request description. + --no-edit + Use the message from the first commit on the branch as pull request title + and description without opening a text editor. + -F, --file Read the pull request title and description from . @@ -93,7 +97,8 @@ var ( flagPullRequestCopy, flagPullRequestEdit, flagPullRequestPush, - flagPullRequestForce bool + flagPullRequestForce, + flagPullRequestNoEdit bool flagPullRequestAssignees, flagPullRequestReviewers, @@ -110,6 +115,7 @@ func init() { cmdPullRequest.Flag.BoolVarP(&flagPullRequestEdit, "edit", "e", false, "EDIT") cmdPullRequest.Flag.BoolVarP(&flagPullRequestPush, "push", "p", false, "PUSH") cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE") + cmdPullRequest.Flag.BoolVarP(&flagPullRequestNoEdit, "no-edit", "", false, "NO-EDIT") cmdPullRequest.Flag.StringVarP(&flagPullRequestFile, "file", "F", "", "FILE") cmdPullRequest.Flag.VarP(&flagPullRequestAssignees, "assign", "a", "USERS") cmdPullRequest.Flag.VarP(&flagPullRequestReviewers, "reviewer", "r", "USERS") @@ -237,6 +243,14 @@ of text is the title and the rest is the description.`, fullBase, fullHead)) messageBuilder.Message, err = msgFromFile(flagPullRequestFile) utils.Check(err) messageBuilder.Edit = flagPullRequestEdit + } else if flagPullRequestNoEdit { + commits, _ := git.RefList(baseTracking, head) + if len(commits) == 0 { + utils.Check(fmt.Errorf("No commits detected between '' and '' branches")) + } + message, err := git.Show(commits[len(commits)-1]) + utils.Check(err) + messageBuilder.Message = message } else if flagPullRequestIssue == "" { messageBuilder.Edit = true diff --git a/features/pull_request.feature b/features/pull_request.feature index 92a492a8b90a93ed7f86e89e978109360547eee7..de434e6976668d1e0a5a031c924592a502418e57 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -160,6 +160,77 @@ Feature: hub pull-request When I successfully run `hub pull-request` Then the output should contain exactly "the://url\n" + Scenario: Single-commit pull request with "--no-edit" + Given the GitHub API server: + """ + post('/repos/mislav/coral/pulls') { + assert :title => 'Commit title 1', + :body => 'Commit body 1' + status 201 + json :html_url => "the://url" + } + """ + Given I am on the "master" branch pushed to "origin/master" + When I successfully run `git checkout --quiet -b topic` + Given I make a commit with message: + """ + Commit title 1 + + Commit body 1 + """ + And the "topic" branch is pushed to "origin/topic" + When I successfully run `hub pull-request --no-edit` + Then the output should contain exactly "the://url\n" + + Scenario: Multiple-commit pull request with "--no-edit" + Given the GitHub API server: + """ + post('/repos/mislav/coral/pulls') { + assert :title => 'Commit title 1', + :body => 'Commit body 1' + status 201 + json :html_url => "the://url" + } + """ + Given I am on the "master" branch pushed to "origin/master" + When I successfully run `git checkout --quiet -b topic` + Given I make a commit with message: + """ + Commit title 1 + + Commit body 1 + """ + Given I make a commit with message: + """ + Commit title 2 + + Commit body 2 + """ + And the "topic" branch is pushed to "origin/topic" + When I successfully run `hub pull-request --no-edit` + Then the output should contain exactly "the://url\n" + + Scenario: Pull request with "--push" and "--no-edit" + Given the GitHub API server: + """ + post('/repos/mislav/coral/pulls') { + assert :title => 'Commit title 1', + :body => 'Commit body 1' + status 201 + json :html_url => "the://url" + } + """ + Given I am on the "master" branch pushed to "origin/master" + When I successfully run `git checkout --quiet -b topic` + Given I make a commit with message: + """ + Commit title 1 + + Commit body 1 + """ + When I successfully run `hub pull-request --push --no-edit` + Then the output should contain exactly "the://url\n" + Scenario: Message template should include git log summary between base and head Given the text editor adds: """