提交 04e43fa2 编写于 作者: M Mislav Marohnić

Use full text editor filename at call site for greppability

上级 4837835d
......@@ -364,7 +364,7 @@ func createIssue(cmd *Command, args *Args) {
if cmd.FlagPassed("message") {
title, body = readMsg(flagIssueMessage)
} else if cmd.FlagPassed("file") {
title, body, editor, err = readMsgFromFile(flagIssueFile, flagIssueEdit, "ISSUE", "issue")
title, body, editor, err = readMsgFromFile(flagIssueFile, flagIssueEdit, "ISSUE_EDITMSG", "issue")
utils.Check(err)
} else {
message := ""
......@@ -382,7 +382,7 @@ text is the title and the rest is the description.`, project)
}
}
editor, err := github.NewEditor("ISSUE", "issue", message)
editor, err := github.NewEditor("ISSUE_EDITMSG", "issue", message)
utils.Check(err)
editor.AddCommentedSection(helpMessage)
......
......@@ -226,7 +226,7 @@ func pullRequest(cmd *Command, args *Args) {
if cmd.FlagPassed("message") {
title, body = readMsg(flagPullRequestMessage)
} else if cmd.FlagPassed("file") {
title, body, editor, err = readMsgFromFile(flagPullRequestFile, flagPullRequestEdit, "PULLREQ", "pull request")
title, body, editor, err = readMsgFromFile(flagPullRequestFile, flagPullRequestEdit, "PULLREQ_EDITMSG", "pull request")
utils.Check(err)
} else if flagPullRequestIssue == "" {
headForMessage := headTracking
......@@ -270,7 +270,7 @@ of text is the title and the rest is the description.`, fullBase, fullHead)
helpMessage = helpMessage + "\n\nChanges:\n\n" + strings.TrimSpace(commitLogs)
}
editor, err = github.NewEditor("PULLREQ", "pull request", message)
editor, err = github.NewEditor("PULLREQ_EDITMSG", "pull request", message)
utils.Check(err)
editor.AddCommentedSection(helpMessage)
......
......@@ -303,7 +303,7 @@ func createRelease(cmd *Command, args *Args) {
if cmd.FlagPassed("message") {
title, body = readMsg(flagReleaseMessage)
} else if cmd.FlagPassed("file") {
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE", "release")
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE_EDITMSG", "release")
utils.Check(err)
} else {
message := ""
......@@ -312,7 +312,7 @@ 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.String())
editor, err := github.NewEditor("RELEASE", "release", message)
editor, err := github.NewEditor("RELEASE_EDITMSG", "release", message)
utils.Check(err)
editor.AddCommentedSection(helpMessage)
......@@ -391,7 +391,7 @@ func editRelease(cmd *Command, args *Args) {
if cmd.FlagPassed("message") {
title, body = readMsg(flagReleaseMessage)
} else if cmd.FlagPassed("file") {
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE", "release")
title, body, editor, err = readMsgFromFile(flagReleaseFile, flagReleaseEdit, "RELEASE_EDITMSG", "release")
utils.Check(err)
if title == "" {
......@@ -404,7 +404,7 @@ 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.String())
editor, err := github.NewEditor("RELEASE", "release", message)
editor, err := github.NewEditor("RELEASE_EDITMSG", "release", message)
utils.Check(err)
editor.AddCommentedSection(helpMessage)
......
......@@ -15,11 +15,12 @@ import (
"github.com/github/hub/git"
)
func NewEditor(filePrefix, topic, message string) (editor *Editor, err error) {
messageFile, err := getMessageFile(filePrefix)
func NewEditor(filename, topic, message string) (editor *Editor, err error) {
gitDir, err := git.Dir()
if err != nil {
return
}
messageFile := filepath.Join(gitDir, filename)
program, err := git.Editor()
if err != nil {
......@@ -164,12 +165,3 @@ func readTitleAndBody(reader io.Reader, cs string) (title, body string, err erro
return
}
func getMessageFile(about string) (string, error) {
gitDir, err := git.Dir()
if err != nil {
return "", err
}
return filepath.Join(gitDir, fmt.Sprintf("%s_EDITMSG", about)), nil
}
......@@ -160,8 +160,3 @@ Dem body.
assert.Equal(t, "# Dat title", title)
assert.Equal(t, "Dem body.", body)
}
func TestGetMessageFile(t *testing.T) {
gitPullReqMsgFile, _ := getMessageFile("PULLREQ")
assert.T(t, strings.Contains(gitPullReqMsgFile, "PULLREQ_EDITMSG"))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册