@@ -37,7 +37,7 @@ export function extractCommitData(commit: string) {
3737 } ;
3838}
3939
40- export function parseRefsData ( refs : string ) : ParsedRefs {
40+ export function extractBranchesAndTags ( refs : string ) : ParsedRefs {
4141 if ( ! refs ) return { branches : [ ] , tags : [ ] } ;
4242
4343 const refsArray = refs . replace ( " -> " , ", " ) . split ( ", " ) ;
@@ -55,7 +55,7 @@ export function parseRefsData(refs: string): ParsedRefs {
5555 ) ;
5656}
5757
58- export function parseDiffStatLine ( line : string , diffStats : DifferenceStatistic ) {
58+ export function processDiffStatLine ( line : string , diffStats : DifferenceStatistic ) {
5959 const [ insertions , deletions , path ] = line . split ( "\t" ) ;
6060 const numberedInsertions = insertions === "-" ? 0 : Number ( insertions ) ;
6161 const numberedDeletions = deletions === "-" ? 0 : Number ( deletions ) ;
@@ -68,7 +68,7 @@ export function parseDiffStatLine(line: string, diffStats: DifferenceStatistic)
6868 } ;
6969}
7070
71- export function parseMessageAndDiffStats ( messageAndDiffStats : string [ ] ) : MessageAndDiffStats {
71+ export function extractMessageAndDiffStats ( messageAndDiffStats : string [ ] ) : MessageAndDiffStats {
7272 let messageSubject = "" ;
7373 let messageBody = "" ;
7474 const diffStats : DifferenceStatistic = {
@@ -78,19 +78,19 @@ export function parseMessageAndDiffStats(messageAndDiffStats: string[]): Message
7878 } ;
7979
8080 for ( const [ idx , line ] of messageAndDiffStats . entries ( ) ) {
81- if ( idx === 0 )
82- // message subject
81+ if ( idx === 0 ) {
8382 messageSubject = line ;
84- else if ( line . startsWith ( INDENTATION ) ) {
85- // message body (add newline if not first line)
83+ continue ;
84+ }
85+
86+ if ( line . startsWith ( INDENTATION ) ) {
8687 messageBody += idx === 1 ? line . trim ( ) : `\n${ line . trim ( ) } ` ;
87- } else if ( line === "" )
88- // pass empty line
8988 continue ;
90- else {
91- // diffStats
92- parseDiffStatLine ( line , diffStats ) ;
9389 }
90+
91+ if ( line === "" ) continue ;
92+
93+ processDiffStatLine ( line , diffStats ) ;
9494 }
9595
9696 const message = messageBody === "" ? messageSubject : `${ messageSubject } \n${ messageBody } ` ;
@@ -101,7 +101,7 @@ export function createCommitRaw(
101101 commitIdx : number ,
102102 commitData : ReturnType < typeof extractCommitData > ,
103103 parsedRefs : ParsedRefs ,
104- parsedMessage : ReturnType < typeof parseMessageAndDiffStats >
104+ parsedMessage : ReturnType < typeof extractMessageAndDiffStats >
105105) : CommitRaw {
106106 const { id, parents, authorName, authorEmail, authorDate, committerName, committerEmail, committerDate } = commitData ;
107107 const { branches, tags } = parsedRefs ;
@@ -135,8 +135,8 @@ export default function getCommitRaws(log: string): CommitRaw[] {
135135 const commits = splitLogIntoCommits ( log ) ;
136136 return commits . map ( ( commit , idx ) => {
137137 const commitData = extractCommitData ( commit ) ;
138- const parsedRefs = parseRefsData ( commitData . refs ) ;
139- const parsedMessage = parseMessageAndDiffStats ( commitData . messageAndDiffStats ) ;
138+ const parsedRefs = extractBranchesAndTags ( commitData . refs ) ;
139+ const parsedMessage = extractMessageAndDiffStats ( commitData . messageAndDiffStats ) ;
140140 return createCommitRaw ( idx , commitData , parsedRefs , parsedMessage ) ;
141141 } ) ;
142142}
0 commit comments