@@ -524,7 +524,7 @@ var (
524524
525525// Publisher - for streaming data to Kinesis
526526type Publisher interface {
527- PushEvents (action , source , eventType , subEventType , env string , data []interface {}) (string , error )
527+ PushEvents (action , source , eventType , subEventType , env string , data []interface {}, endpoint string ) (string , error )
528528}
529529
530530// RawPLS - programming language summary (all fields as strings)
@@ -946,7 +946,8 @@ func (j *DSGit) EnrichItem(ctx *shared.Ctx, item map[string]interface{}) (rich m
946946 err = fmt .Errorf ("cannot parse author date from %v" , iAuthorDate )
947947 return
948948 }
949-
949+ clocCount , _ := shared .Dig (commit , []string {"cloc_count" }, true , false )
950+ rich ["cloc_count" ] = clocCount
950951 authorLocation := time .FixedZone (fmt .Sprintf ("UTC%v" , authorTz ), int (authorTz )* 60 * 60 )
951952 authorLocalDate := time .Date (authorDate .Year (), authorDate .Month (), authorDate .Day (), authorDate .Hour (), authorDate .Minute (), authorDate .Second (), authorDate .Nanosecond (), authorLocation )
952953 rich ["orphaned" ] = false
@@ -1342,6 +1343,10 @@ func (j *DSGit) GetModelData(ctx *shared.Ctx, docs []interface{}) []git.CommitCr
13421343 for _ , value := range fileCache {
13431344 commit .Files = append (commit .Files , * value )
13441345 }
1346+ if len (commit .Files ) > 0 {
1347+ clocCount , _ := doc ["cloc_count" ].(int )
1348+ commit .Files [len (commit .Files )- 1 ].ActualLinesOfCode = clocCount
1349+ }
13451350 }
13461351 commit .MergeCommit = len (fileAry ) == 0
13471352 // Event
@@ -1803,7 +1808,7 @@ func (j *DSGit) GitEnrichItems(ctx *shared.Ctx, thrN int, items []interface{}, d
18031808 }
18041809 path := ""
18051810 if len (formattedData ) > 0 {
1806- path , err = j .Publisher .PushEvents (CommitCreated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData )
1811+ path , err = j .Publisher .PushEvents (CommitCreated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData , j . endpoint )
18071812 if err != nil {
18081813 j .log .WithFields (logrus.Fields {"operation" : "GitEnrichItems" }).Errorf ("Error: %+v" , err )
18091814 return
@@ -2561,6 +2566,20 @@ func (j *DSGit) Sync(ctx *shared.Ctx) (err error) {
25612566 return
25622567 }
25632568 processCommit := func (c chan error , commit map [string ]interface {}) (wch chan error , e error ) {
2569+ sha , _ := commit ["commit" ].(string )
2570+ cmdLine := []string {"cloc" , "commit" , sha , "--json" }
2571+ sout , serr , err := shared .ExecCommand (ctx , cmdLine , j .GitPath , GitDefaultEnv )
2572+ if err != nil {
2573+ j .log .WithFields (logrus.Fields {"operation" : "Sync" }).Errorf ("error executing command: %v, error: %v, output: %s, output error: %s" , cmdLine , err , sout , serr )
2574+ return
2575+ }
2576+ r := make (map [string ]clocResult )
2577+ err = jsoniter .Unmarshal ([]byte (sout ), & r )
2578+ if err != nil {
2579+ j .log .WithFields (logrus.Fields {"operation" : "Sync" }).Errorf ("error unmarshall: %v, error: %v" , sout , err )
2580+ return
2581+ }
2582+ commit ["cloc_count" ] = r ["SUM" ].Code
25642583 defer func () {
25652584 if c != nil {
25662585 c <- e
@@ -2924,7 +2943,7 @@ func (j *DSGit) handleDataLakeOrphans() {
29242943 }
29252944
29262945 if len (formattedData ) > 0 {
2927- path , err := j .Publisher .PushEvents (CommitUpdated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData )
2946+ path , err := j .Publisher .PushEvents (CommitUpdated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData , j . endpoint )
29282947 if err != nil {
29292948 j .log .WithFields (logrus.Fields {"operation" : "handleDataLakeOrphans" }).Errorf ("error pushing data lake orphand commits: %+v" , err )
29302949 return
@@ -2969,3 +2988,10 @@ type ReportData struct {
29692988 SyncStatus string `json:"sync_status"`
29702989 OrphanedCommits int64 `json:"orphaned_commits"`
29712990}
2991+
2992+ type clocResult struct {
2993+ Code int `json:"code"`
2994+ Blank int `json:"blank"`
2995+ Comment int `json:"comment"`
2996+ NumberOfFiles int `json:"nFiles"`
2997+ }
0 commit comments