/
runner.go
79 lines (63 loc) · 1.84 KB
/
runner.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package extract
import (
"context"
"time"
"github.com/sirupsen/logrus"
"golang.org/x/tools/go/packages"
"github.com/vorlif/spreak/xspreak/internal/config"
"github.com/vorlif/spreak/xspreak/internal/extract/extractors"
"github.com/vorlif/spreak/xspreak/internal/result"
"github.com/vorlif/spreak/xspreak/internal/result/processors"
"github.com/vorlif/spreak/xspreak/internal/util"
)
type Runner struct {
Processors []processors.Processor
Log *logrus.Entry
}
func NewRunner(cfg *config.Config, pkgs map[string]*packages.Package) (*Runner, error) {
p := []processors.Processor{
processors.NewSkipEmptyMsgID(),
}
if !cfg.ExtractErrors {
p = append(p, processors.NewSkipErrors())
}
p = append(p,
processors.NewCommentCleaner(cfg),
processors.NewSkipIgnore(),
processors.BuildTranslations(cfg))
ret := &Runner{
Processors: p,
Log: logrus.WithField("service", "Runner"),
}
return ret, nil
}
func (r Runner) Run(ctx context.Context, extractCtx *extractors.Context, extractors []extractors.Extractor) ([]result.Issue, error) {
defer util.TrackTime(time.Now(), "Extracting the issues")
var issues []result.Issue
for _, extr := range extractors {
extractedIssues, err := extr.Run(ctx, extractCtx)
if err != nil {
r.Log.Warnf("Can't run extractor %s: %v", extr.Name(), err)
} else {
issues = append(issues, extractedIssues...)
}
}
return r.processIssues(issues), nil
}
func (r *Runner) processIssues(issues []result.Issue) []result.Issue {
defer util.TrackTime(time.Now(), "Process the issues")
for _, p := range r.Processors {
var newIssues []result.Issue
var err error
newIssues, err = p.Process(issues)
if err != nil {
r.Log.Warnf("Can't process result by %s processor: %s", p.Name(), err)
} else {
issues = newIssues
}
if issues == nil {
issues = []result.Issue{}
}
}
return issues
}