Skip to content

Commit

Permalink
Merge pull request #5 from heppu/support-comments
Browse files Browse the repository at this point in the history
Support commented lines
  • Loading branch information
heppu committed Jul 12, 2019
2 parents b4b78c6 + d34c0c1 commit a52d644
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,47 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/heppu/go-review)](https://goreportcard.com/report/github.com/heppu/go-review)

# Go Review
Publish reports from different Go linters as gerrit reviews
Publish reports from different Go linters as gerrit review comments.

## Install

Specific release can be installed by downloading from [releases page](https://github.com/heppu/go-review/releases).

Latest version from master can be installed by running: `go get github.com/heppu/go-review/...`

## Usage

go-review uses following environment variables to access gerrit review server:

- `GERRIT_REVIEW_URL`: required
- `GERRIT_CHANGE_ID`: required
- `GERRIT_PATCHSET_REVISION`: required
- `GERRIT_USERNAME`: optional
- `GERRIT_PASSWORD`: optional

Behavior can be controlled with following flags:

- `-version`: print versions details and exit
- `-dry`: parse env vars and input but do not publish review
- `-show`: print lines while parsing

## Examples
Every linter that is able to produce similar output as go vet can be used as an input.

### go vet

```sh
go vet ./... 2>&1 | go-review
```

### golangci-lint

```sh
golangci-lint run --out-format=line-number --print-issued-lines=false | go-review
```

### staticcheck

```sh
staticcheck ./... | go-review
```
5 changes: 5 additions & 0 deletions review.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func LinesToReviewComments(r io.Reader) (comments map[string][]gerrit.CommentInp
for scanner.Scan() {
lineNumber++
line := scanner.Text()

if strings.HasPrefix(line, "#") {
continue
}

problem, err := parseLine(line)
if err != nil {
return nil, &ParseError{LineNumber: lineNumber, Err: err}
Expand Down
7 changes: 7 additions & 0 deletions review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ file_2.go:3:5: problem`),
comments: map[string][]gerrit.CommentInput{
"some.go/file.go": {{Line: 1, Message: "problem"}},
},
}, {
name: "CommentLine",
input: strings.NewReader(`# some/pkg
file.go:1:2: some problem`),
comments: map[string][]gerrit.CommentInput{
"file.go": {{Line: 1, Message: "some problem"}},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit a52d644

Please sign in to comment.