diff --git a/commands/issue.go b/commands/issue.go index 219821ce344e4fb3cf933e3af8d00e12d70cd293..0e921dc7bdc5061dd0449056911bd3cad6a7bd36 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -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) diff --git a/commands/pull_request.go b/commands/pull_request.go index bd83b6e0b9c4dc98d3a62f3da36cef5d51c37a09..b566d5cfe45d855fd760c3745222f111e9dc26e6 100644 --- a/commands/pull_request.go +++ b/commands/pull_request.go @@ -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) diff --git a/commands/release.go b/commands/release.go index 1769a26de55b0249922bd874cfbda2f8b3afa927..b502073ede7d88edaf143ba210e4e3382edf3825 100644 --- a/commands/release.go +++ b/commands/release.go @@ -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) diff --git a/github/editor.go b/github/editor.go index ceff944a7c89b326c2edd09cd04679f8b3135c93..dbc5ac237e2a2142632885779a019d3507620a8e 100644 --- a/github/editor.go +++ b/github/editor.go @@ -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 -} diff --git a/github/editor_test.go b/github/editor_test.go index a05a80ca8684a572a6b3e35c15da67f21cfbef1e..63264ad2b5b8262f070693ae3f7cf06cc16093d3 100644 --- a/github/editor_test.go +++ b/github/editor_test.go @@ -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")) -}