From 04e43fa22fd9eda7a62e354035dab05ec874eb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 31 Jul 2017 17:11:30 +0200 Subject: [PATCH] Use full text editor filename at call site for greppability --- commands/issue.go | 4 ++-- commands/pull_request.go | 4 ++-- commands/release.go | 8 ++++---- github/editor.go | 14 +++----------- github/editor_test.go | 5 ----- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/commands/issue.go b/commands/issue.go index 219821ce..0e921dc7 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 bd83b6e0..b566d5cf 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 1769a26d..b502073e 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 ceff944a..dbc5ac23 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 a05a80ca..63264ad2 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")) -} -- GitLab