func writePullRequestChanges(repo *github.Repo, messageFile string) error { message := ` # Requesting a pull to %s from %s # # Write a message for this pull request. The first block # of the text is the title and the rest is description.%s ` startRegexp := regexp.MustCompilePOSIX("^") endRegexp := regexp.MustCompilePOSIX(" +$") commitLogs, _ := git.Log(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` changesMsg = fmt.Sprintf(changesMsg, commitLogs) } message = fmt.Sprintf(message, repo.FullBase(), repo.FullHead(), changesMsg) return ioutil.WriteFile(messageFile, []byte(message), 0644) }
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 } defaultMsg = fmt.Sprintf("%s\n", msg) } else if len(commits) > 1 { commitLogs, err := git.Log(base, head) if err != nil { return "", err } if len(commitLogs) > 0 { startRegexp := regexp.MustCompilePOSIX("^") endRegexp := regexp.MustCompilePOSIX(" +$") commitLogs = strings.TrimSpace(commitLogs) commitLogs = startRegexp.ReplaceAllString(commitLogs, "# ") commitLogs = endRegexp.ReplaceAllString(commitLogs, "") commitSummary = ` # # Changes: # %s` commitSummary = fmt.Sprintf(commitSummary, commitLogs) } } message := `%s # Requesting a pull to %s from %s # # Write a message for this pull request. The first block # of the text is the title and the rest is description.%s ` message = fmt.Sprintf(message, defaultMsg, fullBase, fullHead, commitSummary) return message, nil }