Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show the commit message body #83

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/actions/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ type prBodyTemplateData struct {
Commits []git.CommitInfo
}

var prBodyTemplate = template.Must(template.New("prBody").Parse(`%% Creating pull request for branch '{{ .Branch }}'
var templateFuncs = template.FuncMap{"trimSpace": strings.TrimSpace}

var prBodyTemplate = template.Must(template.New("prBody").Funcs(templateFuncs).Parse(`%% Creating pull request for branch '{{ .Branch }}'
%% Lines starting with '%%' will be ignored and an empty message aborts the
%% creation of the pull request.

Expand All @@ -283,6 +285,11 @@ var prBodyTemplate = template.Must(template.New("prBody").Parse(`%% Creating pul
%% This branch includes the following commits:
{{- range $c := .Commits }}
%% {{ $c.ShortHash }} {{ $c.Subject }}
{{- if trimSpace $c.Body }}
{{- range $line := $c.BodyWithPrefix "%% " }}
{{ trimSpace $line }}
{{- end }}
{{- end }}
{{- end }}
`))

Expand Down
8 changes: 8 additions & 0 deletions internal/git/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ type CommitInfo struct {
Body string
}

func (c CommitInfo) BodyWithPrefix(prefix string) []string {
var lines []string
for _, line := range strings.Split(strings.TrimSpace(c.Body), "\n") {
lines = append(lines, prefix + line)
}
return lines
}

func (r *Repo) CommitInfo(opts CommitInfoOpts) (*CommitInfo, error) {
// Need --quiet to suppress the diff that would otherwise be printed at the
// end
Expand Down