Skip to content

Commit e73a876

Browse files
committed
support patch reading from env var
1 parent 9dd2baf commit e73a876

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

internal/commands/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
228228
}
229229
runner := pkg.SimpleRunner{
230230
Processors: []processors.Processor{
231+
processors.NewPathPrettifier(), // must be before diff processor at least
231232
processors.NewExclude(excludeTotalPattern),
232233
processors.NewCgo(),
233234
processors.NewNolint(fset),
@@ -236,7 +237,6 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
236237
processors.NewMaxPerFileFromLinter(),
237238
processors.NewMaxSameIssues(e.cfg.Issues.MaxSameIssues),
238239
processors.NewMaxFromLinter(e.cfg.Issues.MaxIssuesPerLinter),
239-
processors.NewPathPrettifier(),
240240
},
241241
}
242242

pkg/result/processors/diff.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"io"
77
"io/ioutil"
8+
"os"
9+
"strings"
810

911
"github.com/golangci/golangci-lint/pkg/result"
1012
"github.com/golangci/revgrep"
@@ -14,6 +16,7 @@ type Diff struct {
1416
onlyNew bool
1517
fromRev string
1618
patchFilePath string
19+
patch string
1720
}
1821

1922
var _ Processor = Diff{}
@@ -23,6 +26,7 @@ func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff {
2326
onlyNew: onlyNew,
2427
fromRev: fromRev,
2528
patchFilePath: patchFilePath,
29+
patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"),
2630
}
2731
}
2832

@@ -31,7 +35,7 @@ func (p Diff) Name() string {
3135
}
3236

3337
func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
34-
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" { // no need to work
38+
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" { // no need to work
3539
return issues, nil
3640
}
3741

@@ -42,7 +46,10 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
4246
return nil, fmt.Errorf("can't read from pathc file %s: %s", p.patchFilePath, err)
4347
}
4448
patchReader = bytes.NewReader(patch)
49+
} else if p.patch != "" {
50+
patchReader = strings.NewReader(p.patch)
4551
}
52+
4653
c := revgrep.Checker{
4754
Patch: patchReader,
4855
RevisionFrom: p.fromRev,

pkg/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue)
145145
newIssues, err := p.Process(issues)
146146
elapsed := time.Since(startedAt)
147147
if elapsed > 50*time.Millisecond {
148-
logrus.Infof("Result processor %s took %s", p.Name(), elapsed)
148+
logrus.Infof("Result processor %s took %s and transformed %d -> %d issues",
149+
p.Name(), elapsed, len(issues), len(newIssues))
149150
}
150151
if err != nil {
151152
logrus.Warnf("Can't process result by %s processor: %s", p.Name(), err)

0 commit comments

Comments
 (0)