mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-15 18:08:23 -07:00
47efba78ec
Fix #21435. Use the first line of the template as the git commit message title, and the rest as the description. ## Snapshots <img width="806" alt="image" src="https://user-images.githubusercontent.com/9418365/209644083-5d85179c-cf58-404f-bc98-c662398a2411.png"> <img width="860" alt="image" src="https://user-images.githubusercontent.com/9418365/209644392-22573090-e2c1-458b-ba44-855b79735632.png"> <img width="1154" alt="image" src="https://user-images.githubusercontent.com/9418365/209644457-a1b2711a-6787-45b4-b52c-a88d7fc132d7.png"> Co-authored-by: delvh <dev.lh@web.de>
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pull
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_expandDefaultMergeMessage(t *testing.T) {
|
|
type args struct {
|
|
template string
|
|
vars map[string]string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
wantBody string
|
|
}{
|
|
{
|
|
name: "single line",
|
|
args: args{
|
|
template: "Merge ${PullRequestTitle}",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "",
|
|
},
|
|
{
|
|
name: "multiple lines",
|
|
args: args{
|
|
template: "Merge ${PullRequestTitle}\nDescription:\n\n${PullRequestDescription}\n",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "Description:\n\nPull\nRequest\nDescription\n",
|
|
},
|
|
{
|
|
name: "leading newlines",
|
|
args: args{
|
|
template: "\n\n\nMerge ${PullRequestTitle}\n\n\nDescription:\n\n${PullRequestDescription}\n",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "Description:\n\nPull\nRequest\nDescription\n",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, got1 := expandDefaultMergeMessage(tt.args.template, tt.args.vars)
|
|
assert.Equalf(t, tt.want, got, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars)
|
|
assert.Equalf(t, tt.wantBody, got1, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars)
|
|
})
|
|
}
|
|
}
|