Skip to content

Commit 5a33821

Browse files
committed
temp commit
1 parent dfe91e9 commit 5a33821

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

cli/cmd/digger/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func PreRun(cmd *cobra.Command, args []string) {
9393
//PolicyChecker = policy.NewPolicyChecker(hostName, orgName, token)
9494

9595
if os.Getenv("REPORTING_STRATEGY") == "comments_per_run" || os.Getenv("ACCUMULATE_PLANS") == "true" {
96-
ReportStrategy = &reporting.CommentPerRunStrategy{
96+
ReportStrategy = &reporting.SingleCommentStrategy{
9797
TimeOfRun: time.Now(),
9898
}
9999
} else {

ee/cli/cmd/digger/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func PreRun(cmd *cobra.Command, args []string) {
8787
BackendApi = NewBackendApi(hostName, token)
8888

8989
if os.Getenv("REPORTING_STRATEGY") == "comments_per_run" || os.Getenv("ACCUMULATE_PLANS") == "true" {
90-
ReportStrategy = &reporting.CommentPerRunStrategy{
90+
ReportStrategy = &reporting.SingleCommentStrategy{
9191
TimeOfRun: time.Now(),
9292
}
9393
} else {

libs/comment_utils/reporting/reporting.go

+31-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type CiReporter struct {
1717
}
1818

1919
func (ciReporter CiReporter) Report(report string, reportFormatting func(report string) string) error {
20-
_, _, err := ciReporter.ReportStrategy.Report(ciReporter.CiService, ciReporter.PrNumber, report, reportFormatting, ciReporter.SupportsMarkdown())
20+
_, _, err := ciReporter.ReportStrategy.Report("", ciReporter.CiService, ciReporter.PrNumber, report, reportFormatting, ciReporter.SupportsMarkdown())
2121
return err
2222
}
2323

@@ -53,16 +53,30 @@ func (reporter StdOutReporter) Suppress() error {
5353
}
5454

5555
type ReportStrategy interface {
56-
Report(ciService ci.PullRequestService, PrNumber int, report string, reportFormatter func(report string) string, supportsCollapsibleComment bool) (commentId string, commentUrl string, error error)
57-
Flush() (string, string, error)
56+
Report(projectName string, report string, reportFormatter func(report string) string) (error error)
57+
Flush(ciService ci.PullRequestService, PrNumber int, supportsCollapsibleComment bool) (commentId string, commentUrl string, error error)
5858
}
5959

60-
type CommentPerRunStrategy struct {
61-
Title string
62-
TimeOfRun time.Time
60+
type ReportFormat struct {
61+
ReportTitle string
62+
ReportFormatter func(report string) string
6363
}
6464

65-
func (strategy CommentPerRunStrategy) Report(ciService ci.PullRequestService, PrNumber int, report string, reportFormatter func(report string) string, supportsCollapsibleComment bool) (string, string, error) {
65+
type SingleCommentStrategy struct {
66+
Title string
67+
TimeOfRun time.Time
68+
Formatters map[string]ReportFormat
69+
}
70+
71+
func (strategy SingleCommentStrategy) Report(projectName string, report string, reportFormatter func(report string) string, supportsCollapsibleComment bool) error {
72+
strategy.Formatters[projectName] = ReportFormat{
73+
ReportTitle: report,
74+
ReportFormatter: reportFormatter,
75+
}
76+
return nil
77+
}
78+
79+
func (strategy SingleCommentStrategy) Flush(ciService ci.PullRequestService, PrNumber int, supportsCollapsibleComment bool) (string, string, error) {
6680
comments, err := ciService.GetComments(PrNumber)
6781
if err != nil {
6882
return "", "", fmt.Errorf("error getting comments: %v", err)
@@ -76,9 +90,6 @@ func (strategy CommentPerRunStrategy) Report(ciService ci.PullRequestService, Pr
7690
}
7791
commentId, commentUrl, err := upsertComment(ciService, PrNumber, report, reportFormatter, comments, reportTitle, supportsCollapsibleComment)
7892
return commentId, commentUrl, err
79-
}
80-
81-
func (s CommentPerRunStrategy) Flush() (string, string, error) {
8293
return "", "", nil
8394
}
8495

@@ -132,13 +143,18 @@ func upsertComment(ciService ci.PullRequestService, PrNumber int, report string,
132143
return fmt.Sprintf("%v", commentIdForThisRun), commentUrl, nil
133144
}
134145

135-
type MultipleCommentsStrategy struct{}
146+
type MultipleCommentsStrategy struct {
147+
Formatters map[string]ReportFormat
148+
}
136149

137-
func (strategy MultipleCommentsStrategy) Report(ciService ci.PullRequestService, PrNumber int, report string, reportFormatter func(report string) string, supportsCollapsibleComment bool) (string, string, error) {
138-
_, err := ciService.PublishComment(PrNumber, reportFormatter(report))
139-
return "", "", err
150+
func (strategy MultipleCommentsStrategy) Report(projectName string, report string, reportFormatter func(report string) string) error {
151+
strategy.Formatters[projectName] = ReportFormat{
152+
ReportTitle: report,
153+
ReportFormatter: reportFormatter,
154+
}
155+
return nil
140156
}
141157

142-
func (s MultipleCommentsStrategy) Flush() (string, string, error) {
158+
func (strategy MultipleCommentsStrategy) Flush(ciService ci.PullRequestService, PrNumber int, supportsCollapsibleComment bool) (string, string, error) {
143159
return "", "", nil
144160
}

libs/comment_utils/reporting/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func PostInitialSourceComments(ghService ci.PullRequestService, prNumber int, im
2828
reporter := CiReporter{
2929
PrNumber: prNumber,
3030
CiService: ghService,
31-
ReportStrategy: CommentPerRunStrategy{fmt.Sprintf("Report for location: %v", location), time.Now()},
31+
ReportStrategy: SingleCommentStrategy{fmt.Sprintf("Report for location: %v", location), time.Now()},
3232
}
3333
err := reporter.Report("Comment Reporter", func(report string) string { return "" })
3434
if err != nil {

libs/spec/providers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r ReporterProvider) GetReporter(title string, reporterSpec ReporterSpec, c
117117
getStrategy := func(strategy string) reporting.ReportStrategy {
118118
switch reporterSpec.ReportingStrategy {
119119
case "comments_per_run":
120-
return reporting.CommentPerRunStrategy{
120+
return reporting.SingleCommentStrategy{
121121
Title: title,
122122
TimeOfRun: time.Now(),
123123
}

0 commit comments

Comments
 (0)