github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/comment_utils/reporting/utils.go (about) 1 package reporting 2 3 import ( 4 "fmt" 5 dg_configuration "github.com/diggerhq/digger/libs/digger_config" 6 dg_github "github.com/diggerhq/digger/libs/orchestrator/github" 7 "log" 8 "time" 9 ) 10 11 type SourceDetails struct { 12 SourceLocation string `json:"source_location"` 13 CommentId string `json:"comment_id"` 14 Projects []string `json:"projects"` 15 } 16 17 func PostInitialSourceComments(ghService *dg_github.GithubService, prNumber int, impactedProjectsSourceMapping map[string]dg_configuration.ProjectToSourceMapping) ([]SourceDetails, error) { 18 19 locations := make(map[string][]string) 20 sourceDetails := make([]SourceDetails, 0) 21 22 for projectName, sourceMapping := range impactedProjectsSourceMapping { 23 for _, location := range sourceMapping.ImpactingLocations { 24 locations[location] = append(locations[location], projectName) 25 } 26 } 27 for location, projects := range locations { 28 reporter := CiReporter{ 29 PrNumber: prNumber, 30 CiService: ghService, 31 ReportStrategy: CommentPerRunStrategy{fmt.Sprintf("Report for location: %v", location), time.Now()}, 32 } 33 commentId, _, err := reporter.Report("Comment Reporter", func(report string) string { return "" }) 34 if err != nil { 35 log.Printf("Error reporting source module comment: %v", err) 36 return nil, fmt.Errorf("error reporting source module comment: %v", err) 37 } 38 39 sourceDetails = append(sourceDetails, SourceDetails{location, commentId, projects}) 40 } 41 42 return sourceDetails, nil 43 }