From f28805d9b00ef3b7ef6e5c50ca2f452c1be3e829 Mon Sep 17 00:00:00 2001 From: Jingwen Owen Ou Date: Fri, 24 May 2013 11:54:01 -0700 Subject: [PATCH] Don't show commit logs if not available --- pull_request.go | 26 +++++++++++++++----------- repo.go | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/pull_request.go b/pull_request.go index eb875f49..852fb371 100644 --- a/pull_request.go +++ b/pull_request.go @@ -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) } diff --git a/repo.go b/repo.go index e8b036a3..55db06a1 100644 --- a/repo.go +++ b/repo.go @@ -1,5 +1,9 @@ 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 { -- GitLab