@@ -97,6 +97,65 @@ func TestCalculateCommitTitle(t *testing.T) {
9797 }
9898}
9999
100+ func TestCalculateCommitMessage (t * testing.T ) {
101+ defaultPullContext := & pulltest.MockPullContext {
102+ TitleValue : "This is the PR title!" ,
103+ BodyValue : "This is the PR body!" ,
104+ CommitsValue : []* pull.Commit {
105+ {SHA : "f6374a30ec7a3f2dbf35b40ac984b64358ccd246" , Message : "The first commit message!" },
106+ {SHA : "89aec3244253260261351047f0bf6d9b7626c4f6" , Message : "The second commit message!" },
107+ {SHA : "9907911cde43652c51808f79047c98f0d48ae58f" , Message : "The third commit message!" },
108+ },
109+ }
110+
111+ tests := map [string ]struct {
112+ PullContext pull.Context
113+ Strategy MessageStrategy
114+ Delimiter string
115+ Output string
116+ }{
117+ "emptyBody" : {
118+ PullContext : defaultPullContext ,
119+ Strategy : EmptyBody ,
120+ Output : "" ,
121+ },
122+ "summarizeCommits" : {
123+ PullContext : defaultPullContext ,
124+ Strategy : SummarizeCommits ,
125+ Output : "* The first commit message!\n * The second commit message!\n * The third commit message!\n " ,
126+ },
127+ "pullRequestBody" : {
128+ PullContext : defaultPullContext ,
129+ Strategy : PullRequestBody ,
130+ Output : "This is the PR body!" ,
131+ },
132+ "pullRequestBodyDelimiter" : {
133+ PullContext : & pulltest.MockPullContext {
134+ BodyValue : "Prefix text...\n ~~\n The delimited body\n ~~\n Suffix text..." ,
135+ },
136+ Strategy : PullRequestBody ,
137+ Delimiter : "~~" ,
138+ Output : "The delimited body" ,
139+ },
140+ "pullRequestBodyMissingDelimiter" : {
141+ PullContext : defaultPullContext ,
142+ Strategy : PullRequestBody ,
143+ Delimiter : "~~" ,
144+ Output : "" ,
145+ },
146+ }
147+
148+ ctx := context .Background ()
149+
150+ for name , test := range tests {
151+ t .Run (name , func (t * testing.T ) {
152+ output , err := calculateCommitMessage (ctx , test .PullContext , SquashOptions {Body : test .Strategy , MessageDelimiter : test .Delimiter })
153+ require .NoError (t , err )
154+ assert .Equal (t , test .Output , output , "calculated body is incorrect" )
155+ })
156+ }
157+ }
158+
100159func TestPushRestrictionMerger (t * testing.T ) {
101160 normal := & MockMerger {}
102161 restricted := & MockMerger {}
0 commit comments