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

Merge pull request #1951 from github/multiline-message

Add support for multiple `--message` options
......@@ -106,7 +106,11 @@ With no arguments, show a list of open issues.
%uI: updated date, ISO 8601 format
-m, --message <MESSAGE>
Use the first line of <MESSAGE> as issue title, and the rest as issue description.
The text up to the first blank line in <MESSAGE> is treated as the issue
title, and the rest is used as issue description in Markdown format.
If multiple <MESSAGE> options are given, their values are concatenated as
separate paragraphs.
-F, --file <FILE>
Read the issue title and description from <FILE>.
......@@ -175,7 +179,6 @@ With no arguments, show a list of open issues.
flagIssueState,
flagIssueFormat,
flagShowIssueFormat,
flagIssueMessage,
flagIssueMilestoneFilter,
flagIssueCreator,
flagIssueMentioned,
......@@ -184,6 +187,8 @@ With no arguments, show a list of open issues.
flagIssueSort,
flagIssueFile string
flagIssueMessage messageBlocks
flagIssueEdit,
flagIssueCopy,
flagIssueBrowse,
......@@ -203,7 +208,7 @@ With no arguments, show a list of open issues.
func init() {
cmdShowIssue.Flag.StringVarP(&flagShowIssueFormat, "format", "f", "", "FORMAT")
cmdCreateIssue.Flag.StringVarP(&flagIssueMessage, "message", "m", "", "MESSAGE")
cmdCreateIssue.Flag.VarP(&flagIssueMessage, "message", "m", "MESSAGE")
cmdCreateIssue.Flag.StringVarP(&flagIssueFile, "file", "F", "", "FILE")
cmdCreateIssue.Flag.Uint64VarP(&flagIssueMilestone, "milestone", "M", 0, "MILESTONE")
cmdCreateIssue.Flag.VarP(&flagIssueLabels, "label", "l", "LABEL")
......@@ -471,8 +476,8 @@ func createIssue(cmd *Command, args *Args) {
Write a message for this issue. The first block of
text is the title and the rest is the description.`, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagIssueMessage
if len(flagIssueMessage) > 0 {
messageBuilder.Message = flagIssueMessage.String()
messageBuilder.Edit = flagIssueEdit
} else if cmd.FlagPassed("file") {
messageBuilder.Message, err = msgFromFile(flagIssueFile)
......
......@@ -29,8 +29,12 @@ pull-request -i <ISSUE>
Skip the check for unpushed commits.
-m, --message <MESSAGE>
Use the first line of <MESSAGE> as pull request title, and the rest as pull
request description.
The text up to the first blank line in <MESSAGE> is treated as the pull
request title, and the rest is used as pull request description in Markdown
format.
If multiple <MESSAGE> options are given, their values are concatenated as
separate paragraphs.
--no-edit
Use the message from the first commit on the branch as pull request title
......@@ -104,10 +108,11 @@ var (
flagPullRequestBase,
flagPullRequestHead,
flagPullRequestIssue,
flagPullRequestMessage,
flagPullRequestMilestone,
flagPullRequestFile string
flagPullRequestMessage messageBlocks
flagPullRequestBrowse,
flagPullRequestCopy,
flagPullRequestEdit,
......@@ -126,7 +131,7 @@ func init() {
cmdPullRequest.Flag.StringVarP(&flagPullRequestIssue, "issue", "i", "", "ISSUE")
cmdPullRequest.Flag.BoolVarP(&flagPullRequestBrowse, "browse", "o", false, "BROWSE")
cmdPullRequest.Flag.BoolVarP(&flagPullRequestCopy, "copy", "c", false, "COPY")
cmdPullRequest.Flag.StringVarP(&flagPullRequestMessage, "message", "m", "", "MESSAGE")
cmdPullRequest.Flag.VarP(&flagPullRequestMessage, "message", "m", "MESSAGE")
cmdPullRequest.Flag.BoolVarP(&flagPullRequestEdit, "edit", "e", false, "EDIT")
cmdPullRequest.Flag.BoolVarP(&flagPullRequestPush, "push", "p", false, "PUSH")
cmdPullRequest.Flag.BoolVarP(&flagPullRequestForce, "force", "f", false, "FORCE")
......@@ -251,8 +256,8 @@ func pullRequest(cmd *Command, args *Args) {
Write a message for this pull request. The first block
of text is the title and the rest is the description.`, fullBase, fullHead))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagPullRequestMessage
if len(flagPullRequestMessage) > 0 {
messageBuilder.Message = flagPullRequestMessage.String()
messageBuilder.Edit = flagPullRequestEdit
} else if cmd.FlagPassed("file") {
messageBuilder.Message, err = msgFromFile(flagPullRequestFile)
......
......@@ -73,7 +73,11 @@ With '--exclude-prereleases', exclude non-stable releases from the listing.
character is taken as asset label.
-m, --message <MESSAGE>
Use the first line of <MESSAGE> as release title, and the rest as release description.
The text up to the first blank line in <MESSAGE> is treated as the release
title, and the rest is used as release description in Markdown format.
If multiple <MESSAGE> options are given, their values are concatenated as
separate paragraphs.
-F, --file <FILE>
Read the release title and description from <FILE>.
......@@ -175,12 +179,13 @@ hub(1), git-tag(1)
flagReleaseCopy,
flagReleasePrerelease bool
flagReleaseMessage,
flagReleaseFile,
flagReleaseFormat,
flagShowReleaseFormat,
flagReleaseCommitish string
flagReleaseMessage messageBlocks
flagReleaseAssets stringSliceValue
flagReleaseLimit int
......@@ -201,7 +206,7 @@ func init() {
cmdCreateRelease.Flag.BoolVarP(&flagReleaseBrowse, "browse", "o", false, "BROWSE")
cmdCreateRelease.Flag.BoolVarP(&flagReleaseCopy, "copy", "c", false, "COPY")
cmdCreateRelease.Flag.VarP(&flagReleaseAssets, "attach", "a", "ATTACH_ASSETS")
cmdCreateRelease.Flag.StringVarP(&flagReleaseMessage, "message", "m", "", "MESSAGE")
cmdCreateRelease.Flag.VarP(&flagReleaseMessage, "message", "m", "MESSAGE")
cmdCreateRelease.Flag.StringVarP(&flagReleaseFile, "file", "F", "", "FILE")
cmdCreateRelease.Flag.StringVarP(&flagReleaseCommitish, "commitish", "t", "", "COMMITISH")
......@@ -209,7 +214,7 @@ func init() {
cmdEditRelease.Flag.BoolVarP(&flagReleaseDraft, "draft", "d", false, "DRAFT")
cmdEditRelease.Flag.BoolVarP(&flagReleasePrerelease, "prerelease", "p", false, "PRERELEASE")
cmdEditRelease.Flag.VarP(&flagReleaseAssets, "attach", "a", "ATTACH_ASSETS")
cmdEditRelease.Flag.StringVarP(&flagReleaseMessage, "message", "m", "", "MESSAGE")
cmdEditRelease.Flag.VarP(&flagReleaseMessage, "message", "m", "MESSAGE")
cmdEditRelease.Flag.StringVarP(&flagReleaseFile, "file", "F", "", "FILE")
cmdEditRelease.Flag.StringVarP(&flagReleaseCommitish, "commitish", "t", "", "COMMITISH")
......@@ -421,8 +426,8 @@ func createRelease(cmd *Command, args *Args) {
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagReleaseMessage
if len(flagReleaseMessage) > 0 {
messageBuilder.Message = flagReleaseMessage.String()
messageBuilder.Edit = flagReleaseEdit
} else if cmd.FlagPassed("file") {
messageBuilder.Message, err = msgFromFile(flagReleaseFile)
......@@ -507,8 +512,8 @@ func editRelease(cmd *Command, args *Args) {
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagReleaseMessage
if len(flagReleaseMessage) > 0 {
messageBuilder.Message = flagReleaseMessage.String()
messageBuilder.Edit = flagReleaseEdit
} else if cmd.FlagPassed("file") {
messageBuilder.Message, err = msgFromFile(flagReleaseFile)
......
......@@ -39,6 +39,17 @@ func (l *listFlag) Set(value string) error {
return nil
}
type messageBlocks []string
func (m *messageBlocks) String() string {
return strings.Join([]string(*m), "\n\n")
}
func (m *messageBlocks) Set(value string) error {
*m = append(*m, value)
return nil
}
func isCloneable(file string) bool {
f, err := os.Open(file)
if err != nil {
......
......@@ -34,7 +34,7 @@ complete -f -c hub -n '__fish_hub_needs_command' -a sync -d "update local branch
complete -f -c hub -n ' __fish_hub_using_command alias' -a 'bash zsh sh ksh csh fish' -d "output shell script suitable for eval"
# pull-request
complete -f -c hub -n ' __fish_hub_using_command pull-request' -s f -d "Skip the check for unpushed commits"
complete -f -c hub -n ' __fish_hub_using_command pull-request' -s -m -d "Use the first line of <MESSAGE> as pull request title, and the rest as pull request description"
complete -f -c hub -n ' __fish_hub_using_command pull-request' -s -m -d "Set the pull request title and description separated by a blank line"
complete -f -c hub -n ' __fish_hub_using_command pull-request' -s F -d "Read the pull request title and description from <FILE>"
complete -f -c hub -n ' __fish_hub_using_command pull-request' -s o -d "Open the new pull request in a web browser"
complete -f -c hub -n ' __fish_hub_using_command pull-request' -l browse -d "Open the new pull request in a web browser"
......
......@@ -499,6 +499,19 @@ Feature: hub pull-request
Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
And the file ".git/PULLREQ_EDITMSG" should not exist
Scenario: Title and body from multiple command-line arguments
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :title => 'I am just a pull',
:body => "A little pull\n\nAnd description"
status 201
json :html_url => "https://github.com/mislav/coral/pull/12"
}
"""
When I successfully run `hub pull-request -m "I am just a pull" -m "A little pull" -m "And description"`
Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
Scenario: Error when implicit head is the same as base
Given I am on the "master" branch with upstream "origin/master"
When I run `hub pull-request`
......
package github
import (
"testing"
"github.com/bmizerany/assert"
)
func TestMessageBuilder_multiline_title(t *testing.T) {
builder := &MessageBuilder{
Message: `hello
multiline
text
the rest is
description`,
}
title, body, err := builder.Extract()
assert.Equal(t, nil, err)
assert.Equal(t, "hello multiline text", title)
assert.Equal(t, "the rest is\ndescription", body)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册