@@ -2,6 +2,7 @@ package main
22
33import (
44 "bufio"
5+ "encoding/json"
56 "flag"
67 "fmt"
78 "io"
@@ -1752,13 +1753,33 @@ func (j *DSGit) GitEnrichItems(ctx *shared.Ctx, thrN int, items []interface{}, d
17521753 data := j .GetModelData (ctx , * docs )
17531754 if j .Publisher != nil {
17541755 formattedData := make ([]interface {}, 0 )
1756+ vals := make ([]map [string ]interface {}, 0 )
17551757 for _ , d := range data {
1756- formattedData = append (formattedData , d )
1758+ isCreated , err := j .cacheProvider .IsKeyCreated (j .endpoint , d .Payload .SHA )
1759+ if err != nil {
1760+ j .log .WithFields (logrus.Fields {"operation" : "GitEnrichItems" }).Errorf ("error creating cache for commit %s, error %v" , d .Payload .SHA , err )
1761+ continue
1762+ }
1763+ if ! isCreated {
1764+ formattedData = append (formattedData , d )
1765+ b , err := json .Marshal (d )
1766+ if err != nil {
1767+ j .log .WithFields (logrus.Fields {"operation" : "GitEnrichItems" }).Errorf ("error marshall data for commit %s, error %v" , d .Payload .SHA , err )
1768+ continue
1769+ }
1770+ vals = append (vals , map [string ]interface {}{
1771+ "id" : d .Payload .ID ,
1772+ "data" : b ,
1773+ })
1774+ }
17571775 }
1758- err = j .Publisher .PushEvents (CommitCreated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData )
1759- if err != nil {
1760- j .log .WithFields (logrus.Fields {"operation" : "GitEnrichItems" }).Errorf ("Error: %+v" , err )
1761- return
1776+ err = j .cacheProvider .Create (j .endpoint , vals )
1777+ if len (formattedData ) > 0 {
1778+ err = j .Publisher .PushEvents (CommitCreated , "insights" , GitDataSource , "commits" , os .Getenv ("STAGE" ), formattedData )
1779+ if err != nil {
1780+ j .log .WithFields (logrus.Fields {"operation" : "GitEnrichItems" }).Errorf ("Error: %+v" , err )
1781+ return
1782+ }
17621783 }
17631784 } else {
17641785 var jsonBytes []byte
@@ -2657,5 +2678,5 @@ func (j *DSGit) initStructuredLogger(ctx *shared.Ctx) {
26572678func (j * DSGit ) AddCacheProvider () {
26582679 cacheProvider := cache .NewManager (GitDataSource , os .Getenv ("STAGE" ))
26592680 j .cacheProvider = * cacheProvider
2660- j .endpoint = strings .ReplaceAll (strings .TrimPrefix (strings .TrimPrefix (j .URL , "https://" ), "http://" ), "/" , "-" )
2681+ j .endpoint = strings .ReplaceAll (strings .TrimPrefix (strings .TrimPrefix (strings . TrimPrefix ( j .URL , "https://" ), "git ://" ), "http://" ), "/" , "-" )
26612682}
0 commit comments