Skip to content

Commit

Permalink
Merge pull request src-d#468 from se7entyse7en/fix-comments-count
Browse files Browse the repository at this point in the history
Fixes comments count in log message
  • Loading branch information
se7entyse7en authored Jan 15, 2019
2 parents ecac376 + 6c88cf0 commit e24eda9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
10 changes: 10 additions & 0 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
34 changes: 34 additions & 0 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion cmd/server-test/multi_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
})
}
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e24eda9

Please sign in to comment.