-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathposter.go
More file actions
55 lines (44 loc) · 1.11 KB
/
poster.go
File metadata and controls
55 lines (44 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package json
import (
"context"
"encoding/json"
"io"
"github.com/src-d/lookout"
"github.com/src-d/lookout/util/ctxlog"
"gopkg.in/src-d/go-log.v1"
)
// Poster prints json comments to stdout
type Poster struct {
writer io.Writer
enc *json.Encoder
}
var _ lookout.Poster = &Poster{}
// NewPoster creates a new json poster for stdout
func NewPoster(w io.Writer) *Poster {
return &Poster{
writer: w,
enc: json.NewEncoder(w),
}
}
// Post prints json comments to stdout
func (p *Poster) Post(ctx context.Context, e lookout.Event,
aCommentsList []lookout.AnalyzerComments) error {
for _, a := range aCommentsList {
for _, c := range a.Comments {
if err := p.enc.Encode(commentToPrint{AnalyzerName: a.Config.Name, Comment: c}); err != nil {
return err
}
}
}
return nil
}
// Status prints the new status to the log
func (p *Poster) Status(ctx context.Context, e lookout.Event,
status lookout.AnalysisStatus) error {
ctxlog.Get(ctx).With(log.Fields{"status": status}).Infof("New status")
return nil
}
type commentToPrint struct {
AnalyzerName string `json:"analyzer-name"`
*lookout.Comment
}