@@ -17,7 +17,7 @@ type CiReporter struct {
17
17
}
18
18
19
19
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 ())
21
21
return err
22
22
}
23
23
@@ -53,16 +53,30 @@ func (reporter StdOutReporter) Suppress() error {
53
53
}
54
54
55
55
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 )
58
58
}
59
59
60
- type CommentPerRunStrategy struct {
61
- Title string
62
- TimeOfRun time. Time
60
+ type ReportFormat struct {
61
+ ReportTitle string
62
+ ReportFormatter func ( report string ) string
63
63
}
64
64
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 ) {
66
80
comments , err := ciService .GetComments (PrNumber )
67
81
if err != nil {
68
82
return "" , "" , fmt .Errorf ("error getting comments: %v" , err )
@@ -76,9 +90,6 @@ func (strategy CommentPerRunStrategy) Report(ciService ci.PullRequestService, Pr
76
90
}
77
91
commentId , commentUrl , err := upsertComment (ciService , PrNumber , report , reportFormatter , comments , reportTitle , supportsCollapsibleComment )
78
92
return commentId , commentUrl , err
79
- }
80
-
81
- func (s CommentPerRunStrategy ) Flush () (string , string , error ) {
82
93
return "" , "" , nil
83
94
}
84
95
@@ -132,13 +143,18 @@ func upsertComment(ciService ci.PullRequestService, PrNumber int, report string,
132
143
return fmt .Sprintf ("%v" , commentIdForThisRun ), commentUrl , nil
133
144
}
134
145
135
- type MultipleCommentsStrategy struct {}
146
+ type MultipleCommentsStrategy struct {
147
+ Formatters map [string ]ReportFormat
148
+ }
136
149
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
140
156
}
141
157
142
- func (s MultipleCommentsStrategy ) Flush () (string , string , error ) {
158
+ func (strategy MultipleCommentsStrategy ) Flush (ciService ci. PullRequestService , PrNumber int , supportsCollapsibleComment bool ) (string , string , error ) {
143
159
return "" , "" , nil
144
160
}
0 commit comments