Skip to content

Commit

Permalink
Merge branch 'master' into exit-code
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Aug 1, 2024
2 parents aaf8252 + 494e65f commit 3788f0a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 19 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### :sparkles: Release Note <!-- optional -->

### :rocket: Enhancements
- ...
- [#1845](https://github.com/reviewdog/reviewdog/pull/1845) Normalize file path in `related_locations` too.

### :bug: Fixes
- [#1846](https://github.com/reviewdog/reviewdog/issues/1846) Unexpected error
exit code when using `-reporter=github-[pr-]check` with
`-fail-on-error=true`. See the below breaking changes section for more details.

### :rotating_light: (Actually No) Breaking changes
- [#1854](https://github.com/reviewdog/reviewdog/pull/1854) `-fail-on-error`
### :rotating_light: Breaking changes
- [#1858](https://github.com/reviewdog/reviewdog/pull/1858) Remove original_output from rdjson/rdjsonl reporters' output

### :rotating_light: Deprecation Warnings
- [#1854](https://github.com/reviewdog/reviewdog/pull/1854) (Actually No Breaking changes) `-fail-on-error`
flag is deprecated. Use `-fail-level=[none,any,error,warning,info]` flag
instead. You can reproduce the same behavior with `-fail-level=any` for most
reporters (reviewdog will exit with 1 if it find any severity level).
Expand All @@ -26,7 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

`-fail-on-error` is just deprecated and it's not removed yet. Please update
the flag while it's working.

<!-- TODO: update the v0.19.0 release section -->

## [v0.20.1] - 2024-07-10
Expand Down
4 changes: 4 additions & 0 deletions comment_iowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (cw *RDJSONLCommentWriter) Post(_ context.Context, c *Comment) error {
Name: c.ToolName,
}
}
// Remove OriginalOutput. It's used internally and we shouldn't expose it as output.
c.Result.Diagnostic.OriginalOutput = ""
b, err := protojson.MarshalOptions{
UseProtoNames: true,
UseEnumNumbers: false,
Expand Down Expand Up @@ -124,6 +126,8 @@ func (cw *RDJSONCommentWriter) Flush(_ context.Context) error {
Diagnostics: make([]*rdf.Diagnostic, 0, len(cw.comments)),
}
for _, c := range cw.comments {
// Remove OriginalOutput. It's used internally and we shouldn't expose it as output.
c.Result.Diagnostic.OriginalOutput = ""
result.Diagnostics = append(result.Diagnostics, c.Result.Diagnostic)
}
b, err := protojson.MarshalOptions{
Expand Down
10 changes: 6 additions & 4 deletions comment_iowriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ func TestRDJSONLCommentWriter_Post(t *testing.T) {
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
OriginalOutput: "original output",
},
},
ToolName: "tool name",
Expand Down Expand Up @@ -167,8 +168,9 @@ func TestRDJSONCommentWriter_Post(t *testing.T) {
{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
OriginalOutput: "original output",
},
},
ToolName: "tool name",
Expand Down
1 change: 0 additions & 1 deletion filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func FilterCheck(results []*rdf.Diagnostic, diff []*diff.FileDiff, strip int,
for _, result := range results {
check := &FilteredDiagnostic{Diagnostic: result, SourceLines: make(map[int]string)}
loc := result.GetLocation()
loc.Path = pathutil.NormalizePath(loc.GetPath(), cwd, "")
startLine := int(loc.GetRange().GetStart().GetLine())
endLine := int(loc.GetRange().GetEnd().GetLine())
if endLine == 0 {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.7
require (
cloud.google.com/go/compute/metadata v0.5.0
cloud.google.com/go/datastore v1.17.1
code.gitea.io/sdk/gitea v0.18.0
code.gitea.io/sdk/gitea v0.19.0
contrib.go.opencensus.io/exporter/stackdriver v0.13.12
github.com/bradleyfalzon/ghinstallation/v2 v2.11.0
github.com/google/go-cmp v0.6.0
Expand All @@ -22,9 +22,9 @@ require (
github.com/reviewdog/go-bitbucket v0.0.0-20201024094602-708c3f6a7de0
github.com/stretchr/testify v1.9.0
github.com/vvakame/sdlog v1.2.0
github.com/xanzy/go-gitlab v0.106.0
github.com/xanzy/go-gitlab v0.107.0
go.opencensus.io v0.24.0
golang.org/x/build v0.0.0-20240712162709-0b82a206aadf
golang.org/x/build v0.0.0-20240731015247-ede91cf91ea8
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.7.0
google.golang.org/protobuf v1.34.2
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/trace v1.0.0/go.mod h1:4iErSByzxkyHWzzlAj63/Gmjz0NH1ASqhJguHpGcr6A=
cloud.google.com/go/trace v1.10.7 h1:gK8z2BIJQ3KIYGddw9RJLne5Fx0FEXkrEQzPaeEYVvk=
cloud.google.com/go/trace v1.10.7/go.mod h1:qk3eiKmZX0ar2dzIJN/3QhY2PIFh1eqcIdaN5uEjQPM=
code.gitea.io/sdk/gitea v0.18.0 h1:+zZrwVmujIrgobt6wVBWCqITz6bn1aBjnCUHmpZrerI=
code.gitea.io/sdk/gitea v0.18.0/go.mod h1:IG9xZJoltDNeDSW0qiF2Vqx5orMWa7OhVWrjvrd5NpI=
code.gitea.io/sdk/gitea v0.19.0 h1:8I6s1s4RHgzxiPHhOQdgim1RWIRcr0LVMbHBjBFXq4Y=
code.gitea.io/sdk/gitea v0.19.0/go.mod h1:IG9xZJoltDNeDSW0qiF2Vqx5orMWa7OhVWrjvrd5NpI=
contrib.go.opencensus.io/exporter/stackdriver v0.13.12 h1:bjBKzIf7/TAkxd7L2utGaLM78bmUWlCval5K9UeElbY=
contrib.go.opencensus.io/exporter/stackdriver v0.13.12/go.mod h1:mmxnWlrvrFdpiOHOhxBaVi1rkc0WOqhgfknj4Yg0SeQ=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
Expand Down Expand Up @@ -279,8 +279,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vvakame/sdlog v1.2.0 h1:gwZRXZ0EmhJQJN/Do/+PTQigcmFiSqZ07aDjxqGOLT8=
github.com/vvakame/sdlog v1.2.0/go.mod h1:gFYv2g/iR3pJSxkJz0YnkNmhNbXT5R3PzWsfZKGQADY=
github.com/xanzy/go-gitlab v0.106.0 h1:EDfD03K74cIlQo2EducfiupVrip+Oj02bq9ofw5F8sA=
github.com/xanzy/go-gitlab v0.106.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI=
github.com/xanzy/go-gitlab v0.107.0 h1:P2CT9Uy9yN9lJo3FLxpMZ4xj6uWcpnigXsjvqJ6nd2Y=
github.com/xanzy/go-gitlab v0.107.0/go.mod h1:wKNKh3GkYDMOsGmnfuX+ITCmDuSDWFO0G+C4AygL9RY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -308,8 +308,8 @@ go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/build v0.0.0-20240712162709-0b82a206aadf h1:yxXHOnHUeXT9mop6DOYhyBNeVl20sSyKYR6+5YAwLnk=
golang.org/x/build v0.0.0-20240712162709-0b82a206aadf/go.mod h1:YsGhg4JUVUWLzdqU2wCrtpRrOveOql6w56FLDHq/CJ4=
golang.org/x/build v0.0.0-20240731015247-ede91cf91ea8 h1:RnTh6wT7sv6wjo49xAgWQBozAvNnPfNoXJZGUNbR4x0=
golang.org/x/build v0.0.0-20240731015247-ede91cf91ea8/go.mod h1:C12yKxWgJeykUO2lfQINDq2U/JrauqR2Rh/tQeFnU5I=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
18 changes: 18 additions & 0 deletions pathutil/pathutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package pathutil
import (
"path/filepath"
"strings"

"github.com/reviewdog/reviewdog/proto/rdf"
)

// NormalizePath return normalized path with workdir and relative path to
Expand Down Expand Up @@ -42,6 +44,22 @@ func NormalizeDiffPath(diffpath string, strip int) string {
return filepath.ToSlash(filepath.Clean(path))
}

// NormalizePathInResults normalize file path in RDFormat results.
func NormalizePathInResults(results []*rdf.Diagnostic, cwd string) {
for _, result := range results {
normalizeLocation(result.GetLocation(), cwd)
for _, rel := range result.GetRelatedLocations() {
normalizeLocation(rel.GetLocation(), cwd)
}
}
}

func normalizeLocation(loc *rdf.Location, cwd string) {
if loc != nil {
loc.Path = NormalizePath(loc.GetPath(), cwd, "")
}
}

func contains(path, base string) bool {
ps := splitPathList(path)
bs := splitPathList(base)
Expand Down
49 changes: 49 additions & 0 deletions pathutil/pathutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package pathutil

import (
"strings"
"testing"

"github.com/reviewdog/reviewdog/proto/rdf"
)

func TestNormalizePathInResults(t *testing.T) {
cwd := "/path/to/cwd"
results := []*rdf.Diagnostic{
{
Location: &rdf.Location{
Path: cwd + "/" + "sample_1_abs.txt",
},
},
{
Location: &rdf.Location{
Path: "sample_2_rel.txt",
},
},
{
RelatedLocations: []*rdf.RelatedLocation{
{
Location: &rdf.Location{
Path: cwd + "/" + "sample_related_1_abs.txt",
},
},
{
Location: &rdf.Location{
Path: "sample_related_2_rel.txt",
},
},
},
},
}
NormalizePathInResults(results, cwd)
for _, result := range results {
if strings.HasPrefix(result.GetLocation().GetPath(), cwd) {
t.Errorf("path unexpectedly contain prefix: %s", result.GetLocation().GetPath())
}
for _, rel := range result.GetRelatedLocations() {
if strings.HasPrefix(rel.GetLocation().GetPath(), cwd) {
t.Errorf("related locations path unexpectedly contain prefix: %s", rel.GetLocation().GetPath())
}
}
}
}
3 changes: 3 additions & 0 deletions reviewdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/reviewdog/reviewdog/diff"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/parser"
"github.com/reviewdog/reviewdog/pathutil"
"github.com/reviewdog/reviewdog/proto/rdf"
)

Expand Down Expand Up @@ -73,6 +74,8 @@ func (w *Reviewdog) runFromResult(ctx context.Context, results []*rdf.Diagnostic
return err
}

pathutil.NormalizePathInResults(results, wd)

checks := filter.FilterCheck(results, filediffs, strip, wd, w.filterMode)
shouldFail := false

Expand Down
2 changes: 1 addition & 1 deletion service/github/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *PullRequestDiffService) Diff(ctx context.Context) ([]byte, error) {
d, resp, err := p.Cli.PullRequests.GetRaw(ctx, p.Owner, p.Repo, p.PR, opt)
if err != nil {
if resp != nil && p.FallBackToGitCLI && resp.StatusCode == http.StatusNotAcceptable {
log.Print("reviwedog: fallback to use git command")
log.Print("reviewdog: fallback to use git command")
return p.diffUsingGitCommand(ctx)
}

Expand Down

0 comments on commit 3788f0a

Please sign in to comment.