review

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2020 License: MIT Imports: 6 Imported by: 0

README

GoDoc Build Status Coverage Status Go Report Card

Go Review

Publish reports from different Go linters as gerrit review comments as part of CI pipe.

Install

Specific release can be installed by downloading from releases page.

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_NUMBER: required
  • GERRIT_PATCHSET_NUMBER: required
  • GERRIT_USERNAME: optional
  • GERRIT_PASSWORD: optional - This is the HTTP Credential, not the password used to login to gerrit.

Behavior can be controlled with following flags:

  • -version: print versions details and exit
  • -dry-run: 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
go vet ./... 2>&1 | go-review
golangci-lint
 golangci-lint run --out-format=line-number --print-issued-lines=false | go-review
staticcheck
staticcheck ./... | go-review
Jenkins pipeline
stage('Lint') {
    steps {
        sh 'golangci-lint run --new-from-rev=HEAD~ --out-format=line-number --print-issued-lines=false | go-review'
    }
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinesToReviewComments

func LinesToReviewComments(r io.Reader) (comments map[string][]gerrit.CommentInput, err error)

LinesToReviewComments reads linter reports and converts those to Gerrit Review Comments. Key in returned map is file name and value all associated problems as comments.

Example
// Mock Gerrit server
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	data, _ := ioutil.ReadAll(r.Body)
	fmt.Printf("%s", data)
	fmt.Fprint(w, ")]}\n{}")
}))
defer s.Close()

input := strings.NewReader(`file_1.go:1:2: some problem`)
comments, err := review.LinesToReviewComments(input)
if err != nil {
	if err == review.ErrNoProblemsFound {
		return
	}
	log.Fatal(err)
}

r := gerrit.ReviewInput{
	Message:  "go-review",
	Comments: comments,
}

c := gerrit.NewClient(s.URL, gerrit.NoAuth)
if err := c.SetReview(context.Background(), "some-change-id", "some-revision", r); err != nil {
	log.Fatal(err)
}

// {
//   "message": "go-review",
//   "comments": {
//     "file_1.go": [
//       {
//         "line": 1,
//         "message": "some problem"
//       }
//     ]
//   }
// }
Output:

Types

type ErrorString

type ErrorString string
const (
	ErrNoProblemsFound ErrorString = "no problems to convert into review comments"
	ErrSplitLine       ErrorString = "failed to split line to location and description"
	ErrSplitLocation   ErrorString = "failed split location to filename and position"
)

func (ErrorString) Error

func (e ErrorString) Error() string

type ParseError

type ParseError struct {
	LineNumber int
	Err        error
}

func (*ParseError) Error

func (e *ParseError) Error() string

type Position

type Position struct {
	Line   int
	Column int
}

type Problem

type Problem struct {
	FileName    string
	Description string
	Position
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL