Create '--no-edit' option for hub pull-request

This commit is contained in:
Harald Nordgren 2018-05-03 01:02:52 +02:00
Родитель cd988bc491
Коммит 2628ba3471
2 изменённых файлов: 86 добавлений и 1 удалений

Просмотреть файл

@ -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("No commits detected between '<BASE>' and '<HEAD>' branches"))
}
message, err := git.Show(commits[len(commits)-1])
utils.Check(err)
messageBuilder.Message = message
} else if flagPullRequestIssue == "" {
messageBuilder.Edit = true

Просмотреть файл

@ -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:
"""