@@ -19,6 +19,8 @@ export interface Commit {
1919 fullText : string ;
2020 /** The header line of the commit, will be used in the changelog entries. */
2121 header : string ;
22+ /** The original header line of the commit, before stripping away fixup, squash, etc. */
23+ originalHeader : string ;
2224 /** The full body of the commit, not including the footer. */
2325 body : string ;
2426 /** The footer of the commit, containing issue references and note sections. */
@@ -114,8 +116,8 @@ const parseOptions: ParserOptions = {
114116 noteKeywords : [ NoteSections . BREAKING_CHANGE , NoteSections . DEPRECATED ] ,
115117 notesPattern : ( keywords : string ) => new RegExp ( `^\\s*(${ keywords } ): ?(.*)` ) ,
116118} ;
117-
118- let commitParser : CommitParser | undefined ;
119+ /** Instance of the commit parser to parse raw commits. */
120+ const commitParser = new CommitParser ( parseOptions ) ;
119121
120122/** Parse a commit message into its composite parts. */
121123export const parseCommitMessage : ( fullText : string ) => Commit = parseInternal ;
@@ -128,21 +130,18 @@ function parseInternal(fullText: string): Commit;
128130function parseInternal ( fullText : Buffer ) : CommitFromGitLog ;
129131function parseInternal ( fullText : string | Buffer ) : CommitFromGitLog | Commit {
130132 // Ensure the fullText symbol is a `string`, even if a Buffer was provided.
131- fullText = fullText . toString ( ) ;
132- /** The commit message text with the fixup and squash markers stripped out. */
133- const strippedCommitMsg = fullText
134- . replace ( FIXUP_PREFIX_RE , '' )
135- . replace ( SQUASH_PREFIX_RE , '' )
136- . replace ( REVERT_PREFIX_RE , '' ) ;
137-
138- commitParser ??= new CommitParser ( parseOptions ) ;
139-
133+ fullText = fullText . toString ( ) . trim ( ) ;
140134 /** The initially parsed commit. */
141- const commit = commitParser . parse ( strippedCommitMsg ) ;
135+ const commit = commitParser . parse ( fullText ) ;
142136 /** A list of breaking change notes from the commit. */
143137 const breakingChanges : CommitNote [ ] = [ ] ;
144138 /** A list of deprecation notes from the commit. */
145139 const deprecations : CommitNote [ ] = [ ] ;
140+ /** The extracted header after stripping away fixup, squash, etc. */
141+ const header = ( commit . header || '' )
142+ . replace ( FIXUP_PREFIX_RE , '' )
143+ . replace ( SQUASH_PREFIX_RE , '' )
144+ . replace ( REVERT_PREFIX_RE , '' ) ;
146145
147146 // Extract the commit message notes by marked types into their respective lists.
148147 for ( const note of commit . notes ) {
@@ -160,9 +159,10 @@ function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
160159 fullText,
161160 breakingChanges,
162161 deprecations,
162+ header,
163163 body : commit . body || '' ,
164164 footer : commit . footer || '' ,
165- header : commit . header || '' ,
165+ originalHeader : commit . header || '' ,
166166 references : commit . references ,
167167 scope : commit [ 'scope' ] || '' ,
168168 subject : commit [ 'subject' ] || '' ,
0 commit comments