@@ -27,6 +27,7 @@ import (
2727 "github.com/LF-Engineering/insights-datasource-shared/cache"
2828 elastic "github.com/LF-Engineering/insights-datasource-shared/elastic"
2929 logger "github.com/LF-Engineering/insights-datasource-shared/ingestjob"
30+ "github.com/LF-Engineering/insights-datasource-shared/report"
3031 "github.com/LF-Engineering/lfx-event-schema/service"
3132 "github.com/LF-Engineering/lfx-event-schema/service/insights"
3233 "github.com/LF-Engineering/lfx-event-schema/service/insights/git"
@@ -591,6 +592,7 @@ type DSGit struct {
591592 log * logrus.Entry
592593 cacheProvider cache.Manager
593594 endpoint string
595+ reportProvider * report.Manager
594596}
595597
596598// PublisherPushEvents - this is a fake function to test publisher locally
@@ -1819,6 +1821,23 @@ func (j *DSGit) GitEnrichItems(ctx *shared.Ctx, thrN int, items []interface{}, d
18191821 if err != nil {
18201822 return
18211823 }
1824+
1825+ // write report data
1826+ rData := new (ReportData )
1827+ rData .NewCommits = int64 (len (data ))
1828+ rData .URL = j .URL
1829+ rData .Date = time .Now ().UnixNano ()
1830+
1831+ b , err := jsoniter .Marshal (rData )
1832+ if err != nil {
1833+ return
1834+ }
1835+
1836+ err = j .reportProvider .UpdateFileByKey (fmt .Sprintf ("%+v-%+v.json" , j .endpoint , time .Now ().Unix ()), b )
1837+ if err != nil {
1838+ return
1839+ }
1840+
18221841 }
18231842 }
18241843 if final {
@@ -2723,6 +2742,7 @@ func main() {
27232742 shared .SetLogLoggerError (false )
27242743 shared .AddLogger (& git .Logger , GitDataSource , logger .Internal , []map [string ]string {{"REPO_URL" : git .URL , "ProjectSlug" : ctx .Project }})
27252744 git .AddCacheProvider ()
2745+ git .AddReportProvider ()
27262746 if os .Getenv ("SPAN" ) != "" {
27272747 tracer .Start (tracer .WithGlobalTag ("connector" , "git" ))
27282748 defer tracer .Stop ()
@@ -2788,6 +2808,13 @@ func (j *DSGit) AddCacheProvider() {
27882808 j .endpoint = strings .ReplaceAll (strings .TrimPrefix (strings .TrimPrefix (strings .TrimPrefix (j .URL , "https://" ), "git://" ), "http://" ), "/" , "-" )
27892809}
27902810
2811+ // AddReportProvider - adds report provider
2812+ func (j * DSGit ) AddReportProvider () {
2813+ reportProvider := report .NewManager (os .Getenv ("STAGE" ))
2814+ j .reportProvider = reportProvider
2815+ j .endpoint = strings .ReplaceAll (strings .TrimPrefix (strings .TrimPrefix (strings .TrimPrefix (j .URL , "https://" ), "git://" ), "http://" ), "/" , "-" )
2816+ }
2817+
27912818func (j * DSGit ) createCacheFile (cache []CommitCache , path string ) error {
27922819 for _ , comm := range cache {
27932820 comm .FileLocation = path
@@ -2901,3 +2928,15 @@ type CommitCache struct {
29012928 Orphaned bool `json:"orphaned"`
29022929 FromDL bool `json:"from_dl"`
29032930}
2931+
2932+ // ReportData schema
2933+ type ReportData struct {
2934+ ID string `json:"id"`
2935+ SfdcID string `json:"sfdc_id"`
2936+ ProjectName string `json:"project_name"`
2937+ URL string `json:"url"`
2938+ NewCommits int64 `json:"new_commits"`
2939+ Date int64 `json:"date"`
2940+ SyncStatus string `json:"sync_status"`
2941+ OrphanedCommits int64 `json:"orphaned_commits"`
2942+ }
0 commit comments