@@ -190,17 +190,25 @@ func parseSimpleCommit(commitPart commitPart, commit *gitrepo.Commit, libraryID
190190 processFooters (footers )
191191
192192 var commits []* ConventionalCommit
193- // If the body lines have multiple headers, separate them into different conventional
194- // commit, all associated with the same commit sha.
195- // Note that we assume single line headers, the 2nd line of headers, if exists,
196- // will be discarded .
193+ // Hold the subjects of each commit.
194+ var subjects [][] string
195+ // If the body lines have multiple headers, separate them into different conventional commit, all associated with
196+ // the same commit sha .
197197 for _ , bodyLine := range bodyLines {
198198 header , ok := parseHeader (bodyLine )
199199 if ! ok {
200200 slog .Warn ("bodyLine is not a header" , "bodyLine" , bodyLine , "hash" , commit .Hash .String ())
201+ if len (commits ) == 0 {
202+ // This should not happen as we expect a conventional commit message inside a nested commit.
203+ continue
204+ }
205+
206+ // This might be a multi-line header, append the line to the subject of the last commit.
207+ subjects [len (subjects )- 1 ] = append (subjects [len (subjects )- 1 ], strings .TrimSpace (bodyLine ))
201208 continue
202209 }
203210
211+ subjects = append (subjects , []string {})
204212 commits = append (commits , & ConventionalCommit {
205213 Type : header .Type ,
206214 Scope : header .Scope ,
@@ -214,10 +222,17 @@ func parseSimpleCommit(commitPart commitPart, commit *gitrepo.Commit, libraryID
214222 })
215223 }
216224
217- // If only one conventional commit is found, i.e., only one header line is
218- // in the commit message, assign the body field.
219225 if len (commits ) == 1 {
226+ // If only one conventional commit is found, i.e., only one header line is
227+ // in the commit message, assign the body field.
220228 commits [0 ].Body = strings .TrimSpace (strings .Join (bodyLines [1 :], "\n " ))
229+ } else {
230+ // Otherwise, concatenate all lines as the subject of the corresponding commit.
231+ // This is a workaround when GitHub inserts line breaks in the middle of a long line after squash and merge.
232+ for i , commit := range commits {
233+ sub := fmt .Sprintf ("%s %s" , commit .Subject , strings .Join (subjects [i ], " " ))
234+ commit .Subject = strings .TrimSpace (sub )
235+ }
221236 }
222237
223238 return commits , nil
0 commit comments