提交 42719ada 编写于 作者: D David Calavera

Simplify title and body hint message creation.

上级 0624580e
......@@ -5,7 +5,6 @@ import (
"github.com/jingweno/gh/git"
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
"io/ioutil"
"reflect"
"regexp"
"strings"
......@@ -188,23 +187,24 @@ func pullRequest(cmd *Command, args *Args) {
}
func writePullRequestTitleAndBody(base, head, fullBase, fullHead string, commits []string) (title, body string, err error) {
return github.GetTitleAndBodyFromEditor("PULLREQ", func(messageFile string) error {
return writePullRequestChanges(base, head, fullBase, fullHead, commits, messageFile)
})
message, err := pullRequestChangesMessage(base, head, fullBase, fullHead, commits)
utils.Check(err)
return github.GetTitleAndBodyFromEditor("PULLREQ", message)
}
func writePullRequestChanges(base, head, fullBase, fullHead string, commits []string, messageFile string) error {
func pullRequestChangesMessage(base, head, fullBase, fullHead string, commits []string) (string, error) {
var defaultMsg, commitSummary string
if len(commits) == 1 {
msg, err := git.Show(commits[0])
if err != nil {
return err
return "", err
}
defaultMsg = fmt.Sprintf("%s\n", msg)
} else if len(commits) > 1 {
commitLogs, err := git.Log(base, head)
if err != nil {
return err
return "", err
}
if len(commitLogs) > 0 {
......@@ -231,7 +231,7 @@ func writePullRequestChanges(base, head, fullBase, fullHead string, commits []st
`
message = fmt.Sprintf(message, defaultMsg, fullBase, fullHead, commitSummary)
return ioutil.WriteFile(messageFile, []byte(message), 0644)
return message, nil
}
func parsePullRequestProject(context *github.Project, s string) (p *github.Project, ref string) {
......
......@@ -7,7 +7,6 @@ import (
"github.com/jingweno/gh/utils"
"github.com/jingweno/go-octokit/octokit"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
......@@ -110,17 +109,15 @@ func release(cmd *Command, args *Args) {
}
func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string) (string, string, error) {
return github.GetTitleAndBodyFromEditor("RELEASE", func(messageFile string) error {
message := `
message := `
# Creating release %s for %s from %s
#
# Write a message for this release. The first block
# of the text is the title and the rest is description.
`
message = fmt.Sprintf(message, tag, project.Name, currentBranch)
message = fmt.Sprintf(message, tag, project.Name, currentBranch)
return ioutil.WriteFile(messageFile, []byte(message), 0644)
})
return github.GetTitleAndBodyFromEditor("RELEASE", message)
}
func runInLocalRepo(fn func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client)) {
......
......@@ -35,15 +35,15 @@ func GetTitleAndBodyFromFlags(messageFlag, fileFlag string) (title, body string,
return
}
func GetTitleAndBodyFromEditor(about string, fn func(messageFile string) error) (title, body string, err error) {
func GetTitleAndBodyFromEditor(about, message string) (title, body string, err error) {
messageFile, err := getMessageFile(about)
if err != nil {
return
}
defer os.Remove(messageFile)
if fn != nil {
err = fn(messageFile)
if message != "" {
err = ioutil.WriteFile(messageFile, []byte(message), 0644)
if err != nil {
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册