提交 f28805d9 编写于 作者: J Jingwen Owen Ou

Don't show commit logs if not available

上级 69ce2229
......@@ -75,23 +75,27 @@ func writePullRequestChanges(repo *Repo, messageFile string) error {
# Requesting a pull to %s from %s
#
# Write a message for this pull reuqest. The first block
# of the text is the title and the rest is description.
# of the text is the title and the rest is description.%s
`
startRegexp := regexp.MustCompilePOSIX("^")
endRegexp := regexp.MustCompilePOSIX(" +$")
commitLogs, _ := FetchGitCommitLogs(repo.Base, repo.Head)
var changesMsg string
if len(commitLogs) > 0 {
commitLogs = strings.TrimSpace(commitLogs)
commitLogs = startRegexp.ReplaceAllString(commitLogs, "# ")
commitLogs = endRegexp.ReplaceAllString(commitLogs, "")
changesMsg = `
#
# Changes:
#
%s
`
startRegexp := regexp.MustCompilePOSIX("^")
endRegexp := regexp.MustCompilePOSIX(" +$")
commitLogs, err := FetchGitCommitLogs(repo.Base, repo.Head)
check(err)
commitLogs = strings.TrimSpace(commitLogs)
commitLogs = startRegexp.ReplaceAllString(commitLogs, "# ")
commitLogs = endRegexp.ReplaceAllString(commitLogs, "")
changesMsg = fmt.Sprintf(changesMsg, commitLogs)
}
message = fmt.Sprintf(message, repo.FullBase(), repo.FullHead(), commitLogs)
message = fmt.Sprintf(message, repo.FullBase(), repo.FullHead(), changesMsg)
return ioutil.WriteFile(messageFile, []byte(message), 0644)
}
......
package main
import (
"strings"
)
type Repo struct {
Dir string
Editor string
......@@ -10,11 +14,19 @@ type Repo struct {
}
func (r *Repo) FullBase() string {
return r.Owner + ":" + r.Base
if strings.Contains(r.Base, ":") {
return r.Base
} else {
return r.Owner + ":" + r.Base
}
}
func (r *Repo) FullHead() string {
return r.Owner + ":" + r.Head
if strings.Contains(r.Head, ":") {
return r.Head
} else {
return r.Owner + ":" + r.Head
}
}
func NewRepo() *Repo {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册