diff --git a/analysis.go b/analysis.go index d5461071..7f8fc5fa 100644 --- a/analysis.go +++ b/analysis.go @@ -79,3 +79,13 @@ func (g AnalyzerCommentsGroups) Filter(fn CommentsFilterFn) ([]AnalyzerComments, return result, nil } + +// Count returns the total number of comments +func (g AnalyzerCommentsGroups) Count() int { + count := 0 + for _, group := range g { + count += len(group.Comments) + } + + return count +} diff --git a/analysis_test.go b/analysis_test.go index 7d1e5535..3d757af3 100644 --- a/analysis_test.go +++ b/analysis_test.go @@ -46,3 +46,37 @@ func TestAnalyzerCommentsGroupsFilter(t *testing.T) { assert.Equal(e, err) } + +func TestAnalyzerCommentsGroupsCount(t *testing.T) { + assert := assert.New(t) + + g := AnalyzerCommentsGroups{} + + assert.Equal(g.Count(), 0) + + g = AnalyzerCommentsGroups{ + { + Comments: []*Comment{ + {Text: "some text"}, + }, + }, + } + + assert.Equal(g.Count(), 1) + + g = AnalyzerCommentsGroups{ + { + Comments: []*Comment{ + {Text: "some text"}, + }, + }, + { + Comments: []*Comment{ + {Text: "some text"}, + {Text: "some text"}, + }, + }, + } + + assert.Equal(g.Count(), 3) +} diff --git a/cmd/server-test/multi_analyzer_test.go b/cmd/server-test/multi_analyzer_test.go index d2e9f989..06a8edf6 100644 --- a/cmd/server-test/multi_analyzer_test.go +++ b/cmd/server-test/multi_analyzer_test.go @@ -40,9 +40,11 @@ func (suite *MultiDummyIntegrationSuite) TestSuccessReview() { suite.GrepAll(suite.r, []string{ "processing pull request", - "posting analysis", + `msg="posting analysis" app=lookoutd comments=4`, `{"analyzer-name":"Dummy1","file":"another.go","line":3,"text":"This line exceeded`, + `{"analyzer-name":"Dummy1","file":"another.go","line":3,"text":"This line exceeded 120 chars."}`, `{"analyzer-name":"Dummy2","file":"another.go","line":3,"text":"This line exceeded`, + `{"analyzer-name":"Dummy2","file":"another.go","line":3,"text":"This line exceeded 120 chars."}`, `status=success`, }) } diff --git a/server/server.go b/server/server.go index 44624eb7..32611eec 100644 --- a/server/server.go +++ b/server/server.go @@ -409,7 +409,7 @@ func (s *Server) post(ctx context.Context, e lookout.Event, comments lookout.Ana } ctxlog.Get(ctx).With(log.Fields{ - "comments": len(comments), + "comments": comments.Count(), }).Infof("posting analysis") if err := s.poster.Post(ctx, e, comments, safe); err != nil {