示例#1
0
func createPullRequestMessage(base, head, fullBase, fullHead string) (string, error) {
	var (
		defaultMsg string
		commitLogs string
		err        error
	)

	commits, _ := git.RefList(base, head)
	if len(commits) == 1 {
		defaultMsg, err = git.Show(commits[0])
		if err != nil {
			return "", err
		}
	} else if len(commits) > 1 {
		commitLogs, err = git.Log(base, head)
		if err != nil {
			return "", err
		}
	}

	workdir, err := git.WorkdirName()
	if err != nil {
		return "", err
	}
	template, err := github.ReadTemplate(github.PullRequestTemplate, workdir)
	if err != nil {
		return "", err
	} else if template != "" {
		if defaultMsg == "" {
			defaultMsg = "\n\n" + template
		} else {
			parts := strings.SplitN(defaultMsg, "\n\n", 2)
			defaultMsg = parts[0] + "\n\n" + template
			if len(parts) > 1 && parts[1] != "" {
				defaultMsg = defaultMsg + "\n\n" + parts[1]
			}
		}
	}

	cs := git.CommentChar()

	return renderPullRequestTpl(defaultMsg, cs, fullBase, fullHead, commitLogs)
}
示例#2
0
func pullRequestChangesMessage(base, head, fullBase, fullHead string) (string, error) {
	var (
		defaultMsg string
		commitLogs string
		err        error
	)

	commits, _ := git.RefList(base, head)
	if len(commits) == 1 {
		defaultMsg, err = git.Show(commits[0])
		if err != nil {
			return "", err
		}
	} else if len(commits) > 1 {
		commitLogs, err = git.Log(base, head)
		if err != nil {
			return "", err
		}
	}

	cs := git.CommentChar()

	return renderPullRequestTpl(defaultMsg, cs, fullBase, fullHead, commitLogs)
}