github.com/developest/gtm-core@v1.0.4-0.20220111132249-cc80a3372c3f/report/summary.go (about)

     1  // Copyright 2016 Michael Schenk. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package report
     6  
     7  type commitSummaryLine struct {
     8  	StartGroup bool
     9  	EndGroup   bool
    10  	CommitLine bool
    11  	Date       string
    12  	Subject    string
    13  	Project    string
    14  	Total      int
    15  }
    16  
    17  type commitSummaryBuilder struct {
    18  }
    19  
    20  func (c commitSummaryBuilder) Build(notes commitNoteDetails) []commitSummaryLine {
    21  	total := 0
    22  	lines := []commitSummaryLine{}
    23  	for idx, n := range notes {
    24  		if idx == 0 || notes[idx].Date != notes[idx-1].Date {
    25  			if idx != 0 {
    26  				lines = append(lines, commitSummaryLine{EndGroup: true, Total: total})
    27  			}
    28  			total = 0
    29  			lines = append(lines, commitSummaryLine{StartGroup: true, Date: n.Date})
    30  		}
    31  		lines = append(lines, commitSummaryLine{CommitLine: true, Subject: n.Subject, Project: n.Project, Total: n.Note.Total()})
    32  		total += n.Note.Total()
    33  	}
    34  	lines = append(lines, commitSummaryLine{EndGroup: true, Total: total})
    35  	return lines
    36  }