Documentation ΒΆ
Index ΒΆ
- Constants
- func CleanPath(path, workdir string) string
- func CreateMergeRequestDiscussion(cli *gitlab.Client, projectID string, mergeRequest int, ...) (*gitlab.Response, error)
- func RunFromResult(ctx context.Context, c CommentService, results []*CheckResult, ...) error
- type BulkCommentService
- type CheckResult
- type CheckStyleError
- type CheckStyleFile
- type CheckStyleParser
- type CheckStyleResult
- type Comment
- type CommentService
- type DiffCmd
- type DiffService
- type DiffString
- type ErrorformatParser
- type FilteredCheck
- type GitHubPullRequest
- type GitLabMergeRequestCommitCommenter
- type GitLabMergeRequestDiff
- type GitLabMergeRequestDiscussion
- type GitLabMergeRequestDiscussionCommenter
- type GitLabMergeRequestDiscussionList
- type GitLabMergeRequestDiscussionPosition
- type ListMergeRequestDiscussionOptions
- type Parser
- type ParserOpt
- type RawCommentWriter
- type Reviewdog
- type UnifiedCommentWriter
Examples ΒΆ
Constants ΒΆ
const Version = "0.9.11"
Version is version of reviewdog CLI.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func CleanPath ΒΆ
CleanPath clean up given path. If workdir is not empty, it returns relative path to the given workdir.
func CreateMergeRequestDiscussion ΒΆ
func CreateMergeRequestDiscussion(cli *gitlab.Client, projectID string, mergeRequest int, discussion *GitLabMergeRequestDiscussion) (*gitlab.Response, error)
CreateMergeRequestDiscussion creates new discussion on a merge request.
GitLab API docs: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-discussion
func RunFromResult ΒΆ
func RunFromResult(ctx context.Context, c CommentService, results []*CheckResult, filediffs []*diff.FileDiff, strip int, toolname string) error
Types ΒΆ
type BulkCommentService ΒΆ
type BulkCommentService interface { CommentService Flush(context.Context) error }
BulkCommentService posts comments all at once when Flush() is called. Flush() will be called at the end of reviewdog run.
type CheckResult ΒΆ
type CheckResult struct { Path string // relative file path Lnum int // line number Col int // column number (1 <tab> == 1 character column) Message string // error message Lines []string // Original error lines (often one line) }
CheckResult represents a checked result of static analysis tools. :h error-file-format
type CheckStyleError ΒΆ
type CheckStyleError struct { Column int `xml:"column,attr,omitempty"` Line int `xml:"line,attr"` Message string `xml:"message,attr"` Severity string `xml:"severity,attr,omitempty"` Source string `xml:"source,attr,omitempty"` }
CheckStyleError represents <error line="1" column="10" severity="error" message="msg" source="src" />
type CheckStyleFile ΒΆ
type CheckStyleFile struct { Name string `xml:"name,attr"` Errors []*CheckStyleError `xml:"error"` }
CheckStyleFile represents <file name="fname"><error ... />...</file>
type CheckStyleParser ΒΆ
type CheckStyleParser struct{}
CheckStyleParser is checkstyle parser.
func (*CheckStyleParser) Parse ΒΆ
func (p *CheckStyleParser) Parse(r io.Reader) ([]*CheckResult, error)
type CheckStyleResult ΒΆ
type CheckStyleResult struct { XMLName xml.Name `xml:"checkstyle"` Version string `xml:"version,attr"` Files []*CheckStyleFile `xml:"file,omitempty"` }
CheckStyleResult represents checkstyle XML result. <?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file ...></file>...</checkstyle>
References:
type Comment ΒΆ
type Comment struct { *CheckResult Body string LnumDiff int ToolName string }
Comment represents a reported result as a comment.
type CommentService ΒΆ
CommentService is an interface which posts Comment.
func MultiCommentService ΒΆ
func MultiCommentService(services ...CommentService) CommentService
MultiCommentService creates a comment service that duplicates its post to all the provided comment services.
type DiffCmd ΒΆ
type DiffCmd struct {
// contains filtered or unexported fields
}
type DiffService ΒΆ
DiffService is an interface which get diff.
func NewDiffString ΒΆ
func NewDiffString(diff string, strip int) DiffService
type DiffString ΒΆ
type DiffString struct {
// contains filtered or unexported fields
}
func (*DiffString) Strip ΒΆ
func (d *DiffString) Strip() int
type ErrorformatParser ΒΆ
type ErrorformatParser struct {
// contains filtered or unexported fields
}
ErrorformatParser is errorformat parser.
func NewErrorformatParser ΒΆ
func NewErrorformatParser(efm *errorformat.Errorformat) *ErrorformatParser
NewErrorformatParser returns a new ErrorformatParser.
func NewErrorformatParserString ΒΆ
func NewErrorformatParserString(efms []string) (*ErrorformatParser, error)
NewErrorformatParserString returns a new ErrorformatParser from errorformat in string representation.
func (*ErrorformatParser) Parse ΒΆ
func (p *ErrorformatParser) Parse(r io.Reader) ([]*CheckResult, error)
type FilteredCheck ΒΆ
type FilteredCheck struct { *CheckResult InDiff bool LnumDiff int }
FilteredCheck represents CheckResult with filtering info.
func FilterCheck ΒΆ
func FilterCheck(results []*CheckResult, diff []*diff.FileDiff, strip int, wd string) []*FilteredCheck
FilterCheck filters check results by diff. It doesn't drop check which is not in diff but set FilteredCheck.InDiff field false.
type GitHubPullRequest ΒΆ
type GitHubPullRequest struct {
// contains filtered or unexported fields
}
GitHubPullRequest is a comment and diff service for GitHub PullRequest.
API:
https://developer.github.com/v3/pulls/comments/#create-a-comment POST /repos/:owner/:repo/pulls/:number/comments
func NewGitHubPullReqest ΒΆ
func NewGitHubPullReqest(cli *github.Client, owner, repo string, pr int, sha string) (*GitHubPullRequest, error)
NewGitHubPullReqest returns a new GitHubPullRequest service. GitHubPullRequest service needs git command in $PATH.
func (*GitHubPullRequest) Diff ΒΆ
func (g *GitHubPullRequest) Diff(ctx context.Context) ([]byte, error)
Diff returns a diff of PullRequest.
func (*GitHubPullRequest) Flush ΒΆ
func (g *GitHubPullRequest) Flush(ctx context.Context) error
Flush posts comments which has not been posted yet.
func (*GitHubPullRequest) Post ΒΆ
func (g *GitHubPullRequest) Post(_ context.Context, c *Comment) error
Post accepts a comment and holds it. Flush method actually posts comments to GitHub in parallel.
func (*GitHubPullRequest) Strip ΒΆ
func (g *GitHubPullRequest) Strip() int
Strip returns 1 as a strip of git diff.
type GitLabMergeRequestCommitCommenter ΒΆ
type GitLabMergeRequestCommitCommenter struct {
// contains filtered or unexported fields
}
GitLabMergeRequestCommitCommenter is a comment service for GitLab MergeRequest.
API:
https://docs.gitlab.com/ce/api/commits.html#post-comment-to-commit POST /projects/:id/repository/commits/:sha/comments
func NewGitLabMergeRequestCommitCommenter ΒΆ
func NewGitLabMergeRequestCommitCommenter(cli *gitlab.Client, owner, repo string, pr int, sha string) (*GitLabMergeRequestCommitCommenter, error)
NewGitLabMergeRequestCommitCommenter returns a new GitLabMergeRequestCommitCommenter service. GitLabMergeRequestCommitCommenter service needs git command in $PATH.
type GitLabMergeRequestDiff ΒΆ
type GitLabMergeRequestDiff struct {
// contains filtered or unexported fields
}
GitLabMergeRequestDiff is a diff service for GitLab MergeRequest.
func NewGitLabMergeRequestDiff ΒΆ
func NewGitLabMergeRequestDiff(cli *gitlab.Client, owner, repo string, pr int, sha string) (*GitLabMergeRequestDiff, error)
NewGitLabMergeRequestDiff returns a new GitLabMergeRequestDiff service. itLabMergeRequestDiff service needs git command in $PATH.
func (*GitLabMergeRequestDiff) Diff ΒΆ
func (g *GitLabMergeRequestDiff) Diff(ctx context.Context) ([]byte, error)
Diff returns a diff of MergeRequest. It runs `git diff` locally instead of diff_url of GitLab Merge Request because diff of diff_url is not suited for comment API in a sense that diff of diff_url is equivalent to `git diff --no-renames`, we want diff which is equivalent to `git diff --find-renames`.
func (*GitLabMergeRequestDiff) Strip ΒΆ
func (g *GitLabMergeRequestDiff) Strip() int
Strip returns 1 as a strip of git diff.
type GitLabMergeRequestDiscussion ΒΆ
type GitLabMergeRequestDiscussion struct { Body string `json:"body"` // The content of a discussion Position *GitLabMergeRequestDiscussionPosition `json:"position"` }
GitLabMergeRequestDiscussion represents a discussion of MergeRequest.
type GitLabMergeRequestDiscussionCommenter ΒΆ
type GitLabMergeRequestDiscussionCommenter struct {
// contains filtered or unexported fields
}
GitLabMergeRequestDiscussionCommenter is a comment and diff service for GitLab MergeRequest.
API:
https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-discussion POST /projects/:id/merge_requests/:merge_request_iid/discussions
func NewGitLabMergeRequestDiscussionCommenter ΒΆ
func NewGitLabMergeRequestDiscussionCommenter(cli *gitlab.Client, owner, repo string, pr int, sha string) (*GitLabMergeRequestDiscussionCommenter, error)
NewGitLabMergeRequestDiscussionCommenter returns a new GitLabMergeRequestDiscussionCommenter service. GitLabMergeRequestDiscussionCommenter service needs git command in $PATH.
type GitLabMergeRequestDiscussionList ΒΆ
type GitLabMergeRequestDiscussionList struct {
Notes []*GitLabMergeRequestDiscussion `json:"notes"`
}
GitLabMergeRequestDiscussionList represents response of ListMergeRequestDiscussion API.
GitLab API docs: https://docs.gitlab.com/ee/api/discussions.html#list-project-merge-request-discussions
func ListMergeRequestDiscussion ΒΆ
func ListMergeRequestDiscussion(cli *gitlab.Client, projectID string, mergeRequest int, opts *ListMergeRequestDiscussionOptions) ([]*GitLabMergeRequestDiscussionList, *gitlab.Response, error)
ListMergeRequestDiscussion lists discussion on a merge request.
GitLab API docs: https://docs.gitlab.com/ee/api/discussions.html#list-project-merge-request-discussions
type GitLabMergeRequestDiscussionPosition ΒΆ
type GitLabMergeRequestDiscussionPosition struct { // Required. BaseSHA string `json:"base_sha,omitempty"` // Base commit SHA in the source branch StartSHA string `json:"start_sha,omitempty"` // SHA referencing commit in target branch HeadSHA string `json:"head_sha,omitempty"` // SHA referencing HEAD of this merge request PositionType string `json:"position_type,omitempty"` // Type of the position reference', allowed values: 'text' or 'image' // Optional. NewPath string `json:"new_path,omitempty"` // File path after change NewLine int `json:"new_line,omitempty"` // Line number after change (for 'text' diff notes) OldPath string `json:"old_path,omitempty"` // File path before change OldLine int `json:"old_line,omitempty"` // Line number before change (for 'text' diff notes) }
GitLabMergeRequestDiscussionPosition represents position of GitLab MergeRequest Discussion.
type ListMergeRequestDiscussionOptions ΒΆ
type ListMergeRequestDiscussionOptions gitlab.ListOptions
ListMergeRequestDiscussionOptions represents the available ListMergeRequestDiscussion() options.
GitLab API docs: https://docs.gitlab.com/ee/api/discussions.html#list-project-merge-request-discussions
type Parser ΒΆ
type Parser interface {
Parse(r io.Reader) ([]*CheckResult, error)
}
Parser is an interface which parses compilers, linters, or any tools results.
func NewCheckStyleParser ΒΆ
func NewCheckStyleParser() Parser
NewCheckStyleParser returns a new CheckStyleParser.
type ParserOpt ΒΆ
ParserOpt represents option to create Parser. Either FormatName or Errorformat should be specified.
type RawCommentWriter ΒΆ
type RawCommentWriter struct {
// contains filtered or unexported fields
}
RawCommentWriter is comment writer which writes results to given writer without any formatting.
func NewRawCommentWriter ΒΆ
func NewRawCommentWriter(w io.Writer) *RawCommentWriter
type Reviewdog ΒΆ
type Reviewdog struct {
// contains filtered or unexported fields
}
Reviewdog represents review dog application which parses result of compiler or linter, get diff and filter the results by diff, and report filtered results.
Example ΒΆ
difftext := `diff --git a/golint.old.go b/golint.new.go index 34cacb9..a727dd3 100644 --- a/golint.old.go +++ b/golint.new.go @@ -2,6 +2,12 @@ package test var V int +var NewError1 int + // invalid func comment func F() { } + +// invalid func comment2 +func F2() { +} ` lintresult := `golint.new.go:3:5: exported var V should have comment or be unexported golint.new.go:5:5: exported var NewError1 should have comment or be unexported golint.new.go:7:1: comment on exported function F should be of the form "F ..." golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..." ` efm, _ := errorformat.NewErrorformat([]string{`%f:%l:%c: %m`}) p := NewErrorformatParser(efm) c := NewRawCommentWriter(os.Stdout) d := NewDiffString(difftext, 1) app := NewReviewdog("tool name", p, c, d) app.Run(context.Background(), strings.NewReader(lintresult))
Output: golint.new.go:5:5: exported var NewError1 should have comment or be unexported golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
func NewReviewdog ΒΆ
func NewReviewdog(toolname string, p Parser, c CommentService, d DiffService) *Reviewdog
NewReviewdog returns a new Reviewdog.
type UnifiedCommentWriter ΒΆ
type UnifiedCommentWriter struct {
// contains filtered or unexported fields
}
UnifiedCommentWriter is comment writer which writes results to given writer in one of following unified formats.
Format:
- <file>: [<tool name>] <message>
- <file>:<lnum>: [<tool name>] <message>
- <file>:<lnum>:<col>: [<tool name>] <message>
where <message> can be multiple lines.
func NewUnifiedCommentWriter ΒΆ
func NewUnifiedCommentWriter(w io.Writer) *UnifiedCommentWriter
Source Files ΒΆ
Directories ΒΆ
Path | Synopsis |
---|---|
Package cienv provides utility for environment variable in CI services.
|
Package cienv provides utility for environment variable in CI services. |
cmd
|
|
Package diff provides a utility to parse unified diff.
|
Package diff provides a utility to parse unified diff. |
Package project provides utility for reviewdog execution based on project config.
|
Package project provides utility for reviewdog execution based on project config. |