未验证 提交 b9e86a5d 编写于 作者: M Mislav Marohnić 提交者: GitHub

Merge pull request #1734 from HaraldNordgren/pull_request_no_edit

Create '--no-edit' option for hub pull-request
......@@ -32,6 +32,10 @@ pull-request -i <ISSUE>
Use the first line of <MESSAGE> 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 <FILE>
Read the pull request title and description from <FILE>.
......@@ -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("Aborted: no commits detected between %s and %s", baseTracking, head))
}
message, err := git.Show(commits[len(commits)-1])
utils.Check(err)
messageBuilder.Message = message
} else if flagPullRequestIssue == "" {
messageBuilder.Edit = true
......
......@@ -160,6 +160,87 @@ 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: No commits with "--no-edit"
Given I am on the "master" branch pushed to "origin/master"
When I successfully run `git checkout --quiet -b topic`
And I run `hub pull-request --no-edit`
Then the exit status should be 1
And the stderr should contain exactly:
"""
Aborted: no commits detected between origin/master and topic\n
"""
Scenario: Message template should include git log summary between base and head
Given the text editor adds:
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册