@@ -33,57 +33,6 @@ func (ciReporter CiReporter) SupportsMarkdown() bool {
3333 return ciReporter .IsSupportMarkdown
3434}
3535
36- type CiReporterLazy struct {
37- CiReporter CiReporter
38- isSuppressed bool
39- reports []string
40- formatters []func (report string ) string
41- }
42-
43- func NewCiReporterLazy (ciReporter CiReporter ) * CiReporterLazy {
44- return & CiReporterLazy {
45- CiReporter : ciReporter ,
46- isSuppressed : false ,
47- reports : []string {},
48- formatters : []func (report string ) string {},
49- }
50- }
51-
52- func (lazyReporter * CiReporterLazy ) Report (report string , reportFormatting func (report string ) string ) (string , string , error ) {
53- lazyReporter .reports = append (lazyReporter .reports , report )
54- lazyReporter .formatters = append (lazyReporter .formatters , reportFormatting )
55- return "" , "" , nil
56- }
57-
58- func (lazyReporter * CiReporterLazy ) Flush () (string , string , error ) {
59- if lazyReporter .isSuppressed {
60- log .Printf ("Reporter is suprresed, ignoring messages ..." )
61- return "" , "" , nil
62- }
63- var commentId , commentUrl string
64- for i , _ := range lazyReporter .formatters {
65- var err error
66- commentId , commentUrl , err = lazyReporter .CiReporter .ReportStrategy .Report (lazyReporter .CiReporter .CiService , lazyReporter .CiReporter .PrNumber , lazyReporter .reports [i ], lazyReporter .formatters [i ], lazyReporter .SupportsMarkdown ())
67- if err != nil {
68- log .Printf ("failed to report strategy: " )
69- return "" , "" , err
70- }
71- }
72- // clear the buffers
73- lazyReporter .formatters = []func (comment string ) string {}
74- lazyReporter .reports = []string {}
75- return commentId , commentUrl , nil
76- }
77-
78- func (lazyReporter * CiReporterLazy ) Suppress () error {
79- lazyReporter .isSuppressed = true
80- return nil
81- }
82-
83- func (lazyReporter * CiReporterLazy ) SupportsMarkdown () bool {
84- return lazyReporter .CiReporter .IsSupportMarkdown
85- }
86-
8736type StdOutReporter struct {}
8837
8938func (reporter StdOutReporter ) Report (report string , reportFormatting func (report string ) string ) (string , string , error ) {
@@ -107,42 +56,6 @@ type ReportStrategy interface {
10756 Report (ciService ci.PullRequestService , PrNumber int , report string , reportFormatter func (report string ) string , supportsCollapsibleComment bool ) (commentId string , commentUrl string , error error )
10857}
10958
110- type AlwaysSameCommentStrategy struct {
111- Title string
112- CommentId string
113- TimeOfRun time.Time
114- }
115-
116- func (strategy AlwaysSameCommentStrategy ) Report (ciService ci.PullRequestService , PrNumber int , report string , reportFormatter func (report string ) string , supportsCollapsibleComment bool ) (string , string , error ) {
117- comments , err := ciService .GetComments (PrNumber )
118- if err != nil {
119- return "" , "" , fmt .Errorf ("error getting comments: %v" , err )
120- }
121-
122- var commentBody * string
123- var commentUrl string
124- for _ , comment := range comments {
125- if comment .Id == strategy .CommentId {
126- commentBody = comment .Body
127- commentUrl = comment .Url
128- }
129- }
130-
131- var reportTitle string
132- if strategy .Title != "" {
133- reportTitle = strategy .Title + " " + strategy .TimeOfRun .Format ("2006-01-02 15:04:05 (MST)" )
134- } else {
135- reportTitle = "Digger run report at " + strategy .TimeOfRun .Format ("2006-01-02 15:04:05 (MST)" )
136- }
137-
138- err = appendToExistingComment (ciService , PrNumber , * commentBody , report , reportTitle , strategy .CommentId , supportsCollapsibleComment )
139- if err != nil {
140- return "" , "" , fmt .Errorf ("error while adding to existing comment: %v" , err )
141- }
142-
143- return strategy .CommentId , commentUrl , err
144- }
145-
14659type CommentPerRunStrategy struct {
14760 Title string
14861 TimeOfRun time.Time
@@ -192,39 +105,26 @@ func upsertComment(ciService ci.PullRequestService, PrNumber int, report string,
192105 return fmt .Sprintf ("%v" , comment .Id ), comment .Url , nil
193106 }
194107
195- err := appendToExistingComment (ciService , PrNumber , commentBody , report , reportTitle , commentIdForThisRun , supportsCollapsible )
196- if err != nil {
197- return "" , "" , err
198- }
199-
200- return fmt .Sprintf ("%v" , commentIdForThisRun ), commentUrl , nil
201-
202- }
203-
204- func appendToExistingComment (ciService ci.PullRequestService , prNumber int , existingCommentBody string , reportToAppend string , reportTitle string , commentId string , supportsCollapsible bool ) error {
205-
206108 // strip first and last lines
207- lines := strings .Split (existingCommentBody , "\n " )
208- //if len(lines) > 1 {
209- // lines = lines[1 : len(lines)-1]
210- //}
211- existingCommentBody = strings .Join (lines , "\n " )
109+ lines := strings .Split (commentBody , "\n " )
110+ lines = lines [1 : len (lines )- 1 ]
111+ commentBody = strings .Join (lines , "\n " )
212112
213- existingCommentBody = existingCommentBody + "\n \n " + reportToAppend + "\n "
113+ commentBody = commentBody + "\n \n " + report + "\n "
214114
215115 var completeComment string
216116 if ! supportsCollapsible {
217- completeComment = utils .AsComment (reportTitle )(existingCommentBody )
117+ completeComment = utils .AsComment (reportTitle )(commentBody )
218118 } else {
219- completeComment = utils .AsCollapsibleComment (reportTitle , false )(existingCommentBody )
119+ completeComment = utils .AsCollapsibleComment (reportTitle , false )(commentBody )
220120 }
221121
222- err := ciService .EditComment (prNumber , commentId , completeComment )
122+ err := ciService .EditComment (PrNumber , commentIdForThisRun , completeComment )
223123
224124 if err != nil {
225- return fmt .Errorf ("error editing comment: %v" , err )
125+ return "" , "" , fmt .Errorf ("error editing comment: %v" , err )
226126 }
227- return nil
127+ return fmt . Sprintf ( "%v" , commentIdForThisRun ), commentUrl , nil
228128}
229129
230130type LatestRunCommentStrategy struct {
0 commit comments